home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 28 / amigaformatcd28.iso / -seriously_amiga- / archivers / arcppc / src / arcdos.c < prev    next >
C/C++ Source or Header  |  1998-04-23  |  5KB  |  205 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 "fileio2.h"        /* needed for filehand */
  28. #endif
  29.  
  30. #if    UNIX
  31. #include <sys/types.h>
  32. #include <sys/stat.h>
  33. #include <time.h>
  34.  
  35. struct timeval {    /* man page said <sys/types.h>, but it */
  36.     long tv_sec;    /* really seems to be in <sys/time.h>, */
  37.     long tv_usec;    /* but why bother... */
  38. };
  39. #endif
  40.  
  41. #if    GEMDOS
  42. #include <osbind.h>
  43. #endif
  44.  
  45. char    *strcpy(), *strcat(), *malloc();
  46.  
  47. void
  48. getstamp(f, date, time)        /* get a file's date/time stamp */
  49. #if    !MTS
  50.     FILE           *f;    /* file to get stamp from */
  51. #else
  52.     char           *f;    /* filename "" "" */
  53. #endif
  54.     unsigned short   *date, *time;    /* storage for the stamp */
  55. {
  56. #if    MSDOS
  57.     struct {
  58.         int             ax, bx, cx, dx, si, di, ds, es;
  59.     }               reg;
  60.  
  61.     reg.ax = 0x5700;    /* get date/time */
  62.     reg.bx = filehand(f);    /* file handle */
  63.     if (sysint21(®, ®) & 1)    /* DOS call */
  64.         printf("Get timestamp fail (%d)\n", reg.ax);
  65.  
  66.     *date = reg.dx;        /* save date/time */
  67.     *time = reg.cx;
  68. #endif
  69. #if    GEMDOS
  70.     int    fd, ret[2];
  71.  
  72.     fd = fileno(f);
  73.     Fdatime(ret, fd, 0);
  74.     *date = ret[1];
  75.     *time = ret[0];
  76. #endif
  77. #if    UNIX
  78.     struct stat    buf;
  79.     struct tm    *localtime(), *t;
  80.  
  81.     fstat(fileno(f), &buf);
  82.     t=localtime(&(buf.st_mtime));
  83.     *date = (unsigned short) (((t->tm_year - 80) << 9) +
  84.                 ((t->tm_mon + 1) << 5) + t->tm_mday);
  85.     *time = (unsigned short) ((t->tm_hour << 11) +
  86.                 (t->tm_min << 5) + t->tm_sec / 2);
  87. #endif
  88. #if    MTS
  89.     fortran         timein(),
  90. #if    USEGFINFO
  91.                     gfinfo();
  92. #else
  93.                     fileinfo();
  94. #endif
  95.     int             stclk[2];
  96.     char            name[24];
  97.     struct bigtime {
  98.         int             greg;
  99.         int             year;
  100.         int             mon;
  101.         int             day;
  102.         int             hour;
  103.         int             min;
  104.         int             sec;
  105.         int             usec;
  106.         int             week;
  107.         int             toff;
  108.         int             tzn1;
  109.         int             tzn2;
  110.     }               tvec;
  111. #if    USEGFINFO
  112.     static int      gfflag = 0x0009, gfdummy[2] = {
  113.                                0, 0
  114.     };
  115.     int             gfcinfo[18];
  116. #else
  117.     static int      cattype = 2;
  118. #endif
  119.  
  120.     strcpy(name, f);
  121.     strcat(name, " ");
  122. #if    USEGFINFO
  123.     gfcinfo[0] = 18;
  124.     gfinfo(name, name, &gfflag, gfcinfo, gfdummy, gfdummy);
  125.     timein("*IBM MICROSECONDS*", &gfcinfo[16], &tvec);
  126. #else
  127.     fileinfo(name, &cattype, "CILCCT  ", stclk);
  128.     timein("*IBM MICROSECONDS*", stclk, &tvec);
  129. #endif
  130.  
  131.     *date = (unsigned short) (((tvec.year - 1980) << 9) + ((tvec.mon) << 5) + tvec.day);
  132.     *time = (unsigned short) ((tvec.hour << 11) + (tvec.min << 5) + tvec.sec / 2);
  133. #endif
  134. }
  135.  
  136. void
  137. setstamp(f, date, time)        /* set a file's date/time stamp */
  138.     char           *f;    /* filename to stamp */
  139.     unsigned short    date, time;    /* desired date, time */
  140. {
  141. #if    MSDOS
  142.     FILE    *ff;
  143.     struct {
  144.         int             ax, bx, cx, dx, si, di, ds, es;
  145.     }               reg;
  146.  
  147.     ff = fopen(f, "w+");    /* How else can I get a handle? */
  148.  
  149.     reg.ax = 0x5701;    /* set date/time */
  150.     reg.bx = filehand(f);    /* file handle */
  151.     reg.cx = time;        /* desired time */
  152.     reg.dx = date;        /* desired date */
  153.     if (sysint21(®, ®) & 1)    /* DOS call */
  154.         printf("Set timestamp fail (%d)\n", reg.ax);
  155.     fclose(ff);
  156. #endif
  157. #if    GEMDOS
  158.     int    fd, set[2];
  159.  
  160.     fd = Fopen(f, 0);
  161.     set[0] = time;
  162.     set[1] = date;
  163.     Fdatime(set, fd, 1);
  164.     Fclose(fd);
  165. #endif
  166. #if    UNIX
  167.     struct tm    tm;
  168.     struct timeval  tvp[2];
  169.     int    utimes();
  170.     tm.tm_sec = (time & 31) * 2;
  171.     tm.tm_min = (time >> 5) & 63;
  172.     tm.tm_hour = (time >> 11);
  173.     tm.tm_mday = date & 31;
  174.     tm.tm_mon = ((date >> 5) & 15) - 1;
  175.     tm.tm_year = (date >> 9) + 80;
  176.     tvp[0].tv_sec = tmclock(&tm);
  177.     tvp[1].tv_sec = tvp[0].tv_sec;
  178.     tvp[0].tv_usec = tvp[1].tv_usec = 0;
  179.     utimes(f, tvp);
  180. #endif
  181. }
  182.  
  183. #if    MSDOS
  184. int
  185. filehand(stream)        /* find handle on a file */
  186.     struct bufstr  *stream;    /* file to grab onto */
  187. {
  188.     return stream->bufhand;    /* return DOS 2.0 file handle */
  189. }
  190. #endif
  191.  
  192. #if    UNIX
  193. int
  194. izadir(filename)        /* Is filename a directory? */
  195.     char           *filename;
  196. {
  197.     struct stat     buf;
  198.  
  199.     if (stat(filename, &buf) != 0)
  200.         return (0);    /* Ignore if stat fails since */
  201.     else
  202.         return (buf.st_mode & S_IFDIR);    /* bad files trapped later */
  203. }
  204. #endif
  205.