home *** CD-ROM | disk | FTP | other *** search
/ Amiga Elysian Archive / AmigaElysianArchive.iso / compress / zoosrc20.zoo / bsd.c < prev    next >
C/C++ Source or Header  |  1989-07-25  |  2KB  |  103 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 trunc() truncates a file.
  36. */
  37.  
  38. int trunc (f)
  39. ZOOFILE f;
  40. {
  41.     fflush (f);
  42.                     /* just in case it matters */
  43.    ftruncate (fileno (f), ftell (f));
  44.  
  45. }
  46.  
  47. /****************
  48. Function fixfname() converts the supplied filename to a syntax
  49. legal for the host system.  It is used during extraction.
  50. */
  51.  
  52. char *fixfname(fname)
  53. char *fname;
  54. {
  55.    return (fname); /* default is no-op */
  56. }
  57.  
  58. /****************
  59. Date and time functions are standard UNIX-style functions.  "nixtime.i"
  60. will be included by machine.c.
  61. */
  62.  
  63. #include <sys/types.h>
  64. #include <sys/stat.h>
  65. #include <sys/time.h>
  66.  
  67. /* Function isadir() returns 1 if the supplied handle is a directory, 
  68. else it returns 0.  
  69. */
  70.  
  71. int isadir (f)
  72. ZOOFILE f;
  73. {
  74.    struct stat buf;           /* buffer to hold file information */
  75.    if (fstat (fileno (f), &buf) == -1) {
  76.       return (0);             /* inaccessible -- assume not dir */
  77.    } else {
  78.       if (buf.st_mode & S_IFDIR)
  79.          return (1);
  80.       else
  81.          return (0);
  82.    }
  83. }
  84.  
  85. /* Function gettz(), returns the offset from GMT in seconds */
  86. long gettz()
  87. {
  88.    struct timeval tp;
  89.    struct timezone tzp;
  90.    gettimeofday (&tp, &tzp);              /* specific to 4.3BSD */
  91.  
  92.  
  93.    /* return (tzp.tz_minuteswest * 60); */ /* old incorrect code */
  94.     /* Timezone fix thanks to Bill Davidsen <wedu@ge-crd.ARPA> */
  95.    return (tzp.tz_minuteswest * 60 - tzp.tz_dsttime * 3600L);
  96. }
  97.  
  98. /* Standard UNIX-compatible time routines */
  99. #include "nixtime.i"
  100.  
  101. /* Standard UNIX-specific file attribute routines */
  102. #include "nixmode.i"
  103.