OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / sysdeps / linux / common / setegid.c
1 /*
2  * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
3  *
4  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
5  */
6
7 #define _GNU_SOURCE
8 #include <unistd.h>
9 #include <stdio.h>
10 #include <errno.h>
11 #include <grp.h>
12 #include <sys/types.h>
13 #include <sys/syscall.h>
14
15 libc_hidden_proto(setresgid)
16 libc_hidden_proto(setregid)
17
18 int setegid(gid_t gid)
19 {
20     int result;
21
22     if (gid == (gid_t) ~0)
23     {
24         __set_errno (EINVAL);
25         return -1;
26     }
27
28 #ifdef __NR_setresgid
29     result = setresgid(-1, gid, -1);
30     if (result == -1 && errno == ENOSYS)
31         /* Will also set the saved group ID if egid != gid,
32          * making it impossible to switch back...*/
33 #endif
34         result = setregid(-1, gid);
35
36     return result;
37 }