setuid.c 740 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * setuid() 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_setuid32)) || __WORDSIZE == 64
  12. # ifdef __NR_setuid32
  13. # undef __NR_setuid
  14. # define __NR_setuid __NR_setuid32
  15. # endif
  16. _syscall1(int, setuid, uid_t, uid)
  17. #else
  18. # define __NR___syscall_setuid __NR_setuid
  19. static __always_inline _syscall1(int, __syscall_setuid, __kernel_uid_t, uid)
  20. int setuid(uid_t uid)
  21. {
  22. if (uid == (uid_t) ~ 0 || uid != (uid_t) ((__kernel_uid_t) uid)) {
  23. __set_errno(EINVAL);
  24. return -1;
  25. }
  26. return __syscall_setuid(uid);
  27. }
  28. #endif