uclibc-ng: bump version from 1.0.6 to 1.0.8
[openwrt/openwrt.git] / toolchain / uClibc / patches-0.9.33.2 / 021-add-posix_madvise.c.patch
1 From: "Peter S. Mazinger" <ps.m@gmx.net>
2 Date: Tue, 26 Apr 2011 23:03:44 +0200
3 Subject: [PATCH] add posix_madvise.c
4
5 Signed-off-by: Peter S. Mazinger <ps.m@gmx.net>
6 Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
7 ---
8 create mode 100644 libc/sysdeps/linux/common/posix_madvise.c
9
10 --- a/libc/sysdeps/linux/common/Makefile.in
11 +++ b/libc/sysdeps/linux/common/Makefile.in
12 @@ -81,7 +81,7 @@ CSRC-$(UCLIBC_HAS_REALTIME) += clock_get
13 sched_get_priority_max.c sched_get_priority_min.c sched_getscheduler.c \
14 sched_rr_get_interval.c sched_setparam.c sched_setscheduler.c sigqueue.c
15 # clock_getcpuclockid|clock_nanosleep|mq_timedreceive|mq_timedsend|posix_fadvise|posix_fallocate|posix_madvise|posix_memalign|posix_mem_offset|posix_spawnattr_destroy|posix_spawnattr_init|posix_spawnattr_getflags|posix_spawnattr_setflags|posix_spawnattr_getpgroup|posix_spawnattr_setpgroup|posix_spawnattr_getschedparam|posix_spawnattr_setschedparam|posix_spawnattr_getschedpolicy|posix_spawnattr_setschedpolicy|posix_spawnattr_getsigdefault|posix_spawnattr_setsigdefault|posix_spawnattr_getsigmask|posix_spawnattr_setsigmask|posix_spawnattr_init|posix_spawnattr_setflags|posix_spawnattr_setpgroup|posix_spawnattr_setschedparam|posix_spawnattr_setschedpolicy|posix_spawnattr_setsigdefault|posix_spawnattr_setsigmask|posix_spawn_file_actions_addclose|posix_spawn_file_actions_addopen|posix_spawn_file_actions_adddup2|posix_spawn_file_actions_addopen|posix_spawn_file_actions_destroy|posix_spawn_file_actions_init|posix_spawn_file_actions_init|posix_spawn|posix_spawnp|posix_spawnp|posix_typed_mem_get_info|pthread_mutex_timedlock|sem_timedwait
16 -CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c
17 +CSRC-$(UCLIBC_HAS_ADVANCED_REALTIME) += posix_fadvise64.c posix_fadvise.c posix_madvise.c
18 CSRC-$(UCLIBC_SUSV4_LEGACY) += utime.c
19 CSRC-$(UCLIBC_HAS_EPOLL) += epoll.c
20 CSRC-$(UCLIBC_HAS_XATTR) += xattr.c
21 --- /dev/null
22 +++ b/libc/sysdeps/linux/common/posix_madvise.c
23 @@ -0,0 +1,25 @@
24 +/* vi: set sw=4 ts=4: */
25 +/* Licensed under the LGPL v2.1, see the file LICENSE in this tarball. */
26 +
27 +#include <sys/mman.h>
28 +#include <sys/syscall.h>
29 +
30 +#if defined __NR_madvise && defined __USE_XOPEN2K && defined __UCLIBC_HAS_ADVANCED_REALTIME__
31 +int posix_madvise(void *addr, size_t len, int advice)
32 +{
33 + int result;
34 + /* We have one problem: the kernel's MADV_DONTNEED does not
35 + * correspond to POSIX's POSIX_MADV_DONTNEED. The former simply
36 + * discards changes made to the memory without writing it back to
37 + * disk, if this would be necessary. The POSIX behaviour does not
38 + * allow this. There is no functionality mapping for the POSIX
39 + * behaviour so far so we ignore that advice for now. */
40 + if (advice == POSIX_MADV_DONTNEED)
41 + return 0;
42 +
43 + /* this part might use madvise function */
44 + INTERNAL_SYSCALL_DECL (err);
45 + result = INTERNAL_SYSCALL (madvise, err, 3, addr, len, advice);
46 + return INTERNAL_SYSCALL_ERRNO (result, err);
47 +}
48 +#endif