setegid.c 799 B

1234567891011121314151617181920212223242526272829303132333435363738
  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
  13. libc_hidden_proto(setresgid)
  14. #endif
  15. libc_hidden_proto(setregid)
  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
  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. }