Remove *xattr syscalls.
[glibc.git] / sysdeps / unix / sysv / linux / i386 / getgroups.c
blob2f421176925bbfc4ce7b9a18e9fb9895258c4630
1 /* Copyright (C) 1997, 1998, 2000, 2001 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
19 #include <errno.h>
20 #include <unistd.h>
21 #include <sys/param.h>
22 #include <sys/types.h>
24 #include <sysdep.h>
25 #include <sys/syscall.h>
26 #include <bp-checks.h>
28 #include <linux/posix_types.h>
29 #include <kernel-features.h>
32 extern int __syscall_getgroups (int, __kernel_gid_t *__unbounded);
34 #ifdef __NR_getgroups32
35 extern int __syscall_getgroups32 (int, __kernel_gid32_t *__unbounded);
36 # if __ASSUME_32BITUIDS == 0
37 /* This variable is shared with all files that need to check for 32bit
38 uids. */
39 extern int __libc_missing_32bit_uids;
40 # endif
41 #endif /* __NR_getgroups32 */
43 /* For Linux we must convert the array of groups from the format that the
44 kernel returns. */
45 int
46 __getgroups (int n, gid_t *groups)
48 #if __ASSUME_32BITUIDS > 0
49 return INLINE_SYSCALL (getgroups32, 2, n, CHECK_N (groups, n));
50 #else
51 if (__builtin_expect (n, 1) < 0)
53 __set_errno (EINVAL);
54 return -1;
56 else
58 int i, ngids;
59 __kernel_gid_t kernel_groups[n = MIN (n, __sysconf (_SC_NGROUPS_MAX))];
60 # ifdef __NR_getgroups32
61 if (__libc_missing_32bit_uids <= 0)
63 int result;
64 int saved_errno = errno;
66 result = INLINE_SYSCALL (getgroups32, 2, n, CHECK_N (groups, n));
67 if (result == 0 || errno != ENOSYS)
68 return result;
70 __set_errno (saved_errno);
71 __libc_missing_32bit_uids = 1;
73 # endif /* __NR_getgroups32 */
75 ngids = INLINE_SYSCALL (getgroups, 2, n, CHECK_N (kernel_groups, n));
76 if (n != 0 && ngids > 0)
77 for (i = 0; i < ngids; i++)
78 (__ptrvalue (groups))[i] = kernel_groups[i];
79 return ngids;
81 #endif
84 weak_alias (__getgroups, getgroups)