Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C/C++ v10.0 : C library - <b>synopsis:</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
    #include <dos.h>
    unsigned _dos_setftime( int handle,
                            unsigned short date,
                            unsigned short time );

Description:
    The _dos_setftime function uses system call 0x57 to set the date and
    time that the file associated with handle was last modified.  The date
    consists of the year, month and day packed into 16 bits as follows:

    bits 0-4
        Day (1-31)

    bits 5-8
        Month (1-12)

    bits 9-15
        Year (0-119 representing 1980-2099)

    The time consists of the hour, minute and seconds/2 packed into 16 bits
    as follows:

    bits 0-4
        Seconds/2 (0-29)

    bits 5-10
        Minutes (0-59)

    bits 11-15
        Hours (0-23)


Returns:
    The _dos_setftime function returns zero if successful.  Otherwise, it
    returns an MS-DOS error code and sets  errno to one of the following
    values:

    EBADF
        Invalid file handle


See Also:
    _dos_getftime

Example:
    #include <stdio.h>
    #include <dos.h>
    #include <fcntl.h>

    #define YEAR(t)   (((t & 0xFE00) >> 9) + 1980)
    #define MONTH(t)  ((t & 0x01E0) >> 5)
    #define DAY(t)    (t & 0x001F)
    #define HOUR(t)   ((t & 0xF800) >> 11)
    #define MINUTE(t) ((t & 0x07E0) >> 5)
    #define SECOND(t) ((t & 0x001F) << 1)

    void main()
      {
        int      handle;
        unsigned short date, time;

        if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
          printf( "Unable to open file\n" );
        } else {
          printf( "Open succeeded\n" );
          _dos_getftime( handle, &date, &time );
          printf( "The file was last modified on %d/%d/%d",
                  MONTH(date), DAY(date), YEAR(date) );
          printf( " at %.2d:%.2d:%.2d\n",
                  HOUR(time), MINUTE(time), SECOND(time) );
          /* set the time to 12 noon */
          time = (12 << 11) + (0 << 5) + 0;
          _dos_setftime( handle, date, time );
          _dos_getftime( handle, &date, &time );
          printf( "The file was last modified on %d/%d/%d",
                  MONTH(date), DAY(date), YEAR(date) );
          printf( " at %.2d:%.2d:%.2d\n",
                  HOUR(time), MINUTE(time), SECOND(time) );
          _dos_close( handle );
        }
      }

    produces the following:

    Open succeeded
    The file was last modified on 12/29/1989 at 14:32:46
    The file was last modified on 12/29/1989 at 12:00:00

Classification:
    DOS

Systems:
    DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM

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