home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ZOO21E.EXE / SYSV.C < prev    next >
C/C++ Source or Header  |  1991-07-11  |  4KB  |  150 lines

  1. #ifndef LINT
  2. /* @(#) sysv.c 2.5 88/01/10 14:47:24 */
  3. static char sysvid[]="@(#) sysv.c 2.5 88/01/10 14:47:24";
  4. #endif /* LINT */
  5.  
  6. /* machine.c for System V */
  7.  
  8. /*
  9. The contents of this file are hereby released to the public domain.
  10.  
  11.                                     -- Rahul Dhesi  1986/12/31
  12. */
  13.  
  14. #ifdef UNBUF_IO    /* do not use */
  15. /*
  16. Function tell() returns the current seek position for a file
  17. descriptor.  Microport System V/AT has an undocumented tell()
  18. library function (why?) but the **IX PC doesn't, so we code
  19. one here.  It is needed for unbuffered I/O only.
  20. */
  21. long lseek PARMS ((int, long, int));
  22. long tell (fd)
  23. int fd;
  24. { return (lseek (fd, 0L, 1)); }
  25. #endif /* UNBUF_IO */
  26.  
  27. /****************
  28. Date and time functions are standard **IX-style functions.  "nixtime.i"
  29. will be included by machine.c.
  30. */
  31.  
  32. #include <sys/types.h>
  33. #include <sys/stat.h>
  34. #include <time.h>
  35.  
  36. /* Function isadir() returns 1 if the supplied handle is a directory,
  37. else it returns 0.
  38. */
  39.  
  40. int isadir (file)
  41. ZOOFILE file;
  42. {
  43.    int handle = fileno(file);
  44.    struct stat buf;           /* buffer to hold file information */
  45.    if (fstat (handle, &buf) == -1) {
  46.       return (0);             /* inaccessible -- assume not dir */
  47.    } else {
  48.       if (buf.st_mode & S_IFDIR)
  49.          return (1);
  50.       else
  51.          return (0);
  52.    }
  53. }
  54.  
  55. /****************
  56. Function fixfname() converts the supplied filename to a syntax
  57. legal for the host system.  It is used during extraction.
  58. */
  59.  
  60. char *fixfname(fname)
  61. char *fname;
  62. {
  63.    return (fname); /* default is no-op */
  64. }
  65.  
  66. extern long timezone;   /* defined by library routine */
  67. long time ();
  68. struct tm *localtime ();
  69.  
  70. /* Function gettz(), returns the offset from GMT in seconds of the
  71. local time, taking into account daylight savings time */
  72.  
  73. #if 1        /* Following should work for System V */
  74. long gettz()
  75. {
  76. #define SEC_IN_DAY    (24L * 60L * 60L)
  77. #define INV_VALUE        (SEC_IN_DAY + 1L)
  78.     static long retval = INV_VALUE;         /* cache, init to impossible value */
  79.     struct tm *tm;
  80.     long clock;
  81.     if (retval != INV_VALUE)                 /* if have cached value, return it */
  82.         return retval;
  83.     clock = time ((long *) 0);
  84.     tm = localtime (&clock);
  85.     retval = timezone - tm->tm_isdst*3600;
  86.     return retval;
  87. }
  88. #else
  89. /* This version of gettz should be portable to all Unices, although it can't
  90.    be described as elegant. Users immediately west of the International
  91.    Date Line (Polynesia, Soviet Far East) may get times out by 24 hours.
  92.    Contributed by: Ian Phillipps <igp@camcon.co.uk> */
  93.  
  94. /* Function gettz(), returns the offset from GMT in seconds */
  95. long gettz()
  96. {
  97. #define NOONOFFSET 43200
  98. #define SEC_IN_DAY    (24L * 60L * 60L)
  99. #define INV_VALUE        (SEC_IN_DAY + 1L)
  100.     static long retval = INV_VALUE;         /* cache, init to impossible value */
  101.     extern long time();
  102.     extern struct tm *localtime();
  103.     long now;
  104.     long noon;
  105.     struct tm *noontm;
  106.     if (retval != INV_VALUE)                 /* if have cached value, return it */
  107.         return retval;
  108.    now = time((long *) 0);
  109.    /* Find local time for GMT noon today */
  110.    noon = now - now % SEC_IN_DAY + NOONOFFSET ;
  111.    noontm = localtime( &noon );
  112.    retval = NOONOFFSET - 60 * ( 60 * noontm->tm_hour - noontm->tm_min );
  113.     return retval;
  114. #undef NOONOFFSET
  115. }
  116. #endif
  117.  
  118. /* Standard **IX-compatible time functions */
  119. #include "nixtime.i"
  120.  
  121. /* Standard **IX-specific file attribute routines */
  122. #include "nixmode.i"
  123.  
  124. /*
  125. Make a directory.  System V has no system call accessible to
  126. ordinary users to make a new directory.  Hence we spawn a shell
  127. and hope /bin/mkdir is there.  Since /bin/mkdir gives a nasty
  128. error message if it fails, we call it only if nothing already
  129. exists by the name of the needed directory.
  130. */
  131.  
  132. int mkdir(dirname)
  133. char *dirname;
  134. {
  135.    char cmd[PATHSIZE+11+1]; /* room for "/bin/mkdir " used below  + 1 spare */
  136.    if (!exists(dirname)) {
  137.       strcpy(cmd, "/bin/mkdir ");
  138.       strcat(cmd, dirname);
  139.       return (system(cmd));
  140.    }
  141.     return (0);
  142. }
  143.  
  144. /* No file truncate system call in older System V.  If yours has one,
  145. add it here -- see bsd.c for example.  It's ok for zootrunc to be
  146. a no-op. */
  147. /*ARGSUSED*/
  148. int zootrunc(f) FILE *f; { return 0; }
  149.  
  150.