4 <<pwrite>>---write a file from specified position
13 ssize_t pwrite(int <[fd]>, const void *<[buf]>,
14 size_t <[n]>, off_t <[off]>);
15 ssize_t _pwrite_r(struct _reent *<[rptr]>, int <[fd]>,
16 const void *<[buf]>, size_t <[n]>, off_t <[off]>);
19 The <<pwrite>> function is similar to <<write>>. One difference is that
20 <<pwrite>> has an additional parameter <[off]> which is the offset to
21 position in the file before writing. The function also differs in that
22 the file position is unchanged by the function (i.e. the file position
23 is the same before and after a call to <<pwrite>>).
25 The <<_pwrite_r>> function is the same as <<pwrite>>, only a reentrant
26 struct pointer <[rptr]> is provided to preserve reentrancy.
29 <<pwrite>> returns the number of bytes written or <<-1>> if failure occurred.
32 <<pwrite>> is non-ANSI and is specified by the Single Unix Specification.
34 Supporting OS subroutine required: <<write>>, <<lseek>>.
42 _pwrite_r (struct _reent
*rptr
,
49 _READ_WRITE_RETURN_TYPE num_written
;
51 if ((cur_pos
= _lseek_r (rptr
, fd
, 0, SEEK_CUR
)) == (off_t
)-1)
54 if (_lseek_r (rptr
, fd
, off
, SEEK_SET
) == (off_t
)-1)
57 num_written
= _write_r (rptr
, fd
, buf
, n
);
59 if (_lseek_r (rptr
, fd
, cur_pos
, SEEK_SET
) == (off_t
)-1)
62 return (ssize_t
)num_written
;
73 return _pwrite_r (_REENT
, fd
, buf
, n
, off
);
76 #endif /* !_REENT_ONLY */
77 #endif /* !_NO_PWRITE */