include	clib.inc
include	io.inc
include	iost.inc
include wsub.inc
include	errno.inc

	extrn	copy_jump:word

PPROC	wscopy_remove	; AX: offset of file to remove
	push	ds
	push	ax
	invoke	oclose,addr STDO
	call	remove
	mov	ax,-1
	ret
PEND	wscopy_remove

PPROC	wscopy_open	; AX: offset srcfile
	push	si	; DX: offset outfile
	push	di
	mov	si,ax
	mov	di,dx
	mov	errno,0
	push	ds
	push	dx
	push	M_WRONLY
	call	oopen
	cmp	ax,-1		; -1 == error
	je	wscopy_open_end
	test	ax,ax		;  0 == jump
	jz	wscopy_open_jmp
	push	ds
	push	si
	push	M_RDONLY
	call	oopen
	cmp	ax,-1
	je	wscopy_open_error
    wscopy_open_end:
	pop	di
	pop	si
	ret
    wscopy_open_jmp:
	mov	copy_jump,1
	jmp	wscopy_open_end
    wscopy_open_error:
	mov	dx,ds
	mov	ax,si
	call	eropen
	mov	ax,di
	call	wscopy_remove
	jmp	wscopy_open_end
PEND	wscopy_open

	END
