lchown.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * lchown() 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_lchown
  12. # include <fcntl.h>
  13. int lchown(const char *path, uid_t owner, gid_t group)
  14. {
  15. return fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW);
  16. }
  17. #else
  18. # if (__WORDSIZE == 32 && defined(__NR_lchown32)) || __WORDSIZE == 64
  19. # ifdef __NR_lchown32
  20. # undef __NR_lchown
  21. # define __NR_lchown __NR_lchown32
  22. # endif
  23. _syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group)
  24. # else
  25. # define __NR___syscall_lchown __NR_lchown
  26. static __inline__ _syscall3(int, __syscall_lchown, const char *, path,
  27. __kernel_uid_t, owner, __kernel_gid_t, group)
  28. int lchown(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_lchown(path, owner, group);
  36. }
  37. # endif
  38. #endif