mov bx, Handle ;handle of file or device
mov ah, 3Eh ;Close File with Handle
int 21h
jc error_handler ;carry set means error
Close File with Handle (Function 3Eh) closes a file opened or created with a file-handle function.
Handle
Identifies the file to close.
If the function is successful, the carry flag is clear. Otherwise, the carry flag is set and the AX register contains an error value, which may be 0006h (ERROR_INVALID_HANDLE).
When MS-DOS processes this function, any internal buffer for the file is flushed (any pending write operations are completed), any locked regions of the file are unlocked, and the directory is updated to reflect any changes in the file size, date, or time.
Although closing a file invalidates the corresponding handle, MS-DOS may reuse the handle to identify a file that is subsequently opened or created. Programs can use Is File or Device Remote (Function 440Ah) to determine whether a given handle is valid.
Function 3Ch Create File with Handle
Function 3Dh Open File with Handle
Function 440Ah Is File or Device Remote
Function 5Ah Create Temporary File
Function 5Bh Create New File
Function 6Ch Extended Open/Create