	.title	rrwd	Rewind a stream pointer
	.ident	"V02.00"
;+
; Index		Rewind a stream pointer
;
; Usage
;
;	rrwd(stream, options [, kor])
;	int stream;    /* Stream number from open/create */
;	char *options; /* Option string */
;	int kor;       /* New key-of-reference number */
;		       /* (if "s" option was given) */
;
; Description
;
;	rwd() resets the stream position to the beginning of the file.
;	It returns 0 on error and 1 on success. The following option is
;	available for ISAM files only.
;
;		Option:
;		   s - set key of reference
;-
; Edit History
; V02.00 19-Oct-82 TTC		Rework of old CS library
;
	.MCALL	FSDEF$
	FSDEF$

	.psect	c$strn

skr:	.asciz	"s"
	.even

	.psect	c$data

;
; Rewind option table.
;
rwdopt:	.word	skr,	O.SKR	; *** Note: if this changes look out below!
	.word	0

	.psect	c$code

rrwd::	mov	#FS.RWD,fsqio+q.iofn	; Function: FS.RWD
	mov	4(sp),r0		; r0 --> option string
	mov	#rwdopt,r1		; r1 --> rewind option table
	call	option			; parse option string
	tst	r0			; Error?
	beq	10$			; (Yes)
	bit	#O.SKR,r1		; SKR? (*** HARDWIRED ***)
	beq	5$			; (No)
	swab	r1			; (Yes), pit KOR number into hi byte
	bisb	6(sp),r1
	swab	r1
5$:	mov	#fsqio+q.iopl,r0	; r0 --> qio param list for prmclr
	call	prmclr			; Clear parameter list
	mov	2(sp),fsqio+q.iopl	; Parameter #1: Stream Number
	mov	r1,fsqio+q.iopl+12	; Parameter #6:	Inclu-or of option
	mov	#fsqio,r0		; r0 must = qio for xqiow
	call	.xqiow			; execute qiow
	mov	#1,r0			; Assume success
	cmp	$dsw,#is.suc		; How'd it go
	blo	10$			; Not so good
	cmpb	f.iosb,#is.suc
	beq	20$
10$:	clr	r0			; Branch here if error, r0 = 0
20$:	return
	.end
