setregid.c 888 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * setregid() for uClibc
  3. *
  4. * Copyright (C) 2000-2006 Erik Andersen <andersen@uclibc.org>
  5. *
  6. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  7. */
  8. #include <sys/syscall.h>
  9. #include <unistd.h>
  10. #include <bits/wordsize.h>
  11. #if (__WORDSIZE == 32 && defined(__NR_setregid32)) || __WORDSIZE == 64
  12. # ifdef __NR_setregid32
  13. # undef __NR_setregid
  14. # define __NR_setregid __NR_setregid32
  15. # endif
  16. _syscall2(int, setregid, gid_t, rgid, gid_t, egid)
  17. #else
  18. # define __NR___syscall_setregid __NR_setregid
  19. static __inline__ _syscall2(int, __syscall_setregid,
  20. __kernel_gid_t, rgid, __kernel_gid_t, egid)
  21. int setregid(gid_t rgid, gid_t egid)
  22. {
  23. if (((rgid + 1) > (gid_t) ((__kernel_gid_t) - 1U))
  24. || ((egid + 1) > (gid_t) ((__kernel_gid_t) - 1U))) {
  25. __set_errno(EINVAL);
  26. return -1;
  27. }
  28. return (__syscall_setregid(rgid, egid));
  29. }
  30. #endif
  31. libc_hidden_weak(setregid)