setegid.c 702 B

123456789101112131415161718192021222324252627282930313233
  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. #include <unistd.h>
  7. #include <stdio.h>
  8. #include <errno.h>
  9. #include <grp.h>
  10. #include <sys/types.h>
  11. #include <sys/syscall.h>
  12. int setegid(gid_t gid)
  13. {
  14. int result;
  15. if (gid == (gid_t) ~0)
  16. {
  17. __set_errno (EINVAL);
  18. return -1;
  19. }
  20. #if (defined __NR_setresgid || defined __NR_setresgid32) && defined __USE_GNU
  21. result = setresgid(-1, gid, -1);
  22. if (result == -1 && errno == ENOSYS)
  23. /* Will also set the saved group ID if egid != gid,
  24. * making it impossible to switch back...*/
  25. #endif
  26. result = setregid(-1, gid);
  27. return result;
  28. }