setgid.c 737 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * setgid() 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_setgid32)) || __WORDSIZE == 64
  12. # ifdef __NR_setgid32
  13. # undef __NR_setgid
  14. # define __NR_setgid __NR_setgid32
  15. # endif
  16. _syscall1(int, setgid, gid_t, gid)
  17. #else
  18. # define __NR___syscall_setgid __NR_setgid
  19. static __inline__ _syscall1(int, __syscall_setgid, __kernel_gid_t, gid)
  20. int setgid(gid_t gid)
  21. {
  22. if (gid == (gid_t) ~ 0 || gid != (gid_t) ((__kernel_gid_t) gid)) {
  23. __set_errno(EINVAL);
  24. return -1;
  25. }
  26. return (__syscall_setgid(gid));
  27. }
  28. #endif