home *** CD-ROM | disk | FTP | other *** search
/ Hall of Fame / HallofFameCDROM.cdr / proglc / zoo141_c.lzh / BSD.C < prev    next >
C/C++ Source or Header  |  1987-02-07  |  2KB  |  71 lines

  1. /* machine.c for 4.3BSD. */
  2.  
  3. /*
  4. The contents of this file are hereby released to the public domain.
  5.  
  6.                                     -- Rahul Dhesi  1986/12/31
  7. */
  8.  
  9. long tell();
  10.  
  11. /****************
  12. function trunc() truncates a file.
  13. */
  14.  
  15. int trunc (handle)
  16. int handle;
  17. {
  18.    ftruncate (handle, tell(handle));
  19. }
  20.  
  21. /****************
  22. Function fixfname() converts the supplied filename to a syntax
  23. legal for the host system.  It is used during extraction.
  24. */
  25.  
  26. char *fixfname(fname)
  27. char *fname;
  28. {
  29.    return (fname); /* default is no-op */
  30. }
  31.  
  32. /****************
  33. Date and time functions are standard UNIX-style functions.  "nixtime.i"
  34. will be included by machine.c.
  35. */
  36.  
  37. #include <sys/types.h>
  38. #include <sys/stat.h>
  39. #include <sys/time.h>
  40.  
  41. /* Function isadir() returns 1 if the supplied handle is a directory, 
  42. else it returns 0.  
  43. */
  44.  
  45. int isadir (handle)
  46. int handle;
  47. {
  48.    struct stat buf;           /* buffer to hold file information */
  49.    if (fstat (handle, &buf) == -1) {
  50.       return (0);             /* inaccessible -- assume not dir */
  51.    } else {
  52.       if (buf.st_mode & S_IFDIR)
  53.          return (1);
  54.       else
  55.          return (0);
  56.    }
  57. }
  58.  
  59. /* Function gettz(), returns the offset from GMT in seconds */
  60. long gettz()
  61. {
  62.    struct timeval tp;
  63.    struct timezone tzp;
  64.    gettimeofday (&tp, &tzp);              /* specific to 4.3BSD */
  65. /* return (tzp.tz_minuteswest * 60 + (tzp.tz_dsttime != 0 ? 60L * 60L : 0));*/
  66.    return (tzp.tz_minuteswest * 60);
  67. }
  68.  
  69. /* Standard UNIX-compatible time routines */
  70. #include "nixtime.i"
  71.