home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume1 / 8707 / 67 / arcdos.c next >
Encoding:
C/C++ Source or Header  |  1990-07-13  |  3.6 KB  |  127 lines

  1. static char *RCSid = "$Header: arcdos.c,v 1.2 86/07/15 07:53:02 turner Exp $";
  2.  
  3. /*
  4.  * $Log:    arcdos.c,v $
  5.  * Hack-attack 1.3  86/12/20  01:23:45  wilhite@usceast.uucp
  6.  *     Bludgeoned into submission for VAX 11/780 BSD4.2
  7.  *    (ugly code, but fewer core dumps)
  8.  *
  9.  * Revision 1.2  86/07/15  07:53:02  turner
  10.  * 
  11.  * 
  12.  * Revision 1.1  86/06/26  15:00:15  turner
  13.  * initial version
  14.  * 
  15.  * 
  16.  */
  17.  
  18. /*  ARC - Archive utility - ARCDOS
  19.  
  20. $define(tag,$$segment(@1,$$index(@1,=)+1))#
  21. $define(version,Version $tag(
  22. TED_VERSION DB =1.43), created on $tag(
  23. TED_DATE DB =11/09/85) at $tag(
  24. TED_TIME DB =22:24:44))#
  25. $undefine(tag)#
  26.     $version
  27.  
  28. (C) COPYRIGHT 1985 by System Enhancement Associates; ALL RIGHTS RESERVED
  29.  
  30.     By:  Thom Henderson
  31.  
  32.     Description:
  33.          This file contains certain DOS level routines that assist
  34.          in doing fancy things with an archive, primarily reading and
  35.          setting the date and time last modified.
  36.  
  37.          These are, by nature, system dependant functions.  But they are
  38.          also, by nature, very expendable.
  39.  
  40.     Language:
  41.          Computer Innovations Optimizing C86
  42. */
  43. #include <stdio.h>
  44. #include "arc.h"
  45. #if MSDOS
  46. #include "fileio2.h"                   /* needed for filehand */
  47. #endif
  48. #if BSD
  49. #include <sys/types.h>
  50. #include <sys/stat.h>
  51. #endif
  52.  
  53. INT getstamp(f,date,time)                  /* get a file's date/time stamp */
  54. FILE *f;                               /* file to get stamp from */
  55. unsigned INT *date, *time;             /* storage for the stamp */
  56. {
  57. #if MSDOS
  58.     struct {INT ax,bx,cx,dx,si,di,ds,es;} reg;
  59.  
  60.     reg.ax = 0x5700;                   /* get date/time */
  61.     reg.bx = filehand(f);              /* file handle */
  62.     if(sysint21(®,®)&1)          /* DOS call */
  63.          printf("Get timestamp fail (%d)\n",reg.ax);
  64.  
  65.     *date = reg.dx;                    /* save date/time */
  66.     *time = reg.cx;
  67. #endif
  68. #if BSD
  69.     struct stat *buf;
  70.     int day,hr,min,sec,yr,imon;
  71.     static char mon[4],*mons[12] = {"Jan","Feb","Mar","Apr","May","Jun","Jul",
  72.                     "Aug","Sep","Oct","Nov","Dec"};
  73.  
  74.     buf = (struct stat *)malloc(sizeof(struct stat));
  75.     fstat(f->_file,buf); 
  76. /*
  77.  * assume the UGLY ibm format for date and time
  78.  */
  79.     sscanf(ctime(&(buf->st_mtime)),"%*4s%3s%d%d:%d:%d%d"
  80.     ,mon,&day,&hr,&min,&sec,&yr);
  81.     for(imon = 0; imon < 12 && strcmp(mon,mons[imon]); imon++);
  82.  
  83.     *date = (unsigned INT)(((yr-1980)<<9)+((imon+1)<<5)+day);
  84.     *time = (unsigned INT)((hr<<11)+(min<<5)+sec/2);
  85. #endif
  86. }
  87.  
  88. INT setstamp(f,date,time)                  /* set a file's date/time stamp */
  89. FILE *f;                               /* file to set stamp on */
  90. unsigned INT date, time;               /* desired date, time */
  91. {
  92. #if MSDOS
  93.     struct {INT ax,bx,cx,dx,si,di,ds,es;} reg;
  94.  
  95.     fflush(f);                         /* force any pending output */
  96.  
  97.     reg.ax = 0x5701;                   /* set date/time */
  98.     reg.bx = filehand(f);              /* file handle */
  99.     reg.cx = time;                     /* desired time */
  100.     reg.dx = date;                     /* desired date */
  101.     if(sysint21(®,®)&1)          /* DOS call */
  102.          printf("Set timestamp fail (%d)\n",reg.ax);
  103. #endif
  104. }
  105.  
  106. static INT filehand(stream)            /* find handle on a file */
  107. struct bufstr *stream;                 /* file to grab onto */
  108. {
  109. #if MSDOS
  110.     return stream->bufhand;            /* return DOS 2.0 file handle */
  111. #endif
  112. }
  113.  
  114. INT izadir(filename)            /* Is filename a directory? */
  115. char *filename;
  116. {
  117. #if MSDOS
  118.     return 0;
  119. #else
  120. struct stat buf;
  121.  
  122.     if (stat(filename,&buf)!=0) return 0;   /* Ignore if stat fails since we */
  123.     else return (buf.st_mode & S_IFDIR);    /* trap for bad file elsewhere.  */
  124.  
  125. #endif
  126. }
  127.