]> Git Repo - uclibc-ng.git/blob - libc/sysdeps/linux/common/posix_fadvise.c
csky: port to uclibc-ng
[uclibc-ng.git] / libc / sysdeps / linux / common / posix_fadvise.c
1 /*
2  * posix_fadvise() for uClibc
3  * http://www.opengroup.org/onlinepubs/009695399/functions/posix_fadvise.html
4  *
5  * Copyright (C) 2000-2006 Erik Andersen <[email protected]>
6  *
7  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
8  */
9
10 #include <sys/syscall.h>
11
12 #ifdef __NR_arm_fadvise64_64
13 /* We handle the 64bit alignment issue which is why the arm guys renamed their
14  * syscall in the first place.  So rename it back.
15  */
16 # define __NR_fadvise64_64 __NR_arm_fadvise64_64
17 #endif
18
19 #if defined(__NR_fadvise64) || defined(__NR_fadvise64_64)
20 # include <fcntl.h>
21 # include <endian.h>
22 # include <bits/wordsize.h>
23
24 # if defined(__NR_fadvise64_64)
25 #include <_lfs_64.h>
26
27 int posix_fadvise64(int fd, off64_t offset, off64_t len, int advice);
28 int posix_fadvise(int fd, off_t offset, off_t len, int advice)
29 {
30         return posix_fadvise64(fd, offset, len, advice);
31 }
32 #else
33
34 int posix_fadvise(int fd, off_t offset, off_t len, int advice)
35 {
36         int ret;
37         INTERNAL_SYSCALL_DECL(err);
38
39 # ifdef __NR_fadvise64_64
40 #  if __WORDSIZE == 64
41         ret = INTERNAL_SYSCALL(fadvise64_64, err, 4, fd, offset, len, advice);
42 #  else
43 #   if defined (__arm__) || defined (__nds32__) || defined(__csky__) || \
44       (defined(__UCLIBC_SYSCALL_ALIGN_64BIT__) && (defined(__powerpc__) || defined(__xtensa__)))
45         /* arch with 64-bit data in even reg alignment #1: [powerpc/xtensa]
46          * custom syscall handler (rearranges @advice to avoid register hole punch) */
47         ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd, advice,
48                         OFF_HI_LO (offset), OFF_HI_LO (len));
49 #   elif defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
50         /* arch with 64-bit data in even reg alignment #2: [arcv2/others-in-future]
51          * stock syscall handler in kernel (reg hole punched) */
52         ret = INTERNAL_SYSCALL(fadvise64_64, err, 7, fd, 0,
53                         OFF_HI_LO (offset), OFF_HI_LO (len), advice);
54 #   else
55         ret = INTERNAL_SYSCALL(fadvise64_64, err, 6, fd,
56                         OFF_HI_LO (offset), OFF_HI_LO (len), advice);
57 #   endif
58 #  endif
59 # else  /* __NR_fadvise64 */
60 #  if __WORDSIZE == 64
61         ret = INTERNAL_SYSCALL(fadvise64, err, 4, fd, offset, len, advice);
62 #  else
63 #   if defined(__UCLIBC_SYSCALL_ALIGN_64BIT__)
64         ret = INTERNAL_SYSCALL(fadvise64, err, 6, fd, /*unused*/0,
65 #   else
66         ret = INTERNAL_SYSCALL(fadvise64, err, 5, fd,
67 #   endif
68                         OFF_HI_LO (offset), len, advice);
69 #  endif
70 #  endif
71         if (INTERNAL_SYSCALL_ERROR_P (ret, err))
72                 return INTERNAL_SYSCALL_ERRNO (ret, err);
73         return 0;
74 }
75 # if !defined __NR_fadvise64_64 || __WORDSIZE == 64
76 strong_alias(posix_fadvise,posix_fadvise64)
77 # endif
78 #endif
79 #endif
This page took 0.030189 seconds and 4 git commands to generate.