'_dos_setdate'에 해당되는 글 1건

  1. 2021.06.22 Watcom C Library Reference : _dos_open, _dos_read, _dos_setblock, _dos_setdate

 

 

Watcom C Library Reference : _dos_open, _dos_read, _dos_setblock, _dos_setdate

 

 

 

 

_dos_open

 

Synopsis : #include <dos.h> 

              #include <fcntl.h>

              #include <share.h>

              unsigned _dos_open( char *path, unsigned mode, int *handle );


Description : The _dos_open function uses system call 0x3D to open the file specified by path, which must be an existing file. The mode argument specifies the file's access, sharing and inheritance permissions. The access mode must be one of:

 Mode  Meaning
 O_RDONLY  Read only
 O_WRONLY  Write only
 O_RDWR  Both read and write

 

  

The sharing permissions, if specified, must be one of:

 Permission  Meaning
 SH_COMPAT  Set compatibility mode.
 SH_DENYRW  Prevent read or write access to the file.
 SH_DENYWR  Prevent write access of the file.
 SH_DENYRD  Prevent read access to the file.
 SH_DENYNO  Permit both read and write access to the file.

 

  

The inheritance permission, if specified, is:

 Permission  Meaning
 O_NOINHERIT  File is not inherited by a child process

 

  


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

 Constant  Meaning
 EACCES  Access denied because path specifies a directory or a volume opening a read-only file for write access
 EINVAL  A sharing mode was specified when file sharing is not installed access-mode value is invalid
 EMFILE  No more handles available, (too many open files)
 ENOENT  Path or file not found

 

 

See Also : _dos_close, _dos_creat, _dos_creatnew, _dos_read, _dos_write, open

 


Example :

#include <stdio.h> 

#include <dos.h> 

#include <fcntl.h> 

#include <share.h>


void main( )

{
    int handle;

 

    if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
        printf( "Unable to open file\n" );

    } else {
        printf( "Open succeeded\n" );

        _dos_close( handle );

    }

}

 

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

 

 

 

 

 

_dos_read

 

Synopsis : #include <dos.h> 

              unsigned _dos_read( int handle, void __far *buffer, unsigned count, unsigned *bytes );


Description : The _dos_read function uses system call 0x3F to read count bytes of data from the tile specified by handle into the buffer pointed to by buffer. The number of bytes successfully read will be stored in the unsigned integer pointed to by bytes.

 

 

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

 Constant  Meaning
 EACCES  Access denied because the file is not open for read access
 EBADF  Invalid file handle

 

 

See Also : _dos_close, _dos_open, _dos_write

 


Example :

#include <stdio.h> 

#include <dos.h> 

#include <fcntl.h>


void main( )

{
    unsigned len_read;

    int handle; 

    auto char buffer[80];


    if( _dos_open( "file", O_RDONLY, &handle ) != 0 ) {
        printf( "Unable to open file\n" );

    } else {

        printf( "Open succeeded\n" );
        _dos read( handle, buffer, 80, &len_read);

        _dos_close( handle );

    }

}

 

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

 

 

 

 

 

_dos_setblock

 

Synopsis : #include <dos.h> 

              unsigned _dos_setblock ( unsigned size, unsigned short segment, unsigned *maxsize );

Description : The _dos_setblock function uses system call 0x4A to change the size of segment was previously allocated by _dos_allocmem, to size paragraphs. If the request fails the maximum number of paragraphs that this memory block can be changed to is returned in the word pointed to by maxsize.

 

 

Returns : The _dos_setblock function returns zero if successful. Otherwise, it returns an MS-DOS error code and sets errno to ENOMEM indicating a bad segment value, insufficient memory or corrupted memory.

 

 

See Also : _dos_allocmem, _dos_freemem, realloc

 


Example :

#include <stdio.h> 

#include <dos.h>


void main( )

{
    unsigned short segment;

    unsigned maxsize;


    /* Try to allocate 100 paragraphs, then free them */

    if( _dos_allocmem ( 100, &segment ) != 0 ) {
        printf( "_dos_allocmem failed\n" );
        printf( "Only %u paragraphs available\n", segment);

    } else {

        printf( "_dos_allocmem succeeded\n" );

 

        /* Try to increase it to 200 paragraphs */

        if ( _dos_setblock ( 200, segment, &maxsize ) != 0 )  {

            printf( "Unable to increase the size\n" );

        }
        if ( _dos_freemem ( segment ) != 0 ) {
            printf( "_dos_freemem failed\n" );

        }

    }

}

 

Classification : DOS
Systems : DOS, DOS/PM

 

 

 

 

 

_dos_setdate

 

Synopsis : #include <dos.h> 

              unsigned _dos_setdate( 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_setdate function uses system call 0x2B to set the current system date. The date information is passed in a dosdate_t structure pointed to by date.

 

 

Returns : The _dos_setdate function returns zero if successful. Otherwise, it returns a non-zero value and sets errno to EINVAL indicating that an invalid date was given.

 

 

See Also : _dos_getdate, _dos_gettime, _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 );

 

    /* 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-1989 

The time (HH:MM:SS) is : 14:23:15

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)

 

 

 

728x90
반응형
Posted by 전화카드
,