home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / dmake40.zip / msdos / bccdos / utime.c < prev   
C/C++ Source or Header  |  1994-10-23  |  809b  |  43 lines

  1. /*
  2. ** change access and modify times of file
  3. */
  4. #include <sys/stat.h>
  5. #include <fcntl.h>
  6. #include <time.h>
  7.  
  8. int
  9. utime(name, timep)/*
  10. ====================
  11.     Broken for turbo C it only sets the file time to the current time by
  12.     touching a character in the file */
  13. char*    name;
  14. time_t    timep[2];
  15. {
  16.     struct  stat buf;
  17.     int    fil;
  18.     char    data;
  19.  
  20.     if (stat(name, &buf) != 0)
  21.         return (-1);
  22.     if (buf.st_size != 0)  {
  23.         if ((fil = open(name, O_RDWR, S_IWRITE)) < 0)
  24.             return (-1);
  25.         if (read(fil, &data, 1) < 1) {
  26.             close(fil);
  27.             return (-1);
  28.         }
  29.         lseek(fil, 0L, 0);
  30.         if (write(fil, &data, 1) < 1) {
  31.             close(fil);
  32.             return (-1);
  33.         }
  34.         close(fil);
  35.         return (0);
  36.     } else     if ((fil = creat(name, S_IWRITE)) < 0) {
  37.         return (-1);
  38.     } else {
  39.         close(fil);
  40.         return (0);
  41.     }
  42. }
  43.