yuezonghe | 824eb0c | 2024-06-27 02:32:26 -0700 | [diff] [blame] | 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 | #include <unistd.h> |
| 8 | #include <stdio.h> |
| 9 | #include <errno.h> |
| 10 | #include <grp.h> |
| 11 | #include <sys/types.h> |
| 12 | #include <sys/syscall.h> |
| 13 | |
| 14 | |
| 15 | #if !defined __UCLIBC_LINUX_SPECIFIC__ |
| 16 | #undef __NR_setresgid |
| 17 | #undef __NR_setresgid32 |
| 18 | #endif |
| 19 | |
| 20 | int setegid(gid_t gid) |
| 21 | { |
| 22 | int result; |
| 23 | |
| 24 | if (gid == (gid_t) ~0) |
| 25 | { |
| 26 | __set_errno (EINVAL); |
| 27 | return -1; |
| 28 | } |
| 29 | |
| 30 | #if (defined __NR_setresgid || defined __NR_setresgid32) && defined __USE_GNU |
| 31 | result = setresgid(-1, gid, -1); |
| 32 | if (result == -1 && errno == ENOSYS) |
| 33 | /* Will also set the saved group ID if egid != gid, |
| 34 | * making it impossible to switch back...*/ |
| 35 | #endif |
| 36 | result = setregid(-1, gid); |
| 37 | |
| 38 | return result; |
| 39 | } |