include	clib.inc
include	errno.inc
include	io.inc

PPROC close, osfhnd:word
	mov	ax,osfhnd
	cmp     ax,3
	jb	close_ebadf
	cmp	ax,_nfile
	ja	close_ebadf
	mov	bx,ax
	mov	[bx+_osfile],0
	mov	ah,3Eh
	int	21h
	jc	close_error
	xor	ax,ax
    close_end:
	ret
    close_error:
	call	@dosmaper
	mov     ax,-1
	jmp     close_end
    close_ebadf:
	mov	errno,EBADF
	mov	doserrno,0
	xor	ax,ax
	jmp     close_end
PEND close

	END
