4 <<pread>>---read a file from specified position
13 ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
14 ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
15 void *<[buf]>, size_t <[n]>, off_t <[off]>);
18 The <<pread>> function is similar to <<read>>. One difference is that
19 <<pread>> has an additional parameter <[off]> which is the offset to
20 position in the file before reading. The function also differs in that
21 the file position is unchanged by the function (i.e. the file position
22 is the same before and after a call to <<pread>>).
24 The <<_pread_r>> function is the same as <<pread>>, only a reentrant
25 struct pointer <[rptr]> is provided to preserve reentrancy.
28 <<pread>> returns the number of bytes read or <<-1>> if failure occurred.
31 <<pread>> is non-ANSI and is specified by the Single Unix Specification.
33 Supporting OS subroutine required: <<read>>, <<lseek>>.
41 _pread_r (struct _reent
*rptr
,
48 _READ_WRITE_RETURN_TYPE num_read
;
50 if ((cur_pos
= _lseek_r (rptr
, fd
, 0, SEEK_CUR
)) == (off_t
)-1)
53 if (_lseek_r (rptr
, fd
, off
, SEEK_SET
) == (off_t
)-1)
56 num_read
= _read_r (rptr
, fd
, buf
, n
);
58 if (_lseek_r (rptr
, fd
, cur_pos
, SEEK_SET
) == (off_t
)-1)
61 return (ssize_t
)num_read
;
72 return _pread_r (_REENT
, fd
, buf
, n
, off
);
75 #endif /* !_REENT_ONLY */
76 #endif /* !_NO_PREAD */