home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / ARC521-2.ZIP / ARCDOS.C < prev    next >
C/C++ Source or Header  |  1989-12-30  |  3KB  |  137 lines

  1. /*
  2.  * $Header: arcdos.c,v 1.8 88/08/01 15:07:15 hyc Exp $
  3.  */
  4.  
  5. /*
  6.  * ARC - Archive utility - ARCDOS
  7.  *
  8.  * Version 1.44, created on 07/25/86 at 14:17:38
  9.  *
  10.  * (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  11.  *
  12.  * By:  Thom Henderson
  13.  *
  14.  * Description: This file contains certain DOS level routines that assist in
  15.  * doing fancy things with an archive, primarily reading and setting the date
  16.  * and time last modified.
  17.  *
  18.  * These are, by nature, system dependant functions.  But they are also, by
  19.  * nature, very expendable.
  20.  *
  21.  * Language: Computer Innovations Optimizing C86
  22.  */
  23. #include <stdio.h>
  24. #include "arc.h"
  25.  
  26. #if    MSDOS
  27. #include <dos.h>
  28. #include <sys/types.h>
  29. #include <sys/stat.h>
  30. #include <sys/utime.h>
  31. #include <time.h>
  32. #endif
  33.  
  34. #if    UNIX
  35. #include <sys/types.h>
  36. #include <sys/stat.h>
  37. #include <time.h>
  38.  
  39. struct timeval {    /* man page said <sys/types.h>, but it */
  40.     long tv_sec;    /* really seems to be in <sys/time.h>, */
  41.     long tv_usec;    /* but why bother... */
  42. };
  43. #endif
  44.  
  45. #if    GEMDOS
  46. #include <osbind.h>
  47. #endif
  48.  
  49. char    *strcpy(), *strcat(), *malloc();
  50.  
  51. void
  52. getstamp(f, date, time)        /* get a file's date/time stamp */
  53.     FILE           *f;    /* file to get stamp from */
  54.         unsigned    *date, *time;  /* storage for the stamp */
  55. {
  56. #if    GEMDOS
  57.     int    fd, ret[2];
  58.  
  59.     fd = fileno(f);
  60.     Fdatime(ret, fd, 0);
  61.     *date = ret[1];
  62.     *time = ret[0];
  63. #endif
  64. #if     UNIX || MSDOS
  65.     struct stat    buf;
  66.     struct tm    *localtime(), *t;
  67.  
  68.     fstat(fileno(f), &buf);
  69.     t=localtime(&(buf.st_mtime));
  70.     *date = (unsigned short) (((t->tm_year - 80) << 9) +
  71.                 ((t->tm_mon + 1) << 5) + t->tm_mday);
  72.     *time = (unsigned short) ((t->tm_hour << 11) +
  73.                 (t->tm_min << 5) + t->tm_sec / 2);
  74. #endif
  75. }
  76.  
  77. void
  78. setstamp(f, date, time)        /* set a file's date/time stamp */
  79.     char           *f;    /* filename to stamp */
  80.     unsigned short    date, time;    /* desired date, time */
  81. {
  82. #if     MSDOS
  83.     struct tm    tm;
  84.         struct utimbuf  utb;
  85.  
  86.         tm.tm_sec  = (time & 31) * 2;
  87.         tm.tm_min  = (time >> 5) & 63;
  88.     tm.tm_hour = (time >> 11);
  89.     tm.tm_mday = date & 31;
  90.         tm.tm_mon  = ((date >> 5) & 15) - 1;
  91.         tm.tm_year = (date >> 9) + 80;
  92.  
  93.         utb.actime  = mktime(&tm);
  94.         utb.modtime = mktime(&tm);
  95.         utime(f, &utb);
  96. #endif
  97. #if    GEMDOS
  98.     int    fd, set[2];
  99.  
  100.     fd = Fopen(f, 0);
  101.     set[0] = time;
  102.     set[1] = date;
  103.     Fdatime(set, fd, 1);
  104.     Fclose(fd);
  105. #endif
  106. #if    UNIX
  107.     struct tm    tm;
  108.     struct timeval  tvp[2];
  109.         int     utimes();
  110.  
  111.     tm.tm_sec = (time & 31) * 2;
  112.     tm.tm_min = (time >> 5) & 63;
  113.     tm.tm_hour = (time >> 11);
  114.     tm.tm_mday = date & 31;
  115.     tm.tm_mon = ((date >> 5) & 15) - 1;
  116.     tm.tm_year = (date >> 9) + 80;
  117.     tvp[0].tv_sec = tmclock(&tm);
  118.     tvp[1].tv_sec = tvp[0].tv_sec;
  119.     tvp[0].tv_usec = tvp[1].tv_usec = 0;
  120.     utimes(f, tvp);
  121. #endif
  122. }
  123.  
  124. #if    UNIX
  125. int
  126. izadir(filename)        /* Is filename a directory? */
  127.     char           *filename;
  128. {
  129.     struct stat     buf;
  130.  
  131.     if (stat(filename, &buf) != 0)
  132.         return (0);    /* Ignore if stat fails since */
  133.     else
  134.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  135. }
  136. #endif
  137.