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

  1. #ifndef LINT
  2. static char genericid[]="@(#) generic.c 2.2 88/01/24 12:44:03";
  3. #endif /* LINT */
  4.  
  5. /*
  6. Generic template for machine-dependent functions.
  7.  
  8. The contents of this file are hereby released to the public domain
  9.  
  10.                                             -- Rahul Dhesi 1991/07/05
  11. */
  12.  
  13. /****************
  14. Date and time functions are assumed to be standard **IX-style functions.
  15. */
  16.  
  17. #include <sys/types.h>
  18. #include <sys/stat.h>
  19. #include <time.h>
  20.  
  21. /* Function isadir() returns 1 if the supplied handle is a directory,
  22. else it returns 0.
  23. */
  24.  
  25. int isadir (file)
  26. ZOOFILE file;
  27. {
  28.    int handle = fileno(file);
  29.    struct stat buf;           /* buffer to hold file information */
  30.    if (fstat (handle, &buf) == -1) {
  31.       return (0);             /* inaccessible -- assume not dir */
  32.    } else {
  33.       if (buf.st_mode & S_IFDIR)
  34.          return (1);
  35.       else
  36.          return (0);
  37.    }
  38. }
  39.  
  40. /****************
  41. Function fixfname() converts the supplied filename to a syntax
  42. legal for the host system.  It is used during extraction.
  43. */
  44.  
  45. char *fixfname(fname)
  46. char *fname;
  47. {
  48.     fname[FNLIMIT] = '\0';        /* Just truncate at filename size limit */
  49.     return fname;
  50. }
  51.  
  52. /* The function gettz() returns the offset from GMT in seconds, taking
  53. into account the local timezone and any daylight savings time. */
  54.  
  55. /* This version of gettz should be portable to all Unices, although it
  56. can't be described as elegant.  Users immediately west of the International
  57. Date Line (Polynesia, Soviet Far East) may get times out by 24 hours.
  58. Contributed by: Ian Phillipps <igp@camcon.co.uk> */
  59.  
  60. long gettz()
  61. {
  62. #define NOONOFFSET 43200
  63. #define SEC_IN_DAY    (24L * 60L * 60L)
  64. #define INV_VALUE        (SEC_IN_DAY + 1L)
  65.     static long retval = INV_VALUE;         /* cache, init to impossible value */
  66.     extern long time();
  67.     extern struct tm *localtime();
  68.     long now;
  69.     long noon;
  70.     struct tm *noontm;
  71.     if (retval != INV_VALUE)                 /* if have cached value, return it */
  72.         return retval;
  73.    now = time((long *) 0);
  74.    /* Find local time for GMT noon today */
  75.    noon = now - now % SEC_IN_DAY + NOONOFFSET ;
  76.    noontm = localtime( &noon );
  77.    retval = NOONOFFSET - 60 * ( 60 * noontm->tm_hour - noontm->tm_min );
  78.     return retval;
  79. #undef NOONOFFSET
  80. }
  81.  
  82. /* Standard UNIX-compatible time functions */
  83. #include "nixtime.i"
  84.  
  85. /* Standard UNIX-specific file attribute routines */
  86. #include "nixmode.i"
  87.  
  88. /* Assume no file truncate system call.  Ok to be a no-op. */
  89. /*ARGSUSED*/
  90. int zootrunc(f) FILE *f; { return 0; }
  91.  
  92.