Back to index

glibc  2.9
posix_madvise.c
Go to the documentation of this file.
00001 /* Copyright (C) 2007 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003 
00004    The GNU C Library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Lesser General Public
00006    License as published by the Free Software Foundation; either
00007    version 2.1 of the License, or (at your option) any later version.
00008 
00009    The GNU C Library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Lesser General Public License for more details.
00013 
00014    You should have received a copy of the GNU Lesser General Public
00015    License along with the GNU C Library; if not, write to the Free
00016    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00017    02111-1307 USA.  */
00018 
00019 #include <sysdep.h>
00020 #include <sys/mman.h>
00021 
00022 
00023 int
00024 posix_madvise (void *addr, size_t len, int advice)
00025 {
00026   /* We have one problem: the kernel's MADV_DONTNEED does not
00027      correspond to POSIX's POSIX_MADV_DONTNEED.  The former simply
00028      discards changes made to the memory without writing it back to
00029      disk, if this would be necessary.  The POSIX behavior does not
00030      allow this.  There is no functionality mapping the POSIX behavior
00031      so far so we ignore that advice for now.  */
00032   if (advice == POSIX_MADV_DONTNEED)
00033     return 0;
00034 
00035   INTERNAL_SYSCALL_DECL (err);
00036   int result = INTERNAL_SYSCALL (madvise, err, 3, addr, len, advice);
00037   return INTERNAL_SYSCALL_ERRNO (result, err);
00038 }