Watcom C Library Reference : _dos_setdrive, _dos_setfileattr, _dos_setftime, _dos_settime
Watcom C Reference/D - E - F 2021. 6. 22. 17:35
Watcom C Library Reference : _dos_setdrive, _dos_setfileattr, _dos_setftime, _dos_settime
_dos_setdrive
Synopsis : #include <dos.h>
void _dos_setdrive ( unsigned drive, unsigned *total );
Description : The _dos_setdrive function uses system call 0x0E to set the current default disk drive to be the drive specified by drive, where 1 = drive A, 2 = drive B, etc. The total number of disk drives is returned in the word pointed to by total. For DOS versions 3.0 or later minimum number of drives returned is 5.
Returns : The _dos_setdrive function has no return value. If an invalid drive number drive number is specified, the function fails with no error indication. You must use the _dos_getdrive function to check that the desired drive has been set.
See Also : _dos_getdiskfree, _dos_getdrive
Example :
#include <stdio.h>
#include <dos.h>
void main( )
{
unsigned drive1, drive2, total;
_dos_getdrive ( &drive1 );
printf( "Current drive is %c\n", 'A' + drive1 - 1);
/* try to change to drive c */
_dos_setdrive ( 3, &total );
_dos_getdrive ( &drive2 );
printf( "Current drive is %c\n", 'A' + drive2 - 1);
/* go back to original drive */
_dos_setdrive( drive1, &total );
_dos_getdrive( &drive1 );
printf( "Current drive is %c\n", 'A' + drive1 - 1);
printf( "Total number of drives is %u\n", total );
}
produces the following:
Current drive is D
Current drive is C
Total number of drives is 6
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
_dos_setfileattr
Synopsis : #include <dos.h>
unsigned _dos_setfileattr( char *path, unsigned attributes );
Description : The _dos_setfileattr function uses system call 0x43 to set the attributes of the file or directory that path points to. The possible attributes are:
Attribute | Meaning |
_A_NORMAL | Indicates a normal file. File can be read or written without any restrictions. |
_A_RDONLY | Indicates a read-only file. File cannot be opened for "write". |
_A HIDDEN | Indicates a hidden file. This file will not show up in a normal directory search. |
_A_SYSTEM | Indicates a system file. This file will not show up in a normal directory search. |
_A_VOLID | Indicates a volume-ID. |
_A_SUBDIR | Indicates a sub-directory. |
_A_ARCH | This is the archive flag. It is set whenever the file is modified, and is cleared by the MS-DOS BACKUP command and other backup utility programs. |
Returns : The _dos_setfileattr function returns zero if successful. Otherwise, it returns an MS-DOS error code and sets errno to one of the following:
Constant | Meaning |
ENOENT | No file or directory matched the specified path. |
EACCES | Access denied; cannot change the volume ID or the subdirectory. |
See Also : _dos_getfileattr
Example :
#include <stdio.h>
#include <dos.h>
print_attribute( )
{
unsigned attribute;
_dos_getfileattr( "file", &attribute );
printf( "File attribute is %x\n", attribute );
if( attribute & _A_RDONLY ) {
printf( "This is a read-only file\n" );
} else {
printf( "This is not a read-only file\n" );
}
}
void main( )
{
int handle;
if( _dos_creat ( "file", _A_RDONLY, &handle ) != 0 ) {
printf( "Error creating file\n" );
}
print_attribute( );
_dos_setfileattr( "file", _A_NORMAL );
print_attribute( );
_dos_close( handle );
}
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
_dos_setftime
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 | Meaninga |
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 | Meaninga |
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:
Constant | Meaning |
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/31/1999 at 14:32:46
The file was last modified on 12/31/1999 at 12:00:00
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
_dos_settime
Synopsis : #include <dos.h>
unsigned _dos_settime ( struct dostime_t *time );
struct dostime_t {
unsigned char hour; /* 0-23 */
unsigned char minute; /* 0-59 */
unsigned char second; /* 0-59 */
unsigned char hsecond; /* 1/100 second; 0-99 */
};
Description : The _dos_settime function uses system call 0x2D to set the current system time the time information is passed in a dostime_t structure pointed to by time.
Returns : The _dos_settime function returns zero if successful. Otherwise, it returns a non-zem value and sets errno to EINVAL indicating that an invalid time was given.
See Also : _dos_getdate, _dos_setdate, _dos_gettime, gmtime, localtime, mktim, time
Example :
#include <stdio.h>
#include <dos.h>
void main( )
{
struct dosdate_t date;
struct dostime_t time;
/* Get and display the current date and time */
_dos_getdate( &date );
_dos_gettime ( &time );
printf( "The date (MM-DD-YYYY) is : %d-%d-%d\n", date.month, date.day, date.year );
printf( "The time (HH:MM:SS) is : %.2d:%.2d:%.2d\n", time.hour, time.minute, time.second );
/* Change it to the turn of the century */
date.year = 1999;
date.month = 12;
date.day = 31;
time.hour = 23;
time.minute = 59;
_dos_setdate( &date );
_dos_settime ( &time );
printf( "New date (MM-DD-YYYY) is : %d-%d-%d\n", date.month, date.day, date.year );
printf( "New time (HH:MM:SS) is : %.2d:%.2d:%.2d\n", time.hour, time.minute, time.second );
}
produces the following:
The date (MM-DD-YYYY) is : 12-25-1995
The time (HH:MM:SS) is: 14:23:58
New date (MM-DD-YYYY) is: 12-31-1999
New time (HH:MM:SS) is: 23:59:59
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
This manual describes the WATCOM C library for DOS, Windows, and OS/2, It includes the Standard C Library (as defined in the ANSI C Standard).
WATCOM C Language Reference manual describes the ANSI C Programming language and extensions to it which are supported by WATCOM C/C++ (32bit)