Watcom C Library Reference : _dos_allocmem, _dos_close, _dos_commit, _dos_creat, _dos_creatnew

 

 

 

 

_dos_allocmem

 

Synopsis : #include <dos.h> 

              unsigned _dos_allocmem ( unsigned size, unsigned short *segment );


Description : The _dos_allocmem function uses system call 0x48 to allocate size paragraphs directly from DOS. The size of a paragraph is 16 bytes. The allocated memory is always paragraph aligned. The segment descriptor for the allocated memory is returned in the word pointed to by segment. If the allocation request fails, the maximum number of paragraphs that can be allocated is returned in this word instead.

 

 

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

 

 

See Also : alloca, calloc. _dos_freemem. _dos_setblock, halloc, malloc



Example :

#include <stdio.h> 

#include <dos.h>


void main( )

{
    unsigned short segment;


    /* 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" );

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

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

        }

    }

}

 

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

 

 

 

 

 

_dos_close

 

Synopsis : #include <dos.h> 

              unsigned _dos_close( int handle );

Description : The _dos_close function uses system call 0x3E to close the file indicated by handle. The value for handle is the one returned by a function call that created or last opened the file.

 

 

Returns : The _dos_close function returns zero if successful. Otherwise, it returns an error code and sets errno to EBADF indicating an invalid file handle.

 

 

See Also : creat, _dos_creat, _dos_creatnew, _dos_open, dup, fclose, open

Example :

#include <stdio.h> 

#include <dos.h> 

#include <fcntl.h>


void main( )

{
    int handle;

 

    /* Try to open "stdio.h" and then close it */

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

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

        if ( _dos_close( handle ) != 0 ) {
            printf( "close failed\n" );

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

        }

    }

}

 

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

 

 

 

 

 

_dos_commit

 

Synopsis : #include <dos.h> 

              int _dos_commit( int handle );

Description : The _dos_commit function uses system call 0x68 to flush to disk the DOS buffers associated with the file indicated by handle. It also forces an update on the corresponding disk directory and the file allocation table.

 

 

Returns : The _dos_commit function returns zero if successful. Otherwise, it returns an MS-DOS error code and sets errno to EBADF indicating an invalid file handle.

 

 

See Also : _dos_close, _dos_creat, _dos_open, _dos_write

Example :

#include <stdio.h> 

#include <dos.h> 

#include <fcntl.h>


void main( )

{
    int handle;

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

    } else {

        if ( _dos_commit( handle ) == 0 ) {
            printf( "Commit succeeded. \n" );

        }
        _dos_close( handle );

    }

}

 

 

produces the following :
Commit succeeded.

 

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

 

 

 

 

 

_dos_creat

 

Synopsis : #include <dos.h> 

              unsigned _dos_creat ( char *path, unsigned attribute, int *handle );



Description : The _dos_creat function uses system call 0x3C to create a new file named path, with the access attributes specified by attribute. The handle for the new file is returned in theword pointed to by handle. If the file already exists, the contents will be erased, and the attributes of the file will remain unchanged. The possible values for attribute 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.

 

 


Returns : The _dos_creat 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 directory is full, or the file exists and cannot be overwritten.
 EMFILE  No more handles available, (too many open files)
 ENOENT  Path or file not found

 

 

See Also : creat, _dos_creatnew, _dos_open, open

 


Example :

#include <stdio.h> 

#include <dos.h>


void main( )

{
    int handle;
    if( _dos_creat ( "file", _A_NORMAL, &handle ) != 0 ) {
        printf( "Unable to create file\n");

    } else {

        printf( "Create succeeded\n");

        _dos_close( handle );

    }

}

 

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

 

 

 

 

 

_dos_creatnew

 

Synopsis : #include <dos.h> 

              unsigned _dos_creatnew( char *path, unsigned attribute, int *handle );


Description : The _dos_creatnew function uses system call 0x5B to create a new file named path. with the access attributes specified by attribute. The handle for the new file is returned in the word pointed to by handle. If the file already exists, the create will fail. The possible values for attribute 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.

 

 

 

Returns : The _dos_creatnew 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 directory is full, or the file exists and cannot be overwritten.
 EEXIST  File already exists
 EMFILE  No more handles available, (too many open files)
 ENOENT  Path or file not found

 

 

See Also : creat, _dos.creat, _dos_open, open

 


Example :

#include <stdio.h> 

#include <dos.h>


void main( )

{
    int handlel, handle2;

    if( _dos_creat ( "file", _A_NORMAL, &handlei ) ) {
        printf( "Unable to create file\n" );

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

        if( _dos_creatnew ( "file", _A_NORMAL, &handle2 ) ) {
            printf( "Unable to create new file\n" );

        }
        _dos_close( handlel );

    }

}

 

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 전화카드
,