Q37668 _dos_setftime: File Must Be Opened as Read Only
C Compiler
5.10   | 5.10
MS-DOS | OS/2

Summary:

To use the _dos_setftime function to set the date and time to which a
file was last written, open the file as read only. If you open the
file with write privileges, the time and date are re-updated by the
close function. The program below demonstrates the correct useage;
however, it only works in DOS, not in the OS/2 compatibility box,
where it gives an error message "invalid argument" and returns err =
1.

More Information:

The following code demonstrates this behavior:

 #include <stdio.h>
 #include <dos.h>
 #include <fcntl.h>
 #include <sys\types.h>
 #include <sys\stat.h>
 #include <io.h>
 #include <stdlib.h>

 main()
  {
    unsigned date = 0x421;
    unsigned time = 0xC0F;
    int fh, err;

    if (_dos_open("hang.c",O_RDONLY, &fh) != 0)
       perror("open failed on input file");
    else
       printf("opend succeeded on input file\n");
    err = _dos_setftime (fh, date, time);
    if (err != 0)
     {
       perror("date and time not changed");
       printf("%d\n",err);
     }
    else
       printf("date and time changed\n");
    if (_dos_close(fh) != 0)
       perror("close failed");
    else
       printf("file successfully closed\n");
  }

Keywords:  docerr buglist5.10
Updated  88/11/09 05:51
