Back to index

glibc  2.9
getresgid.c
Go to the documentation of this file.
00001 /* Copyright (C) 1998,2000,2002,2003,2005,2006 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 <errno.h>
00020 #include <unistd.h>
00021 #include <sys/types.h>
00022 
00023 #include <linux/posix_types.h>
00024 
00025 #include <sysdep.h>
00026 #include <sys/syscall.h>
00027 #include <bp-checks.h>
00028 
00029 #include <kernel-features.h>
00030 
00031 #ifdef __NR_getresgid
00032 
00033 # ifdef __NR_getresgid32
00034 #  if __ASSUME_32BITUIDS == 0
00035 /* This variable is shared with all files that need to check for 32bit
00036    uids.  */
00037 extern int __libc_missing_32bit_uids;
00038 #  endif
00039 # endif /* __NR_getresgid32 */
00040 
00041 
00042 int
00043 __getresgid (gid_t *rgid, gid_t *egid, gid_t *sgid)
00044 {
00045 # if __ASSUME_32BITUIDS > 0
00046   return INLINE_SYSCALL (getresgid32, 3, CHECK_1 (rgid),
00047                       CHECK_1 (egid), CHECK_1 (sgid));
00048 # else
00049   __kernel_gid_t k_rgid, k_egid, k_sgid;
00050   int result;
00051 #  ifdef __NR_getresgid32
00052   if (__libc_missing_32bit_uids <= 0)
00053     {
00054       int r;
00055       int saved_errno = errno;
00056 
00057       r = INLINE_SYSCALL (getresgid32, 3, CHECK_1 (rgid),
00058                        CHECK_1 (egid), CHECK_1 (sgid));
00059       if (r == 0 || errno != ENOSYS)
00060        return r;
00061 
00062       __set_errno (saved_errno);
00063       __libc_missing_32bit_uids = 1;
00064     }
00065 #  endif /* __NR_getresgid32 */
00066 
00067   result = INLINE_SYSCALL (getresgid, 3, __ptrvalue (&k_rgid),
00068                         __ptrvalue (&k_egid), __ptrvalue (&k_sgid));
00069 
00070   if (result == 0)
00071     {
00072       *rgid = (gid_t) k_rgid;
00073       *egid = (gid_t) k_egid;
00074       *sgid = (gid_t) k_sgid;
00075     }
00076 
00077   return result;
00078 # endif
00079 }
00080 libc_hidden_def (__getresgid)
00081 weak_alias (__getresgid, getresgid)
00082 
00083 #else
00084 # include <posix/getresgid.c>
00085 #endif