Back to index

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