Function 45h            Duplicate File Handle

Creates a new file handle that can be used to read from or write
to the same file or device that is associated with the original
handle.

Entry AH = 45h
BX = Handle to duplicate

Return AX = Duplicate file handle
or
AX = Error code, if CF is set
| 04h No handles available
| 06h Invalid handle

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

If this function is used to duplicate the handle of an open file,
the file pointer for the new handle is set to the same position as
the pointer for the open handle. Using either handle to read from
or write to the file changes the file pointer for both handles.

Duplicate File Handle can also be used to keep a file open while
its directory entry is changed. If a program creates a duplicate
handle and then closes the duplicate handle, the file's directory
entry is updated (and buffers flushed), but the original handle
remains open (and the file pointer unchanged).

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

Example

; Pre-DOS 3.30 commit file
mov bx,[file_handle] ; Handle of open file
mov ah,45h ; Force Duplicate Handle
int 21h
jc @@error
mov bx,ax ; bx = duplicate handle
mov ah,3eh ; Close duplicate
int 21h
jc @@error