summaryrefslogtreecommitdiff
path: root/libc/sysdeps/linux/common/setegid.c
blob: d3175dad57001e091e42a56a7a513c2a78630e17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define setresgid __setresgid
#define setregid __setregid

#define _GNU_SOURCE
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include <grp.h>
#include <sys/types.h>
#include <sys/syscall.h>

int setegid(gid_t gid)
{
    int result;

    if (gid == (gid_t) ~0)
    {
	__set_errno (EINVAL);
	return -1;
    }

#ifdef __NR_setresgid
    result = setresgid(-1, gid, -1);
    if (result == -1 && errno == ENOSYS)
	/* Will also set the saved group ID if egid != gid,
	 * making it impossible to switch back...*/
#endif
	result = setregid(-1, gid);

    return result;
}