Back to index

glibc  2.9
xstat.c
Go to the documentation of this file.
00001 /* xstat using old-style Unix stat system call.
00002    Copyright (C) 1991,95,96,97,98,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 __xstat64 __xstat64_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 
00046 /* Get information about the file NAME in BUF.  */
00047 int
00048 __xstat (int vers, const char *name, struct stat *buf)
00049 {
00050 #if __ASSUME_STAT64_SYSCALL == 0
00051   struct kernel_stat kbuf;
00052 #endif
00053   int result;
00054 
00055   if (vers == _STAT_VER_KERNEL)
00056     return INLINE_SYSCALL (stat, 2, CHECK_STRING (name), CHECK_1 ((struct kernel_stat *) buf));
00057 
00058 #if __ASSUME_STAT64_SYSCALL > 0
00059   {
00060     struct stat64 buf64;
00061 
00062     result = INLINE_SYSCALL (stat64, 2, CHECK_STRING (name), __ptrvalue (&buf64));
00063     if (result == 0)
00064       result = __xstat32_conv (vers, &buf64, buf);
00065     return result;
00066   }
00067 #else
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 (stat64, 2, CHECK_STRING (name), __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   result = INLINE_SYSCALL (stat, 2, CHECK_STRING (name), __ptrvalue (&kbuf));
00087   if (result == 0)
00088     result = __xstat_conv (vers, &kbuf, buf);
00089 
00090   return result;
00091 #endif  /* __ASSUME_STAT64_SYSCALL  */
00092 }
00093 hidden_def (__xstat)
00094 weak_alias (__xstat, _xstat);
00095 #ifdef XSTAT_IS_XSTAT64
00096 # undef __xstat64
00097 strong_alias (__xstat, __xstat64);
00098 hidden_ver (__xstat, __xstat64)
00099 #endif