home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / DLIBSSRC.ZIP / STIME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-07-17  |  1.5 KB  |  68 lines

  1. #include <time.h>
  2.  
  3. extern    long    gemdos();
  4.  
  5. long cnvtime(rawtime, time)
  6. long *rawtime;
  7. register struct tm *time;
  8. /*
  9.  *    Convert <time> structure value to raw time format.  In addition to
  10.  *    returning the raw time value, if the <rawtime> pointer in not NULL,
  11.  *    the value is stored in the long <rawtime> points to. (cf: time)
  12.  */
  13. {
  14.     register long t;
  15.  
  16.     t = (time->tm_year - 80) & 0x7F;
  17.     t <<= 4;
  18.     t |= (time->tm_mon - 1) & 0x0F;
  19.     t <<= 5;
  20.     t |= (time->tm_mday) & 0x1F;
  21.     t <<= 5;
  22.     t |= (time->tm_hour) & 0x1F;
  23.     t <<= 6;
  24.     t |= (time->tm_min) & 0x3F;
  25.     t <<= 5;
  26.     t |= (time->tm_sec >> 1) & 0x1F;
  27.     if(rawtime)
  28.         *rawtime = t;
  29.     return(t);
  30. }
  31.  
  32. void stime(rawtime)
  33. long *rawtime;
  34. /*
  35.  *    Set the system clock to <rawtime>.
  36.  */
  37. {
  38.     register int *ip = rawtime;
  39.  
  40.     gemdos(0x2B, ip[0]);        /* set date from high word */
  41.     gemdos(0x2D, ip[1]);        /* set time from low word */
  42. }
  43.  
  44. int utime(pathname, rawtime)
  45. char *pathname;
  46. long *rawtime;
  47. /*
  48.  *    Set the modification date of <pathname> to <rawtime>.  Returns zero
  49.  *    for success, or a negative error code.
  50.  */
  51. {
  52.     register int h, *ip = rawtime;
  53.     int d_and_t[2];
  54.     long raw;
  55.  
  56.     if(!ip) {
  57.         ip = &raw;                    /* current */
  58.         time(ip);                    /*  time   */
  59.     }
  60.     if((h = ((int) gemdos(0x3D, pathname, 2))) < 0)        /* open */
  61.         return(h);                    /* FAILURE */
  62.     d_and_t[0] = ip[1];                    /* time */
  63.     d_and_t[1] = ip[0];                    /* date */
  64.     gemdos(0x57, d_and_t, h, 1);                /* timestamp */
  65.     gemdos(0x3E, h);                    /* close */
  66.     return(0);                        /* SUCCESS */
  67. }
  68.