include	clib.inc
include	errno.inc

PPROC lseek, handle:word, offs:dword, pos:word
	mov	ax,4200h
	add	ax,pos
	mov	bx,handle
	mov	cx,word ptr offs+2
	mov	dx,word ptr offs
	int	21h
	jc	lseek_error
	cmp	dx,-1
	jne	lseek_end
	cmp	ax,-1
	je	lseek_negseek
    lseek_end:
	ret
    lseek_negseek:
	xor	cx,cx
	mov	dx,cx
	mov	ax,4200h
	int	21h
	mov	ax,ER_NEGATIVE_SEEK
    lseek_error:
	call	@dosmaper
	mov	ax,-1
	mov	dx,ax
	jmp	lseek_end
PEND	lseek

	END