diff options
author | Jeff Johnston <jjohnstn@redhat.com> | 2002-04-29 19:31:23 +0000 |
---|---|---|
committer | Jeff Johnston <jjohnstn@redhat.com> | 2002-04-29 19:31:23 +0000 |
commit | 29798f0d57549a89d7ec6c8717fda26347e6bbf7 (patch) | |
tree | 76ffe5ce7c145afb2449d0b56780d8cd03e98ae1 /newlib/libc/unix/pwrite.c | |
parent | eccebec08df9f2b74e2bf457f4063c86662727e0 (diff) | |
download | newlib-29798f0d57549a89d7ec6c8717fda26347e6bbf7.zip newlib-29798f0d57549a89d7ec6c8717fda26347e6bbf7.tar.gz newlib-29798f0d57549a89d7ec6c8717fda26347e6bbf7.tar.bz2 |
2002-04-29 Jeff Johnston <jjohnstn@redhat.com>
* libc/include/sys/unistd.h (pread, pwrite): Added prototypes.
* libc/unix/Makefile.am: Add pread.c and pwrite.c.
* libc/sys/linux/Makefile.am: Add pread64.c and pwrite64.c.
* libc/sys/linux/Makefile.in: Regenerated.
* libc/unix/Makefile.in: Ditto.
* libc/sys/linux/pread64.c: New file.
* libc/sys/linux/pwrite64.c: Ditto.
* libc/unix/pread.c: Ditto.
* libc/unix/pwrite.c: Ditto.
Diffstat (limited to 'newlib/libc/unix/pwrite.c')
-rw-r--r-- | newlib/libc/unix/pwrite.c | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/newlib/libc/unix/pwrite.c b/newlib/libc/unix/pwrite.c new file mode 100644 index 0000000..2d672bf --- /dev/null +++ b/newlib/libc/unix/pwrite.c @@ -0,0 +1,92 @@ +/* +FUNCTION +<<pwrite>>---write a file from specified position + +INDEX + pwrite +INDEX + _pwrite_r + +ANSI_SYNOPSIS + #include <unistd.h> + ssize_t pwrite(int <[fd]>, const void *<[buf]>, + size_t <[n]>, off_t <[off]>); + ssize_t _pwrite_r(struct _reent *<[rptr]>, int <[fd]>, + const void *<[buf]>, size_t <[n]>, off_t <[off]>); + +TRAD_SYNOPSIS + #include <unistd.h> + ssize_t pwrite(<[fd]>, <[buf]>, <[n]>, <[off]>) + int <[fd]>; + const void *<[buf]>; + size_t <[n]>; + off_t <[off]>; + + ssize_t _pwrite_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>) + struct _reent *<[rptr]>; + int <[fd]>; + const void *<[buf]>; + size_t <[n]>; + off_t <[off]>; + +DESCRIPTION +The <<pwrite>> function is similar to <<write>>. One difference is that +<<pwrite>> has an additional parameter <[off]> which is the offset to +position in the file before writing. The function also differs in that +the file position is unchanged by the function (i.e. the file position +is the same before and after a call to <<pwrite>>). + +The <<_pwrite_r>> function is the same as <<pwrite>>, only a reentrant +struct pointer <[rptr]> is provided to preserve reentrancy. + +RETURNS +<<pwrite>> returns the number of bytes written or <<-1>> if failure occurred. + +PORTABILITY +<<pwrite>> is non-ANSI and is specified by the Single Unix Specification. + +Supporting OS subroutine required: <<write>>, <<lseek>>. +*/ + +#include <_ansi.h> +#include <unistd.h> +#include <reent.h> + +ssize_t +_DEFUN (pwrite_r, (rptr, fd, buf, n, off), + struct _reent *rptr _AND + int fd _AND + _CONST _PTR buf _AND + size_t n _AND + off_t off) +{ + off_t cur_pos; + _READ_WRITE_RETURN_TYPE num_written; + + if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1) + return -1; + + if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1) + return -1; + + num_written = _write_r (rptr, fd, buf, n); + + if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return (ssize_t)num_written; +} + +#ifndef _REENT_ONLY + +ssize_t +_DEFUN (pwrite, (fd, buf, n, off), + int fd _AND + _CONST _PTR buf _AND + size_t n _AND + off_t off) +{ + return _pwrite_r (_REENT, fd, buf, n, off); +} + +#endif |