Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C 6.0 - <b>_dos_setftime() set file date and time</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_setftime()         Set file date and time

 #include   <dos.h>

  unsigned     _dos_setftime(handle, date, time);
  int handle;            File identifier
  unsigned *date;        Date return buffer
  unsigned *time;        Time return buffer

    _dos_setftime() uses MS-DOS function 57h to determine the date and
    time that the file identified by 'handle' was last modified. The date
    and time are returned in locations 'date' and 'time', respectively,
    and are defined as follows:

     Date = (Year - 1980) * 512 + Month * 32 + Day
     Time = Hour * 2048 + Minute * 32 + Second / 2

     Date Bits           Description
        0 - 4            Day (1..31)
        5 - 8            Month (1..12)
        9 - 15           Years since 1980 (0..119)

     Time Bits           Description
        0 - 4            Seconds/2 (0..29)
        5 - 10           Minutes (0..59)
       11 - 15           Hours (0..23)

    Returns:    If successful, _dos_setftime() returns 0, otherwise it
                returns the MS-DOS error code and sets errno to EBADF,
                indicating an invalid file handle.

   Portability:     MS-DOS only, version 2.0 or higher

------------------------------- Example ---------------------------------

 This program sets the date of file "test.c" to 12/31/1990 and the time to
 2:30:00 pm

           #include <dos.h>
           #include <fcntl.h>

           struct d_s  /* bitfields for date */
              {
              unsigned day : 5;
              unsigned month : 4;
              unsigned year : 7;
              };

           struct t_s  /* bitfields for time */
              {
              unsigned second : 5;
              unsigned minute : 6;
              unsigned hour : 5;
              };

           main()
           {
              int handle;
              unsigned return_val;

              union d_u   /*  union to align date word and date bitfields  */
                 {
                 unsigned date;
                 struct d_s date_s;
                 } date_u;

              union t_u   /*  union to align time word and time bitfields  */
                 {
                 unsigned time;
                 struct t_s time_s;
                 } time_u;

              /* open file using _dos_open  */
              return_val = _dos_open("test.c", O_RDWR, &handle);
              if (return_val)
                 printf("Unable to open file -- error code is %u\n",
           return_val);

              /* enter new date values */
              date_u.date_s.year = 1990 - 1980;
              date_u.date_s.month = 12;
              date_u.date_s.day = 31;

              /* enter new time values */
              time_u.time_s.hour = 14;
              time_u.time_s.minute = 30;
              time_u.time_s.second = 00;

              /* set file date and time */
              return_val = _dos_setftime( handle, date_u.date, time_u.time);
              if (return_val)
                 printf("Unable to set file \"test.c\" time and date\n");
              else
                 printf("New date and time set for file \"test.c\"");
           }


See Also: _dos_getftime() _dos_open()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson