chown.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * chown() 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 defined __NR_fchownat && !defined __NR_chown
  12. # include <fcntl.h>
  13. int chown(const char *path, uid_t owner, gid_t group)
  14. {
  15. return fchownat(AT_FDCWD, path, owner, group, 0);
  16. }
  17. #else
  18. # if (__WORDSIZE == 32 && defined(__NR_chown32)) || __WORDSIZE == 64
  19. # ifdef __NR_chown32
  20. # undef __NR_chown
  21. # define __NR_chown __NR_chown32
  22. # endif
  23. _syscall3(int, chown, const char *, path, uid_t, owner, gid_t, group)
  24. # else
  25. # define __NR___syscall_chown __NR_chown
  26. static __inline__ _syscall3(int, __syscall_chown, const char *, path,
  27. __kernel_uid_t, owner, __kernel_gid_t, group)
  28. int chown(const char *path, uid_t owner, gid_t group)
  29. {
  30. if (((owner + 1) > (uid_t) ((__kernel_uid_t) - 1U))
  31. || ((group + 1) > (gid_t) ((__kernel_gid_t) - 1U))) {
  32. __set_errno(EINVAL);
  33. return -1;
  34. }
  35. return (__syscall_chown(path, owner, group));
  36. }
  37. # endif
  38. #endif
  39. libc_hidden_def(chown)