home *** CD-ROM | disk | FTP | other *** search
/ The Original Shareware 1992 / TheOrigSharewareV1.cdr / 25 / arj200.exe / arj / UNARJ.ARJ / ENVIRON.C < prev    next >
C/C++ Source or Header  |  1991-04-09  |  3KB  |  189 lines

  1. /* ENVIRON.C, UNARJ, R JUNG, 04/09/91
  2. /* Implementation dependent routines
  3. /* Copyright (c) 1991 by Robert K Jung.  All rights reserved.
  4. /*
  5. /*   This code may be freely used in programs that are NOT archivers.
  6. /*
  7. /* Modification history:
  8. /* Date      Programmer  Description of modification.
  9. /* 04/09/91  R. Jung     Rewrote code.
  10. /*
  11.  */
  12.  
  13. #include "unarj.h"
  14.  
  15. #ifdef __TURBOC__
  16.  
  17. #define SUBS_DEFINED
  18.  
  19. #include <string.h>
  20. #include <dos.h>
  21. #include <io.h>
  22. #include <fcntl.h>
  23.  
  24. void
  25. case_path(char *name)
  26. {
  27.     strupper(name);
  28. }
  29.  
  30. int
  31. file_exists(char *name)
  32. {
  33.     return (access(name, 0) == 0);
  34. }
  35.  
  36. int
  37. fix_path(char *to_name, char *fr_name)
  38. {
  39.     char *p;
  40.  
  41.     p = fr_name;
  42.     if (p[0] && p[1] == ':')        /* get rid of drive */
  43.         p += 2;
  44.     if (p[0] == '.')
  45.     {
  46.         if (p[1] == '.' && p[2] == '\\')
  47.            p += 2;
  48.         else if (p[1] == '\\')
  49.             p++;
  50.     }
  51.     if (p[0] == '\\')               /* get rid of root dir */
  52.         p++;
  53.     if (to_name != NULL)
  54.     {
  55.         strcpy(to_name, p);
  56.         strupper(p);
  57.     }
  58.     return (int)(p - fr_name);
  59. }
  60.  
  61. int
  62. set_fmode(char *name, ushort attribute)
  63. {
  64.     if (_chmod(name, 1, attribute) == -1)
  65.         return -1;
  66.     return 0;
  67. }
  68.  
  69. int
  70. set_ftime(char *name, ulong tstamp)
  71. {
  72.     FILE *fd;
  73.     int code;
  74.  
  75.     if ((fd = fopen(name, "rb")) == NULL)
  76.     return -1;
  77.     code = setftime(fileno(fd), (struct ftime *) &tstamp);
  78.     fclose(fd);
  79.     return code;
  80. }
  81.  
  82. #endif
  83.  
  84. #ifdef _QC
  85.  
  86. #define SUBS_DEFINED
  87.  
  88. #include <string.h>
  89. #include <dos.h>
  90. #include <io.h>
  91. #include <fcntl.h>
  92.  
  93. void
  94. case_path(char *name)
  95. {
  96.     strupper(name);
  97. }
  98.  
  99. int
  100. file_exists(char *name)
  101. {
  102.     return (access(name, 0) == 0);
  103. }
  104.  
  105. int
  106. fix_path(char *to_name, char *fr_name)
  107. {
  108.     char *p;
  109.  
  110.     p = fr_name;
  111.     if (p[0] && p[1] == ':')        /* get rid of drive */
  112.         p += 2;
  113.     if (p[0] == '\\')               /* get rid of root dir */
  114.         p++;
  115.     if (to_name != NULL)
  116.     {
  117.         strcpy(to_name, p);
  118.         strupper(p);
  119.     }
  120.     return (int)(p - fr_name);
  121. }
  122.  
  123. int
  124. set_fmode(char *name, ushort attribute)
  125. {
  126.     return _dos_setfileattr(name, (uint)attribute);
  127. }
  128.  
  129. int
  130. set_ftime(char *name, ulong tstamp)
  131. {
  132.     FILE *fd;
  133.     int code;
  134.     uint date_stamp, time_stamp;
  135.                              
  136.     date_stamp = (uint)(tstamp >> 16);
  137.     time_stamp = (uint)(tstamp & 0xFFFF);
  138.     if ((fd = fopen(name, "rb")) == NULL)
  139.     return -1;
  140.     code = _dos_setftime(fileno(fd), date_stamp, time_stamp);
  141.     fclose(fd);
  142.     return code;
  143. }
  144.  
  145. #endif
  146.  
  147. #ifndef SUBS_DEFINED       /* vanilla version for other compilers */
  148.  
  149. #include <string.h>
  150.  
  151. void
  152. case_path(char *name)
  153. {
  154. }
  155.  
  156. int
  157. file_exists(char *name)
  158. {
  159.     FILE *fd;
  160.  
  161.     if ((fd = fopen(name, "rb")) == NULL)
  162.     return 0;
  163.     fclose(fd);
  164.     return 1;
  165. }
  166.  
  167. int
  168. fix_path(char *to_name, char *fr_name)
  169. {
  170.     strcpy(to_name, fr_name);
  171.     return 0;
  172. }
  173.  
  174. int
  175. set_fmode(char *name, ushort attribute)
  176. {
  177.     return 0;
  178. }
  179.  
  180. int
  181. set_ftime(char *name, ulong tstamp)
  182. {
  183.     return 0;
  184. }
  185.  
  186. #endif  /* end of vanilla section */
  187.  
  188. /* end ENVIRON.C */
  189.