* NAMES: bread(), brseek(), blseek()
* This is a buffered read package.
* Bread may be called with a negative nbytes which causes it to
* read backwards. In this case, buffer should point to the first
* byte following the buffer. If only a partial read is possible
* (due to beginning of file), only the last bytes of the buffer
struct brbuf
*brs
; char *buff
; {
for (nb
=nbytes
; nb
>0; nb
--) {
brs
->nr
= read(brs
->fd
, brs
->next
=brs
->b
, 512);
if (brs
->nr
< 0) return(-1);
if (brs
->nr
== 0) return(nbytes
-nb
);
for (nb
=nbytes
; nb
>0; nb
--) {
lseek(brs
->fd
, (long) -(512 + brs
->nr
), 1);
brs
->nl
= read(brs
->fd
, brs
->b
, 512);
brs
->nl
= read(brs
->fd
, brs
->b
, k
);
if (brs
->nl
< 0) return(nbytes
-nb
);
if (brs
->nl
== 0) return(nbytes
-nb
);
brs
->next
= brs
->b
+ brs
->nl
;
blseek(brs
, offset
, flag
)
struct brbuf
*brs
; long offset
; {
return(lseek(brs
->fd
,offset
,flag
));