Back to index

glibc  2.9
fxstat.c
Go to the documentation of this file.
00001 /* fxstat using old-style Unix fstat system call.
00002    Copyright (C) 1991,1995-1998,2000,2002,2003,2006
00003        Free Software Foundation, Inc.
00004    This file is part of the GNU C Library.
00005 
00006    The GNU C Library is free software; you can redistribute it and/or
00007    modify it under the terms of the GNU Lesser General Public
00008    License as published by the Free Software Foundation; either
00009    version 2.1 of the License, or (at your option) any later version.
00010 
00011    The GNU C Library is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014    Lesser General Public License for more details.
00015 
00016    You should have received a copy of the GNU Lesser General Public
00017    License along with the GNU C Library; if not, write to the Free
00018    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00019    02111-1307 USA.  */
00020 
00021 /* Ho hum, if xstat == xstat64 we must get rid of the prototype or gcc
00022    will complain since they don't strictly match.  */
00023 #define __fxstat64 __fxstat64_disable
00024 
00025 #include <errno.h>
00026 #include <stddef.h>
00027 #include <sys/stat.h>
00028 #include <kernel_stat.h>
00029 
00030 #include <sysdep.h>
00031 #include <sys/syscall.h>
00032 #include <bp-checks.h>
00033 
00034 #include <kernel-features.h>
00035 
00036 #include <xstatconv.h>
00037 
00038 #ifdef __NR_stat64
00039 # if  __ASSUME_STAT64_SYSCALL == 0
00040 /* The variable is shared between all wrappers around *stat64 calls.  */
00041 extern int __have_no_stat64;
00042 # endif
00043 #endif
00044 
00045 /* Get information about the file FD in BUF.  */
00046 int
00047 __fxstat (int vers, int fd, struct stat *buf)
00048 {
00049 #if __ASSUME_STAT64_SYSCALL == 0
00050   struct kernel_stat kbuf;
00051 #endif
00052   int result;
00053 
00054   if (vers == _STAT_VER_KERNEL)
00055     return INLINE_SYSCALL (fstat, 2, fd, CHECK_1 ((struct kernel_stat *) buf));
00056 
00057 #if __ASSUME_STAT64_SYSCALL > 0
00058   {
00059     struct stat64 buf64;
00060 
00061     result = INLINE_SYSCALL (fstat64, 2, fd, __ptrvalue (&buf64));
00062     if (result == 0)
00063       result = __xstat32_conv (vers, &buf64, buf);
00064     return result;
00065   }
00066 #else
00067 
00068 # if defined __NR_stat64
00069   /* To support 32 bit UIDs, we have to use stat64.  The normal stat call only returns
00070      16 bit UIDs.  */
00071   if (! __have_no_stat64)
00072     {
00073       struct stat64 buf64;
00074 
00075       result = INLINE_SYSCALL (fstat64, 2, fd, __ptrvalue (&buf64));
00076 
00077       if (result == 0)
00078        result = __xstat32_conv (vers, &buf64, buf);
00079 
00080       if (result != -1 || errno != ENOSYS)
00081        return result;
00082 
00083       __have_no_stat64 = 1;
00084     }
00085 # endif
00086 
00087   result = INLINE_SYSCALL (fstat, 2, fd, __ptrvalue (&kbuf));
00088   if (result == 0)
00089     result = __xstat_conv (vers, &kbuf, buf);
00090 
00091   return result;
00092 #endif  /* __ASSUME_STAT64_SYSCALL  */
00093 }
00094 
00095 hidden_def (__fxstat)
00096 weak_alias (__fxstat, _fxstat);
00097 #ifdef XSTAT_IS_XSTAT64
00098 #undef __fxstat64
00099 strong_alias (__fxstat, __fxstat64);
00100 hidden_ver (__fxstat, __fxstat64)
00101 #endif