fchown.c 870 B

123456789101112131415161718192021222324252627282930313233343536
  1. /* vi: set sw=4 ts=4: */
  2. /*
  3. * fchown() for uClibc
  4. *
  5. * Copyright (C) 2000-2006 by Erik Andersen <andersen@codepoet.org>
  6. *
  7. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  8. */
  9. #include "syscalls.h"
  10. #include <unistd.h>
  11. #include <linux/version.h>
  12. /* Linux 2.3.39 introduced 32bit UID/GIDs. Some platforms had 32
  13. bit type all along. */
  14. #if LINUX_VERSION_CODE >= 131879
  15. _syscall3(int, fchown, int, fd, uid_t, owner, gid_t, group);
  16. #else
  17. #define __NR___syscall_fchown __NR_fchown
  18. static inline _syscall3(int, __syscall_fchown, int, fd,
  19. __kernel_uid_t, owner, __kernel_gid_t, group);
  20. int fchown(int fd, uid_t owner, gid_t group)
  21. {
  22. if (((owner + 1) > (uid_t) ((__kernel_uid_t) - 1U))
  23. || ((group + 1) > (gid_t) ((__kernel_gid_t) - 1U))) {
  24. __set_errno(EINVAL);
  25. return -1;
  26. }
  27. return (__syscall_fchown(fd, owner, group));
  28. }
  29. #endif