OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc1/] [newlib/] [libc/] [unix/] [pread.c] - Diff between revs 207 and 345

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 345
#ifndef _NO_PREAD
#ifndef _NO_PREAD
/*
/*
FUNCTION
FUNCTION
<<pread>>---read a file from specified position
<<pread>>---read a file from specified position
 
 
INDEX
INDEX
        pread
        pread
INDEX
INDEX
        _pread_r
        _pread_r
 
 
ANSI_SYNOPSIS
ANSI_SYNOPSIS
        #include <unistd.h>
        #include <unistd.h>
        ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
        ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
        ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
        ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
                         void *<[buf]>, size_t <[n]>, off_t <[off]>);
                         void *<[buf]>, size_t <[n]>, off_t <[off]>);
 
 
TRAD_SYNOPSIS
TRAD_SYNOPSIS
        #include <unistd.h>
        #include <unistd.h>
        ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>)
        ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>)
        int <[fd]>;
        int <[fd]>;
        void *<[buf]>;
        void *<[buf]>;
        size_t <[n]>;
        size_t <[n]>;
        off_t <[off]>;
        off_t <[off]>;
 
 
        ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
        ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
        struct _reent *<[rptr]>;
        struct _reent *<[rptr]>;
        int <[fd]>;
        int <[fd]>;
        void *<[buf]>;
        void *<[buf]>;
        size_t <[n]>;
        size_t <[n]>;
        off_t <[off]>;
        off_t <[off]>;
 
 
DESCRIPTION
DESCRIPTION
The <<pread>> function is similar to <<read>>.  One difference is that
The <<pread>> function is similar to <<read>>.  One difference is that
<<pread>> has an additional parameter <[off]> which is the offset to
<<pread>> has an additional parameter <[off]> which is the offset to
position in the file before reading.  The function also differs in that
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
the file position is unchanged by the function (i.e. the file position
is the same before and after a call to <<pread>>).
is the same before and after a call to <<pread>>).
 
 
The <<_pread_r>> function is the same as <<pread>>, only a reentrant
The <<_pread_r>> function is the same as <<pread>>, only a reentrant
struct pointer <[rptr]> is provided to preserve reentrancy.
struct pointer <[rptr]> is provided to preserve reentrancy.
 
 
RETURNS
RETURNS
<<pread>> returns the number of bytes read or <<-1>> if failure occurred.
<<pread>> returns the number of bytes read or <<-1>> if failure occurred.
 
 
PORTABILITY
PORTABILITY
<<pread>> is non-ANSI and is specified by the Single Unix Specification.
<<pread>> is non-ANSI and is specified by the Single Unix Specification.
 
 
Supporting OS subroutine required: <<read>>, <<lseek>>.
Supporting OS subroutine required: <<read>>, <<lseek>>.
*/
*/
 
 
#include <_ansi.h>
#include <_ansi.h>
#include <unistd.h>
#include <unistd.h>
#include <reent.h>
#include <reent.h>
 
 
ssize_t
ssize_t
_DEFUN (_pread_r, (rptr, fd, buf, n, off),
_DEFUN (_pread_r, (rptr, fd, buf, n, off),
     struct _reent *rptr _AND
     struct _reent *rptr _AND
     int fd _AND
     int fd _AND
     _PTR buf _AND
     _PTR buf _AND
     size_t n _AND
     size_t n _AND
     off_t off)
     off_t off)
{
{
  off_t cur_pos;
  off_t cur_pos;
  _READ_WRITE_RETURN_TYPE num_read;
  _READ_WRITE_RETURN_TYPE num_read;
 
 
  if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)
  if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)
    return -1;
    return -1;
 
 
  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)
  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)
    return -1;
    return -1;
 
 
  num_read = _read_r (rptr, fd, buf, n);
  num_read = _read_r (rptr, fd, buf, n);
 
 
  if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)
  if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)
    return -1;
    return -1;
 
 
  return (ssize_t)num_read;
  return (ssize_t)num_read;
}
}
 
 
#ifndef _REENT_ONLY
#ifndef _REENT_ONLY
 
 
ssize_t
ssize_t
_DEFUN (pread, (fd, buf, n, off),
_DEFUN (pread, (fd, buf, n, off),
     int fd _AND
     int fd _AND
     _PTR buf _AND
     _PTR buf _AND
     size_t n _AND
     size_t n _AND
     off_t off)
     off_t off)
{
{
  return _pread_r (_REENT, fd, buf, n, off);
  return _pread_r (_REENT, fd, buf, n, off);
}
}
 
 
#endif /* !_REENT_ONLY  */
#endif /* !_REENT_ONLY  */
#endif /* !_NO_PREAD  */
#endif /* !_NO_PREAD  */
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.