Watcom C Library Reference : _dos_getdate, _dos_getdiskfree, _dos_getdrive, _dos_getfileattr
Watcom C Reference/D - E - F 2021. 6. 21. 12:37
Watcom C Library Reference : _dos_getdate, _dos_getdiskfree, _dos_getdrive, _dos_getfileattr
_dos_getdate
Synopsis : #include <dos.h>
void _dos_getdate( struct dosdate_t *date );
struct dosdate_t {
unsigned char day; /* 1-31 */
unsigned char month; /* 1-12 */
unsigned short year; /* 1980-2099 */
unsigned char dayofweek; /* 0-6 (0=Sunday) */
};
Description : The _dos_getdate function uses system call 0x2A to get the current system date. The date information is returned in a dosdate_t structure pointed to by date.
Returns : The _dos-getdate function has no return value.
See Also : _dos_gettime, _dos_setdate, _dos_settime, gmtime, localtime, mktime, 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 );
}
produces the following:
The date (MM-DD-YYYY) is : 12-25-1989
The time (HH:MM:SS) is : 14:23:57
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
_dos_getdiskfree
Synopsis : #include <dos.h>
unsigned _dos_getdiskfree ( unsigned drive, struct diskfree_t *diskspace );
struct diskfree_t {
unsigned short total_clusters;
unsigned short avail_clusters;
unsigned short sectors_per-cluster;
unsigned short bytes_per_sector;
};
Description : The _dos_getdiskfree function uses system call 0x36 to obtain useful information on the disk drive specified by drive. Specify 0 for the default drive, 1 for drive A, 2 for drive B. etc. The information about the drive is returned in the structure diskfree_t pointer to by diskspace.
Returns : The _dos_getdiskfree function returns zero if successful. Otherwise, it returns a non-zero value and sets errno to EINVAL indicating an invalid drive was specified.
See Also : _dos_getdrive, _dos_setdrive
Example :
#include <stdio.h>
#include <dos.h>
void main( )
{
struct diskfree_t disk_data;
/* get information about drive 3 (the C drive) */
if( _dos_getdiskfree( 3, &disk_data ) == 0 ) {
printf( "total clusters: %u\n", disk_data.total_clusters );
printf( "available clusters: %u\n", disk_data.avail_clusters );
printf( "sectors/cluster: %u\n", disk_data.sectors_per_cluster );
printf( "bytes per sector: %u\n", disk_data.bytes_per_sector );
} else {
printf( "Invalid drive specified\n" );
}
}
produces the following:
total clusters: 16335
available clusters: 510
sectors/cluster: 4
bytes per sector: 512
Classification : DOS
Systems : DOS, Win, NT, DOS/PM
_dos_getdrive
Synopsis : #include <dos.h>
void _dos_getdrive ( unsigned *drive );
Description : The _dos_getdrive function uses system call Ox19 to get the current disk drive number. The current disk drive number is returned in the word pointed to by drive. A value of 1 is drive A, 2 is drive B, 3 is drive C, etc.
Returns : The _dos_getdrive function has no return value.
See Also : _dos_getdiskfree, _dos_setdrive
Example :
#include <stdio.h>
#include <dos.h>
void main( )
{
unsigned drive;
_dos_getdrive ( &drive );
printf( "The current drive is %c\n", 'A' + drive - 1);
}
produces the following:
The current drive is C
Classification : DOS
Systems : DOS, Win, OS/2 1.x(all), OS/2 2.x, NT, DOS/PM
_dos_getfileattr
Synopsis : #include <dos.h>
unsigned _dos_getfileattr( char *path, unsigned *attributes );
Description : The _dos_getfileattr function uses system call 0x43 to get the current 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_getfileattr function returns zero if successful. Otherwise, it returns a MS-DOS error code and sets errno to ENOENT indicating that no file matched the path.
See Also : _dos_setfileattr
Example :
#include <stdio.h>
#include <dos.h>
print_attribute( )
{
unsigned attribute;
_dos_getfileattr( "file", &attribute );
printf( "File attribute is %d\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
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)