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

  1. #ifndef LINT
  2. static char bsdid[]="@(#) bsd.c 2.3 88/01/10 14:45:19";
  3. #endif /* LINT */
  4.  
  5. /* machine.c for 4.3BSD. */
  6.  
  7. /*
  8. The contents of this file are hereby released to the public domain.
  9.  
  10.                                     -- Rahul Dhesi  1987/07/23
  11. */
  12.  
  13. /*
  14. WARNING:  This file assumes that ZOOFILE is a standard buffered
  15. file.  It will have to be modified if ZOOFILE is changed to
  16. be an unbuffered file descriptor or to any other kind of file.
  17. */
  18.  
  19. #ifdef UNBUF_IO
  20. /*
  21. Function tell() returns the current seek position for a file
  22. descriptor.  4.3BSD on VAX-11/785 has an undocumented tell() function
  23. but it may not exist on all implementations, so we code one here
  24. to be on the safe side.  It is needed for unbuffered I/O only.
  25. */
  26. long lseek PARMS ((int, long, int));
  27. long tell (fd)
  28. int fd;
  29. { return (lseek (fd, 0L, 1)); }
  30. #endif
  31.  
  32. long ftell();
  33.  
  34. /****************
  35. Function fixfname() converts the supplied filename to a syntax
  36. legal for the host system.  It is used during extraction.
  37. */
  38.  
  39. char *fixfname(fname)
  40. char *fname;
  41. {
  42.    return fname; /* default is no-op */
  43. }
  44.  
  45. /****************
  46. Date and time functions are standard UNIX-style functions.
  47. */
  48.  
  49. #include <sys/types.h>
  50. #include <sys/stat.h>
  51. #include <sys/time.h>
  52.  
  53. /* Function isadir() returns 1 if the supplied handle is a directory,
  54. else it returns 0.
  55. */
  56.  
  57. int isadir (f)
  58. ZOOFILE f;
  59. {
  60.    struct stat buf;           /* buffer to hold file information */
  61.    if (fstat (fileno (f), &buf) == -1) {
  62.       return (0);             /* inaccessible -- assume not dir */
  63.    } else {
  64.       if (buf.st_mode & S_IFDIR)
  65.          return (1);
  66.       else
  67.          return (0);
  68.    }
  69. }
  70.  
  71. /* Function gettz() returns the offset from GMT in seconds */
  72. long gettz()
  73. {
  74. #define SEC_IN_DAY    (24L * 60L * 60L)
  75. #define INV_VALUE        (SEC_IN_DAY + 1L)
  76.     static long retval = INV_VALUE;         /* cache, init to impossible value */
  77.    struct timeval tp;
  78.    struct timezone tzp;
  79.     if (retval != INV_VALUE)                 /* if have cached value, return it */
  80.         return retval;
  81.    gettimeofday (&tp, &tzp);              /* specific to 4.3BSD */
  82.    /* return (tzp.tz_minuteswest * 60); */ /* old incorrect code */
  83.     /* Timezone fix thanks to Bill Davidsen <wedu@ge-crd.ARPA> */
  84.     retval = tzp.tz_minuteswest * 60 - tzp.tz_dsttime * 3600L;
  85.     return retval;
  86. }
  87.  
  88. /* Standard UNIX-compatible time routines */
  89. #include "nixtime.i"
  90.  
  91. /* Standard UNIX-specific file attribute routines */
  92. #include "nixmode.i"
  93.  
  94. #ifndef SEEK_CUR
  95. # define  SEEK_CUR    1
  96. #endif
  97.  
  98. /* Truncate a file. */
  99. int zootrunc(f) FILE *f;
  100. {
  101.     extern long lseek();
  102.     long seekpos;
  103.     int fd = fileno(f);
  104.     seekpos = lseek(fd, 0L, SEEK_CUR);
  105.     if (seekpos >= 0)
  106.         return ftruncate(fd, seekpos);
  107. }
  108.