include	clib.inc
include	stdio.inc

PPROC	_ftbuf, flag:word, FP:DPTR
	MLES	bx,FP
	mov	ax,flag
	or	ax,ax
	mov	ax,es:[bx.iob_flag]
	jz	_ftbuf_00
	test	ax,_IOFLRTN
	jz	_ftbuf_01
	push	ax
	push	es
	push	bx
	call	fflush
	pop	ax
	MLES	bx,FP
	and	ax,not (_IOYOURBUF or _IOFLRTN)
	mov	es:[bx.iob_flag],ax
	xor	ax,ax
	mov	word ptr es:[bx.iob_bp],ax
	mov	word ptr es:[bx.iob_bp+2],ax
	mov	word ptr es:[bx.iob_base],ax
	mov	word ptr es:[bx.iob_base+2],ax
	mov	es:[bx.iob_bufsize],ax
	jmp	_ftbuf_01
    _ftbuf_00:
	and	ax,_IOFLRTN
	jz	_ftbuf_01
	push	es
	push	bx
	call	fflush
    _ftbuf_01:
	ret
PEND	_ftbuf

	END
