Function 3Dh            Open File with Handle

Opens any file with the specified access code, for input or
output.

Entry AH = 3Dh
AL = Open mode (access code)
DS:DX = Pointer to ASCIIZ filename

Return AX = File handle, if CF clear
or
AX = Error code, if CF is set
| 02h File not found
| 03h Path not found
| 04h No handle available
| 05h Access denied
| 0Ch Open mode invalid

──────────────────────────────────────────────────────────────────

Function 3Dh opens the file whose pathname is specified in the
ASCIIZ string at DS:DX. This function opens any existing file,
including hidden and system files. The access code byte in AL
specifies the modes with which to open the file (see following).

When the file is opened, the file pointer is set to zero (the
first byte in the file). This function returns the error value 5
if a program attempts to open a directory or volume identifier or
to open a read-only file for write access.

──────────────────────────────────────────────────────────────────
The access code in AL can be a combination (ORable) of values from
the following table. The access value is required; the sharing and
inheritance values are optional:

open_access_readonly = 00h Open the file for read-only
access
open_access_writeonly = 01h Open the file for write-only
access
open_access_readwrite = 02h Open the file for read-and-
write access

open_share_compatibility = 00h Permit other programs any
access to the file. On a
given computer, any program
can open the file any number
of times with this mode. This
is the default sharing value
open_share_denyreadwrite = 10h Do not permit any other
program to open the file
open_share_denywrite = 20h Do not permit any other
program to open the file
for write access
open_share_denyread = 30h Do not permit any other
program to open the file
for read access
open_share_denynone = 40h Permit other programs read or
write access, but no program
may open the file for
compatibility access

open_flags_noinherit = 80h A child program created with
function 4b00h (EXEC) does
not inherit the file handle.
If this mode is not set,
child programs inherit the
file handle

──────────────────────────────────────────────────────────────────

Note
If the SHARE program is not loaded, DOS ignores the following
modes: open_share_denyreadwrite, open_share_denywrite,
open_share_denyread, and open_share_denynone. If this function
fails because of a file-sharing error, a subsequent call to
function 59h (get extended error) returns the error value that
specifies a sharing violation.

If the specified file is on a network drive, this function opens
the file only if the network has granted read access, write
access, or read-and-write access to the drive or directory.

Child processes that inherit files also inherit their sharing and
access restrictions.