setreuid.c 888 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /*
  2. * setreuid() 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_setreuid32)) || __WORDSIZE == 64
  12. # ifdef __NR_setreuid32
  13. # undef __NR_setreuid
  14. # define __NR_setreuid __NR_setreuid32
  15. # endif
  16. _syscall2(int, setreuid, uid_t, ruid, uid_t, euid)
  17. #else
  18. # define __NR___syscall_setreuid __NR_setreuid
  19. static __inline__ _syscall2(int, __syscall_setreuid,
  20. __kernel_uid_t, ruid, __kernel_uid_t, euid)
  21. int setreuid(uid_t ruid, uid_t euid)
  22. {
  23. if (((ruid + 1) > (uid_t) ((__kernel_uid_t) - 1U))
  24. || ((euid + 1) > (uid_t) ((__kernel_uid_t) - 1U))) {
  25. __set_errno(EINVAL);
  26. return -1;
  27. }
  28. return (__syscall_setreuid(ruid, euid));
  29. }
  30. #endif
  31. libc_hidden_weak(setreuid)