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_getftime() get date and time file last modified</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _dos_getftime()         Get date and time file last modified

 #include   <dos.h>

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

    _dos_getftime() 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_getftime() 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 gets the date of file "test.c"

           #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);

              /* get file date and time */
              return_val = _dos_getftime( handle, &date_u.date,
           &time_u.time);
              if (return_val)
                 printf("Unable to locate file\n");
              else
                 {
                 printf("The values for year, month, and day are: %u / %u /
           %u\n",
                   date_u.date_s.year + 1980, date_u.date_s.month,
           date_u.date_s.day);
                 printf("The values for hours, minutes, and seconds are: %u :
           %u : %u\n",
                   time_u.time_s.hour, time_u.time_s.minute,
           time_u.time_s.second / 2);
                 }
           }


See Also: _dos_setftime() _dos_open()

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