OSDN Git Service

fa9ff219fc3e2bdd1c6f8192aa6dea9ac5ead1ee
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / posix_fadvise64.c
1 /* vi: set sw=4 ts=4: */
2 /*
3  * posix_fadvise64() for uClibc
4  * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
5  *
6  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
7  *
8  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
9  */
10
11 #include <features.h>
12 #include <unistd.h>
13 #include <errno.h>
14 #include <endian.h>
15 #include <stdint.h>
16 #include <sys/types.h>
17 #include <sys/syscall.h>
18 #include <fcntl.h>
19
20 #ifdef __UCLIBC_HAS_LFS__
21 #ifdef __NR_fadvise64_64
22
23 /* 64 bit implementation is cake ... or more like pie ... */
24 #if __WORDSIZE == 64
25
26 #define __NR_posix_fadvise64 __NR_fadvise64_64
27
28 int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
29 {
30   if (len != (off_t) len)
31     return EOVERFLOW;
32   INTERNAL_SYSCALL_DECL (err);
33     int ret = INTERNAL_SYSCALL (posix_fadvise64, err, 5, fd,
34                                __LONG_LONG_PAIR ((long) (offset >> 32),
35                                                  (long) offset),
36                                (off_t) len, advice);
37   if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
38     return 0;
39   return INTERNAL_SYSCALL_ERRNO (ret, err);
40 }
41
42 /* 32 bit implementation is kind of a pita */
43 #elif __WORDSIZE == 32
44
45 int posix_fadvise64(int fd, __off64_t offset, __off64_t len, int advice)
46 {
47         INTERNAL_SYSCALL_DECL (err);
48         int ret = INTERNAL_SYSCALL (fadvise64_64, err, 6, fd,
49                                                                 __LONG_LONG_PAIR(offset >> 32, offset &  0xffffffff),
50                                                                 __LONG_LONG_PAIR(len >> 32, len & 0xffffffff),
51                                                                 advice);
52         if (!INTERNAL_SYSCALL_ERROR_P (ret, err))
53                 return 0;
54         return INTERNAL_SYSCALL_ERRNO (ret, err);
55 }
56
57 #else
58 #error your machine is neither 32 bit or 64 bit ... it must be magical
59 #endif
60
61 #endif /* __NR_fadvise64_64 */
62 #endif /* __UCLIBC_HAS_LFS__ */