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 
00032 /* Reserve storage for the data of the file associated with FD.  */
00033 int
00034 posix_fallocate (int fd, __off_t offset, __off_t len)
00035 {
00036 #ifdef __NR_fallocate
00037 # ifndef __ASSUME_FALLOCATE
00038   if (__builtin_expect (__have_fallocate >= 0, 1))
00039 # endif
00040     {
00041       INTERNAL_SYSCALL_DECL (err);
00042       int res = INTERNAL_SYSCALL (fallocate, err, 6, fd, 0,
00043                               __LONG_LONG_PAIR (offset >> 31, offset),
00044                               __LONG_LONG_PAIR (len >> 31, len));
00045 
00046       if (! INTERNAL_SYSCALL_ERROR_P (res, err))
00047        return 0;
00048 
00049 # ifndef __ASSUME_FALLOCATE
00050       if (__builtin_expect (INTERNAL_SYSCALL_ERRNO (res, err) == ENOSYS, 0))
00051        __have_fallocate = -1;
00052       else
00053 # endif
00054        if (INTERNAL_SYSCALL_ERRNO (res, err) != EOPNOTSUPP)
00055          return INTERNAL_SYSCALL_ERRNO (res, err);
00056     }
00057 #endif
00058 
00059   return internal_fallocate (fd, offset, len);
00060 }