source: trunk/libs/newlib/src/newlib/libc/sys/linux/pread64.c

Last change on this file was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 1.2 KB
Line 
1/*
2FUNCTION
3<<pread64>>---read a large file from specified position
4
5INDEX
6        pread64
7
8SYNOPSIS
9        #include <unistd.h>
10        ssize_t pread64(int <[fd]>, void *<[buf]>, size_t <[n]>, loff_t <[off]>);
11
12DESCRIPTION
13The <<pread64>> function is similar to <<pread>>.  The only difference is
14that it operates on large files and so takes a 64-bit offset.  Like <<pread>>>,
15the file position is unchanged by the function (i.e. the file position
16is the same before and after a call to <<pread>>).
17
18RETURNS
19<<pread64>> returns the number of bytes read or <<-1>> if failure occurred.
20
21PORTABILITY
22<<pread64>> is an EL/IX extension.
23
24Supporting 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
32ssize_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}
54weak_alias(__libc_pread64,pread64);
55weak_alias(__libc_pread64,__pread64);
56
Note: See TracBrowser for help on using the repository browser.