OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [newlib-1.17.0/] [newlib/] [libc/] [unix/] [pread.c] - Blame information for rev 862

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#ifndef _NO_PREAD
2
/*
3
FUNCTION
4
<<pread>>---read a file from specified position
5
 
6
INDEX
7
        pread
8
INDEX
9
        _pread_r
10
 
11
ANSI_SYNOPSIS
12
        #include <unistd.h>
13
        ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
14
        ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
15
                         void *<[buf]>, size_t <[n]>, off_t <[off]>);
16
 
17
TRAD_SYNOPSIS
18
        #include <unistd.h>
19
        ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>)
20
        int <[fd]>;
21
        void *<[buf]>;
22
        size_t <[n]>;
23
        off_t <[off]>;
24
 
25
        ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
26
        struct _reent *<[rptr]>;
27
        int <[fd]>;
28
        void *<[buf]>;
29
        size_t <[n]>;
30
        off_t <[off]>;
31
 
32
DESCRIPTION
33
The <<pread>> function is similar to <<read>>.  One difference is that
34
<<pread>> has an additional parameter <[off]> which is the offset to
35
position in the file before reading.  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 <<pread>>).
38
 
39
The <<_pread_r>> function is the same as <<pread>>, only a reentrant
40
struct pointer <[rptr]> is provided to preserve reentrancy.
41
 
42
RETURNS
43
<<pread>> returns the number of bytes read or <<-1>> if failure occurred.
44
 
45
PORTABILITY
46
<<pread>> is non-ANSI and is specified by the Single Unix Specification.
47
 
48
Supporting OS subroutine required: <<read>>, <<lseek>>.
49
*/
50
 
51
#include <_ansi.h>
52
#include <unistd.h>
53
#include <reent.h>
54
 
55
ssize_t
56
_DEFUN (_pread_r, (rptr, fd, buf, n, off),
57
     struct _reent *rptr _AND
58
     int fd _AND
59
     _PTR buf _AND
60
     size_t n _AND
61
     off_t off)
62
{
63
  off_t cur_pos;
64
  _READ_WRITE_RETURN_TYPE num_read;
65
 
66
  if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)
67
    return -1;
68
 
69
  if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)
70
    return -1;
71
 
72
  num_read = _read_r (rptr, fd, buf, n);
73
 
74
  if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)
75
    return -1;
76
 
77
  return (ssize_t)num_read;
78
}
79
 
80
#ifndef _REENT_ONLY
81
 
82
ssize_t
83
_DEFUN (pread, (fd, buf, n, off),
84
     int fd _AND
85
     _PTR buf _AND
86
     size_t n _AND
87
     off_t off)
88
{
89
  return _pread_r (_REENT, fd, buf, n, off);
90
}
91
 
92
#endif /* !_REENT_ONLY  */
93
#endif /* !_NO_PREAD  */

powered by: WebSVN 2.1.0

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