Back to index

glibc  2.9
posix_fallocate.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 <fcntl.h>
00020 #include <kernel-features.h>
00021 #include <sysdep.h>
00022 
00023 #define posix_fallocate static internal_fallocate
00024 #include <sysdeps/posix/posix_fallocate.c>
00025 #undef posix_fallocate
00026 
00027 #if !defined __ASSUME_FALLOCATE && defined __NR_fallocate
00028 int __have_fallocate attribute_hidden;
00029 #endif
00030 
00031 extern int __call_fallocate (int fd, int mode, __off64_t offset, __off64_t len)
00032      attribute_hidden;
00033 
00034 /* Reserve storage for the data of the file associated with FD.  */
00035 int
00036 posix_fallocate (int fd, __off_t offset, __off_t len)
00037 {
00038 #ifdef __NR_fallocate
00039 # ifndef __ASSUME_FALLOCATE
00040   if (__builtin_expect (__have_fallocate >= 0, 1))
00041 # endif
00042     {
00043       int res = __call_fallocate (fd, 0, offset, len);
00044       if (! res)
00045        return 0;
00046 
00047 # ifndef __ASSUME_FALLOCATE
00048       if (__builtin_expect (res == ENOSYS, 0))
00049        __have_fallocate = -1;
00050       else
00051 # endif
00052        if (res != EOPNOTSUPP)
00053          return res;
00054     }
00055 #endif
00056 
00057   return internal_fallocate (fd, offset, len);
00058 }