From 29798f0d57549a89d7ec6c8717fda26347e6bbf7 Mon Sep 17 00:00:00 2001 From: Jeff Johnston Date: Mon, 29 Apr 2002 19:31:23 +0000 Subject: 2002-04-29 Jeff Johnston * 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. --- newlib/libc/unix/Makefile.am | 3 +- newlib/libc/unix/Makefile.in | 13 ++++--- newlib/libc/unix/pread.c | 91 +++++++++++++++++++++++++++++++++++++++++++ newlib/libc/unix/pwrite.c | 92 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 193 insertions(+), 6 deletions(-) create mode 100644 newlib/libc/unix/pread.c create mode 100644 newlib/libc/unix/pwrite.c (limited to 'newlib/libc/unix') diff --git a/newlib/libc/unix/Makefile.am b/newlib/libc/unix/Makefile.am index 5159c0ed0..83fd26254 100644 --- a/newlib/libc/unix/Makefile.am +++ b/newlib/libc/unix/Makefile.am @@ -5,7 +5,8 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) LIB_SOURCES = \ - getpass.c sigset.c getpwent.c ttyname.c getut.c getlogin.c getcwd.c + getcwd.c getlogin.c getpass.c getpwent.c getut.c \ + pread.c pwrite.c sigset.c ttyname.c libunix_la_LDFLAGS = -Xcompiler -nostdlib diff --git a/newlib/libc/unix/Makefile.in b/newlib/libc/unix/Makefile.in index 72ddaf49b..d1de62e59 100644 --- a/newlib/libc/unix/Makefile.in +++ b/newlib/libc/unix/Makefile.in @@ -100,7 +100,8 @@ AUTOMAKE_OPTIONS = cygnus INCLUDES = $(NEWLIB_CFLAGS) $(CROSS_CFLAGS) $(TARGET_CFLAGS) LIB_SOURCES = \ - getpass.c sigset.c getpwent.c ttyname.c getut.c getlogin.c getcwd.c + getcwd.c getlogin.c getpass.c getpwent.c getut.c \ + pread.c pwrite.c sigset.c ttyname.c libunix_la_LDFLAGS = -Xcompiler -nostdlib @@ -130,13 +131,15 @@ DEFS = @DEFS@ -I. -I$(srcdir) CPPFLAGS = @CPPFLAGS@ LIBS = @LIBS@ lib_a_LIBADD = -@USE_LIBTOOL_FALSE@lib_a_OBJECTS = getpass.o sigset.o getpwent.o \ -@USE_LIBTOOL_FALSE@ttyname.o getut.o getlogin.o getcwd.o +@USE_LIBTOOL_FALSE@lib_a_OBJECTS = getcwd.o getlogin.o getpass.o \ +@USE_LIBTOOL_FALSE@getpwent.o getut.o pread.o pwrite.o sigset.o \ +@USE_LIBTOOL_FALSE@ttyname.o LTLIBRARIES = $(noinst_LTLIBRARIES) libunix_la_LIBADD = -@USE_LIBTOOL_TRUE@libunix_la_OBJECTS = getpass.lo sigset.lo getpwent.lo \ -@USE_LIBTOOL_TRUE@ttyname.lo getut.lo getlogin.lo getcwd.lo +@USE_LIBTOOL_TRUE@libunix_la_OBJECTS = getcwd.lo getlogin.lo getpass.lo \ +@USE_LIBTOOL_TRUE@getpwent.lo getut.lo pread.lo pwrite.lo sigset.lo \ +@USE_LIBTOOL_TRUE@ttyname.lo CFLAGS = @CFLAGS@ COMPILE = $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) LTCOMPILE = $(LIBTOOL) --mode=compile $(CC) $(DEFS) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) diff --git a/newlib/libc/unix/pread.c b/newlib/libc/unix/pread.c new file mode 100644 index 000000000..68ed68eb1 --- /dev/null +++ b/newlib/libc/unix/pread.c @@ -0,0 +1,91 @@ +/* +FUNCTION +<>---read a file from specified position + +INDEX + pread +INDEX + _pread_r + +ANSI_SYNOPSIS + #include + ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>); + ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>, + void *<[buf]>, size_t <[n]>, off_t <[off]>); + +TRAD_SYNOPSIS + #include + ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>) + int <[fd]>; + void *<[buf]>; + size_t <[n]>; + off_t <[off]>; + + ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>) + struct _reent *<[rptr]>; + int <[fd]>; + void *<[buf]>; + size_t <[n]>; + off_t <[off]>; + +DESCRIPTION +The <> function is similar to <>. One difference is that +<> has an additional parameter <[off]> which is the offset to +position in the file before reading. 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 <>). + +The <<_pread_r>> function is the same as <>, only a reentrant +struct pointer <[rptr]> is provided to preserve reentrancy. + +RETURNS +<> returns the number of bytes read or <<-1>> if failure occurred. + +PORTABILITY +<> is non-ANSI and is specified by the Single Unix Specification. + +Supporting OS subroutine required: <>, <>. +*/ + +#include <_ansi.h> +#include +#include + +ssize_t +_DEFUN (pread_r, (rptr, fd, buf, n, off), + struct _reent *rptr _AND + int fd _AND + _PTR buf _AND + size_t n _AND + off_t off) +{ + off_t cur_pos; + _READ_WRITE_RETURN_TYPE num_read; + + 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_read = _read_r (rptr, fd, buf, n); + + if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1) + return -1; + + return (ssize_t)num_read; +} + +#ifndef _REENT_ONLY + +ssize_t +_DEFUN (pread, (fd, buf, n, off), + int fd _AND + _PTR buf _AND + size_t n _AND + off_t off) +{ + return _pread_r (_REENT, fd, buf, n, off); +} + +#endif diff --git a/newlib/libc/unix/pwrite.c b/newlib/libc/unix/pwrite.c new file mode 100644 index 000000000..2d672bfbe --- /dev/null +++ b/newlib/libc/unix/pwrite.c @@ -0,0 +1,92 @@ +/* +FUNCTION +<>---write a file from specified position + +INDEX + pwrite +INDEX + _pwrite_r + +ANSI_SYNOPSIS + #include + 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 + 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 <> function is similar to <>. One difference is that +<> 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 <>). + +The <<_pwrite_r>> function is the same as <>, only a reentrant +struct pointer <[rptr]> is provided to preserve reentrancy. + +RETURNS +<> returns the number of bytes written or <<-1>> if failure occurred. + +PORTABILITY +<> is non-ANSI and is specified by the Single Unix Specification. + +Supporting OS subroutine required: <>, <>. +*/ + +#include <_ansi.h> +#include +#include + +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 -- cgit v1.2.3