home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / CLIPPER / MISC / EMXLIB8F.ZIP / EMX / LIB / SYS / UTIMES.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-01-02  |  1.6 KB  |  62 lines

  1. /* sys/utimes.c (emx+gcc) -- Copyright (c) 1992-1993 by Eberhard Mattes */
  2.  
  3. #include <sys/emx.h>
  4. #include <os2emx.h>
  5. #include <string.h>
  6. #include <errno.h>
  7. #include <time.h>
  8. #include <sys/time.h>
  9. #include "syscalls.h"
  10.  
  11. static void _sys_t2p (long sec, PFTIME time, PFDATE date)
  12. {
  13.   struct tm *p;
  14.   USHORT tmp;
  15.  
  16.   p = gmtime (&sec);
  17. #if 0                           /* GCC bug? Abnormal program termination */
  18.   time->twosecs = p->tm_sec / 2;
  19.   time->minutes = p->tm_min;
  20.   time->hours = p->tm_hour;
  21.   date->day = p->tm_mday;
  22.   date->month = p->tm_mon + 1;
  23.   date->year = p->tm_year - 1980 + 1900;
  24. #else
  25.   tmp = (p->tm_sec / 2) + (p->tm_min << 5) + (p->tm_hour << 11);
  26.   *(USHORT *)time = tmp;
  27.   tmp = p->tm_mday + ((p->tm_mon + 1) << 5) + ((p->tm_year - 80) << 9);
  28.   *(USHORT *)date = tmp;
  29. #endif
  30. }
  31.  
  32.  
  33. int __utimes (const char *name, const struct timeval *tvp)
  34. {
  35.   ULONG rc;
  36.   FILESTATUS3 info;
  37.  
  38.   if ((name[0] == '/' || name[0] == '\\') && strlen (name) >= 6 &&
  39.       memicmp (name+1, "pipe", 4) == 0 && (name[5] == '/' || name[5] == '\\'))
  40.     {
  41.       errno = ENOENT;
  42.       return (-1);
  43.     }
  44.   rc = DosQueryPathInfo (name, FIL_STANDARD, &info, sizeof (info));
  45.   if (rc != 0)
  46.     {
  47.       _sys_set_errno (rc);
  48.       return (-1);
  49.     }
  50.   *(USHORT *)&info.ftimeCreation = 0;
  51.   *(USHORT *)&info.fdateCreation = 0;
  52.   _sys_t2p (tvp[0].tv_sec, &info.ftimeLastAccess, &info.fdateLastAccess);
  53.   _sys_t2p (tvp[1].tv_sec, &info.ftimeLastWrite, &info.fdateLastWrite);
  54.   rc = DosSetPathInfo (name, FIL_STANDARD, &info, sizeof (info), 0);
  55.   if (rc != 0)
  56.     {
  57.       _sys_set_errno (rc);
  58.       return (-1);
  59.     }
  60.   return (0);
  61. }
  62.