setegid.c 788 B

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