home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / c / zoo_src / z201src2 / sysv.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-25  |  2.5 KB  |  106 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
  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 UNIX 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
  26.  
  27. /****************
  28. Date and time functions are standard UNIX-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. long gettz()
  73. {
  74.     struct tm *tm;
  75.     long clock;
  76.     clock = time ((long *) 0);
  77.     tm = localtime (&clock);
  78.    return (timezone - tm->tm_isdst*3600);
  79. }
  80.  
  81. /* Standard UNIX-compatible time functions */
  82. #include "nixtime.i"
  83.  
  84. /* Standard UNIX-specific file attribute routines */
  85. #include "nixmode.i"
  86.  
  87. /* 
  88. Make a directory.  System V has no system call accessible to 
  89. ordinary users to make a new directory.  Hence we spawn a shell 
  90. and hope /bin/mkdir is there.  Since /bin/mkdir gives a nasty 
  91. error message if it fails, we call it only if nothing already 
  92. exists by the name of the needed directory.
  93. */
  94.  
  95. int mkdir(dirname)
  96. char *dirname;
  97. {
  98.    char cmd[PATHSIZE+11+1]; /* room for "/bin/mkdir " used below  + 1 spare */
  99.    if (!exists(dirname)) {
  100.       strcpy(cmd, "/bin/mkdir ");
  101.       strcat(cmd, dirname);
  102.       return (system(cmd));
  103.    }
  104.     return (0);
  105. }
  106.