fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / newlib / libc / unix / pread.c
blob72087542e4678db7569467e9bf8ac067600e2b98
1 /*
2 FUNCTION
3 <<pread>>---read a file from specified position
5 INDEX
6 pread
7 INDEX
8 _pread_r
10 ANSI_SYNOPSIS
11 #include <unistd.h>
12 ssize_t pread(int <[fd]>, void *<[buf]>, size_t <[n]>, off_t <[off]>);
13 ssize_t _pread_r(struct _reent *<[rptr]>, int <[fd]>,
14 void *<[buf]>, size_t <[n]>, off_t <[off]>);
16 TRAD_SYNOPSIS
17 #include <unistd.h>
18 ssize_t pread(<[fd]>, <[buf]>, <[n]>, <[off]>)
19 int <[fd]>;
20 void *<[buf]>;
21 size_t <[n]>;
22 off_t <[off]>;
24 ssize_t _pread_r(<[rptr]>, <[fd]>, <[buf]>, <[n]>, <[off]>)
25 struct _reent *<[rptr]>;
26 int <[fd]>;
27 void *<[buf]>;
28 size_t <[n]>;
29 off_t <[off]>;
31 DESCRIPTION
32 The <<pread>> function is similar to <<read>>. One difference is that
33 <<pread>> has an additional parameter <[off]> which is the offset to
34 position in the file before reading. The function also differs in that
35 the file position is unchanged by the function (i.e. the file position
36 is the same before and after a call to <<pread>>).
38 The <<_pread_r>> function is the same as <<pread>>, only a reentrant
39 struct pointer <[rptr]> is provided to preserve reentrancy.
41 RETURNS
42 <<pread>> returns the number of bytes read or <<-1>> if failure occurred.
44 PORTABILITY
45 <<pread>> is non-ANSI and is specified by the Single Unix Specification.
47 Supporting OS subroutine required: <<read>>, <<lseek>>.
50 #include <_ansi.h>
51 #include <unistd.h>
52 #include <reent.h>
54 ssize_t
55 _DEFUN (_pread_r, (rptr, fd, buf, n, off),
56 struct _reent *rptr _AND
57 int fd _AND
58 _PTR buf _AND
59 size_t n _AND
60 off_t off)
62 off_t cur_pos;
63 _READ_WRITE_RETURN_TYPE num_read;
65 if ((cur_pos = _lseek_r (rptr, fd, 0, SEEK_CUR)) == (off_t)-1)
66 return -1;
68 if (_lseek_r (rptr, fd, off, SEEK_SET) == (off_t)-1)
69 return -1;
71 num_read = _read_r (rptr, fd, buf, n);
73 if (_lseek_r (rptr, fd, cur_pos, SEEK_SET) == (off_t)-1)
74 return -1;
76 return (ssize_t)num_read;
79 #ifndef _REENT_ONLY
81 ssize_t
82 _DEFUN (pread, (fd, buf, n, off),
83 int fd _AND
84 _PTR buf _AND
85 size_t n _AND
86 off_t off)
88 return _pread_r (_REENT, fd, buf, n, off);
91 #endif