3 <<pread>>---read a file from specified position
12 ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
13 ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
14 void *<[buf]>, size_t <[n]>, off_t <[off]>);
18 ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>)
24 ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
25 struct _reent *<[rptr]>;
32 The <<pread>> function is similar to <<read>>. One difference is that
33 <<pread>> has an additional parameter <[off]> which is the offset to
34 position in the file before reading. The function also differs in that
35 the file position is unchanged by the function (i.e. the file position
36 is the same before and after a call to <<pread>>).
38 The <<_pread_r>> function is the same as <<pread>>, only a reentrant
39 struct pointer <[rptr]> is provided to preserve reentrancy.
42 <<pread>> returns the number of bytes read or <<-1>> if failure occurred.
45 <<pread>> is non-ANSI and is specified by the Single Unix Specification.
47 Supporting OS subroutine required: <<read>>, <<lseek>>.
55 _DEFUN (_pread_r
, (rptr
, fd
, buf
, n
, off
),
56 struct _reent
*rptr _AND
63 _READ_WRITE_RETURN_TYPE num_read
;
65 if ((cur_pos
= _lseek_r (rptr
, fd
, 0, SEEK_CUR
)) == (off_t
)-1)
68 if (_lseek_r (rptr
, fd
, off
, SEEK_SET
) == (off_t
)-1)
71 num_read
= _read_r (rptr
, fd
, buf
, n
);
73 if (_lseek_r (rptr
, fd
, cur_pos
, SEEK_SET
) == (off_t
)-1)
76 return (ssize_t
)num_read
;
82 _DEFUN (pread
, (fd
, buf
, n
, off
),
88 return _pread_r (_REENT
, fd
, buf
, n
, off
);