home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / rcs / sources / utime.c < prev    next >
C/C++ Source or Header  |  1992-01-05  |  748b  |  41 lines

  1. /* utime for MS-DOS */
  2.  
  3. /* by Frank Whaley and Paul Eggert */
  4.  
  5.     /* $Id: utime.c,v 1.1 1992/01/06 03:18:29 eggert Exp $ */
  6.  
  7. #include <dos.h>
  8. #include <fcntl.h>
  9. #include <io.h>
  10. #include <sys/types.h>
  11.  
  12. struct utimbuf { time_t actime, modtime; };
  13.  
  14.     int
  15. utime(file, times)
  16.     char const *file;
  17.     struct utimbuf const *times;
  18. {
  19.     int fd;
  20.     int ret;
  21.     struct date d;
  22.     struct time t;
  23.     struct ftime ft;
  24.  
  25.     if (0  <=  (fd = open(file, O_WRONLY))) {
  26.         unixtodos(times->modtime, &d, &t);
  27.         ft.ft_tsec = t.ti_sec >> 1;
  28.         ft.ft_min = t.ti_min;
  29.         ft.ft_hour = t.ti_hour;
  30.         ft.ft_day = d.da_day;
  31.         ft.ft_month = d.da_mon;
  32.         ft.ft_year = d.da_year;
  33.  
  34.         ret = setftime(fd, &ft);
  35.  
  36.         if (close(fd) == 0)
  37.             return ret;
  38.     }
  39.     return -1;
  40. }
  41.