2 Proprietary Rand Corporation
, 1981.
3 Further distribution of
this software
4 subject to the terms of the Rand
10 /* used for input using getc/getw */
11 /* does equivalent to requested seek */
12 /* by doing seek by blocks if necessary, */
13 /* and then adjusting nleft/nextp in iobuf */
14 /* first arg is iobuf pointer, others are identical to seek or lseek */
15 struct { int hiword
, loword
; };
16 struct { char lobyte
, hibyte
; };
24 if (dir%3
== 0) loff
.hiword
= 0;
25 return(lfseek(bp
, loff
, dir
));
28 lfseek(abp
, aloff
, adir
)
32 register byteoff
, blockoff
;
34 register struct iobuf
*bp
;
50 if (bp
->b_nleft
>= 0) {
52 byteoff
= bp
->b_nextp
-bp
->b_buff
;
54 bp
->b_nleft
=+ byteoff
;
58 /* negative nleft means must be at e.o.f */
59 /* drop into rel.-to-end seek */
61 if (fstat(bp
->b_fildes
, &statb
) < 0)
63 lsize
.hiword
.hibyte
= 0;
64 lsize
.hiword
.lobyte
= statb
.i_size0
;
65 lsize
.loword
= statb
.i_size1
;
66 /* adjust loff by size of file */
68 dir
= 0; /* now have offset rel.-to-beg. */
70 /* rel.-to-beginning of file seek */
77 bp
->b_nextp
= bp
->b_buff
;
81 if (dir
!= 1 || blockoff
!= 0) {
82 /* must do the seek */
83 if (seek(bp
->b_fildes
, blockoff
, dir
+3) < 0)
85 bp
->b_nleft
= read(bp
->b_fildes
, &bp
->b_buff
, 512);
87 bp
->b_nleft
=- byteoff
;
88 bp
->b_nextp
=+ byteoff
;