_dos_open

Description

Opens a file, using system call 0x3D.

#include <dos.h>    
#include <errno.h>    
#include <fcntl.h> Access mode constants  
#include <share.h> Sharing mode constants  

unsigned _dos_open( char *filename, unsignedmode, int *handle );

filename Path to an existing file  
mode Permissions  
handle Pointer to integer  

Remarks

The _dos_open routine uses system call 0x3D to open the existing file pointed to by filename. The handle for the opened file is copied into the integer pointed to by handle. The mode argument specifies the file's access, sharing, and inheritance modes by combining (with the OR operator) manifest constants from the three groups shown below. At most, one access mode and one sharing mode can be specified at a time.

Constant Mode Meaning

_O_RDONLY Access Read-only
_O_WRONLY Access Write-only
_O_RDWR Access Both read and write
_SH_COMPAT Sharing Compatibility
_SH_DENYRW Sharing Deny reading and writing
_SH_DENYWR Sharing Deny writing
_SH_DENYRD Sharing Deny reading
_SH_DENYNO Sharing Deny neither
_O_NOINHERIT Inheritance by the child process File is not inherited

Do not use the DOS interface I/O routines in conjunction with the console, low-level, or stream I/O routines.

Return Value

If successful, the function returns 0. Otherwise, it returns the DOS error code and sets errno to one of the following manifest constants:

Constant Meaning

EACCES Access denied (possible reasons include specifying a directory or volume ID for filename, or opening a read-only file for write access)
EINVAL Sharing mode specified when file sharing not installed, or access-mode value is invalid
EMFILE Too many open file handles
ENOENT Path or file not found

Compatibility

Standards:None

16-Bit:DOS, QWIN, WIN, WIN DLL

32-Bit:None

See Also

_dos_close, _dos_read, _dos_write

Example

/* DOPEN.C: This program uses DOS I/O functions to open and close a file. */

#include <fcntl.h>

#include <stdio.h>

#include <dos.h>

void main( void )

{

int fh;

/* Open file with _dos_open function */

if( _dos_open( "data1", _O_RDONLY, &fh ) != 0 )

perror( "Open failed on input file\n" );

else

printf( "Open succeeded on input file\n" );

/* Close file with _dos_close function */

if( _dos_close( fh ) != 0 )

perror( "Close failed\n" );

else

printf( "File successfully closed\n" );

}

Output

Open succeeded on input file

File successfully closed