1 | /* |
---|
2 | FUNCTION |
---|
3 | <<pread64>>---read a large file from specified position |
---|
4 | |
---|
5 | INDEX |
---|
6 | pread64 |
---|
7 | |
---|
8 | SYNOPSIS |
---|
9 | #include <unistd.h> |
---|
10 | ssize_t pread64(int <[fd]>, void *<[buf]>, size_t <[n]>, loff_t <[off]>); |
---|
11 | |
---|
12 | DESCRIPTION |
---|
13 | The <<pread64>> function is similar to <<pread>>. The only difference is |
---|
14 | that it operates on large files and so takes a 64-bit offset. Like <<pread>>>, |
---|
15 | the file position is unchanged by the function (i.e. the file position |
---|
16 | is the same before and after a call to <<pread>>). |
---|
17 | |
---|
18 | RETURNS |
---|
19 | <<pread64>> returns the number of bytes read or <<-1>> if failure occurred. |
---|
20 | |
---|
21 | PORTABILITY |
---|
22 | <<pread64>> is an EL/IX extension. |
---|
23 | |
---|
24 | Supporting OS subroutine required: <<read>>, <<lseek64>>. |
---|
25 | */ |
---|
26 | |
---|
27 | #include <_ansi.h> |
---|
28 | #include <unistd.h> |
---|
29 | #include <reent.h> |
---|
30 | #include <machine/weakalias.h> |
---|
31 | |
---|
32 | ssize_t |
---|
33 | __libc_pread64 (int fd, |
---|
34 | void *buf, |
---|
35 | size_t n, |
---|
36 | loff_t off) |
---|
37 | { |
---|
38 | loff_t cur_pos; |
---|
39 | _READ_WRITE_RETURN_TYPE num_read; |
---|
40 | |
---|
41 | if ((cur_pos = lseek64 (fd, 0, SEEK_CUR)) == (loff_t)-1) |
---|
42 | return -1; |
---|
43 | |
---|
44 | if (lseek64 (fd, off, SEEK_SET) == (loff_t)-1) |
---|
45 | return -1; |
---|
46 | |
---|
47 | num_read = read (fd, buf, n); |
---|
48 | |
---|
49 | if (lseek64 (fd, cur_pos, SEEK_SET) == (loff_t)-1) |
---|
50 | return -1; |
---|
51 | |
---|
52 | return (ssize_t)num_read; |
---|
53 | } |
---|
54 | weak_alias(__libc_pread64,pread64); |
---|
55 | weak_alias(__libc_pread64,__pread64); |
---|
56 | |
---|