]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/i386/setregid.c
Update.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / i386 / setregid.c
CommitLineData
2edb61e3 1/* Copyright (C) 1998, 2000, 2003, 2004 Free Software Foundation, Inc.
0dee6738
UD
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
0dee6738
UD
8
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
41bdb6e2 12 Lesser General Public License for more details.
0dee6738 13
41bdb6e2
AJ
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. */
0dee6738
UD
18
19#include <errno.h>
0dee6738 20#include <unistd.h>
85bd6331 21#include <setxid.h>
313fed01
UD
22#include "kernel-features.h"
23
0dee6738 24
313fed01 25#ifdef __NR_setregid32
313fed01
UD
26# if __ASSUME_32BITUIDS == 0
27/* This variable is shared with all files that need to check for 32bit
28 uids. */
29extern int __libc_missing_32bit_uids;
30# endif
31#endif /* __NR_setregid32 */
32
0dee6738
UD
33int
34__setregid (gid_t rgid, gid_t egid)
35{
2edb61e3
UD
36 int result;
37
313fed01 38#if __ASSUME_32BITUIDS > 0
85bd6331 39 result = INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
313fed01 40#else
54c92465 41# ifdef __NR_setregid32
cd090f71 42 if (__libc_missing_32bit_uids <= 0)
313fed01 43 {
313fed01
UD
44 int saved_errno = errno;
45
85bd6331 46 result = INLINE_SETXID_SYSCALL (setregid32, 2, rgid, egid);
313fed01 47
2edb61e3
UD
48 if (result == 0)
49 goto out;
50 if (errno != ENOSYS)
313fed01
UD
51 return result;
52
53 __set_errno (saved_errno);
54 __libc_missing_32bit_uids = 1;
55 }
56# endif /* __NR_setregid32 */
0482576e
UD
57 if (((rgid + 1) > (gid_t) ((__kernel_gid_t) -1U))
58 || ((egid + 1) > (gid_t) ((__kernel_gid_t) -1U)))
0dee6738
UD
59 {
60 __set_errno (EINVAL);
61 return -1;
62 }
63
85bd6331 64 result = INLINE_SETXID_SYSCALL (setregid, 2, rgid, egid);
2edb61e3
UD
65# ifdef __NR_setregid32
66 out:
67# endif
313fed01 68#endif
2edb61e3 69
2edb61e3 70 return result;
0dee6738 71}
2edb61e3 72#ifndef __setregid
0dee6738 73weak_alias (__setregid, setregid)
2edb61e3 74#endif