setegid.c 796 B

123456789101112131415161718192021222324252627282930313233343536373839
  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. #if !defined __UCLIBC_LINUX_SPECIFIC__
  13. #undef __NR_setresgid
  14. #undef __NR_setresgid32
  15. #endif
  16. int setegid(gid_t gid)
  17. {
  18. int result;
  19. if (gid == (gid_t) ~0)
  20. {
  21. __set_errno (EINVAL);
  22. return -1;
  23. }
  24. #if (defined __NR_setresgid || defined __NR_setresgid32) && defined __USE_GNU
  25. result = setresgid(-1, gid, -1);
  26. if (result == -1 && errno == ENOSYS)
  27. /* Will also set the saved group ID if egid != gid,
  28. * making it impossible to switch back...*/
  29. #endif
  30. result = setregid(-1, gid);
  31. return result;
  32. }