3 <<pwrite>>---write a file from specified position
12 ssize_t pwrite(int <[fd]>, const void *<[buf]>,
13 size_t <[n]>, off_t <[off]>);
14 ssize_t _pwrite_r(struct _reent *<[rptr]>, int <[fd]>,
15 const void *<[buf]>, size_t <[n]>, off_t <[off]>);
19 ssize_t pwrite(<[fd]>, <[buf]>, <[n]>, <[off]>)
25 ssize_t _pwrite_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
26 struct _reent *<[rptr]>;
33 The <<pwrite>> function is similar to <<write>>. One difference is that
34 <<pwrite>> has an additional parameter <[off]> which is the offset to
35 position in the file before writing. The function also differs in that
36 the file position is unchanged by the function (i.e. the file position
37 is the same before and after a call to <<pwrite>>).
39 The <<_pwrite_r>> function is the same as <<pwrite>>, only a reentrant
40 struct pointer <[rptr]> is provided to preserve reentrancy.
43 <<pwrite>> returns the number of bytes written or <<-1>> if failure occurred.
46 <<pwrite>> is non-ANSI and is specified by the Single Unix Specification.
48 Supporting OS subroutine required: <<write>>, <<lseek>>.
56 _DEFUN (_pwrite_r
, (rptr
, fd
, buf
, n
, off
),
57 struct _reent
*rptr _AND
64 _READ_WRITE_RETURN_TYPE num_written
;
66 if ((cur_pos
= _lseek_r (rptr
, fd
, 0, SEEK_CUR
)) == (off_t
)-1)
69 if (_lseek_r (rptr
, fd
, off
, SEEK_SET
) == (off_t
)-1)
72 num_written
= _write_r (rptr
, fd
, buf
, n
);
74 if (_lseek_r (rptr
, fd
, cur_pos
, SEEK_SET
) == (off_t
)-1)
77 return (ssize_t
)num_written
;
83 _DEFUN (pwrite
, (fd
, buf
, n
, off
),
89 return _pwrite_r (_REENT
, fd
, buf
, n
, off
);