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
9 #include <sys/syscall.h>
10 #include <unistd.h>
11 #include <bits/wordsize.h>
12
13 #if defined __NR_fchownat && !defined __NR_lchown
14 # include <fcntl.h>
lchown(const char * path,uid_t owner,gid_t group)15 int lchown(const char *path, uid_t owner, gid_t group)
16 {
17 return fchownat(AT_FDCWD, path, owner, group, AT_SYMLINK_NOFOLLOW);
18 }
19
20 #else
21
22 # if (__WORDSIZE == 32 && defined(__NR_lchown32)) || __WORDSIZE == 64
23 # ifdef __NR_lchown32
24 # undef __NR_lchown
25 # define __NR_lchown __NR_lchown32
26 # endif
27
28 _syscall3(int, lchown, const char *, path, uid_t, owner, gid_t, group)
29
30 # else
31
32 # define __NR___syscall_lchown __NR_lchown
33 static __inline__ _syscall3(int, __syscall_lchown, const char *, path,
34 __kernel_uid_t, owner, __kernel_gid_t, group)
35
36 int lchown(const char *path, uid_t owner, gid_t group)
37 {
38 if (((owner + 1) > (uid_t) ((__kernel_uid_t) - 1U))
39 || ((group + 1) > (gid_t) ((__kernel_gid_t) - 1U))) {
40 __set_errno(EINVAL);
41 return -1;
42 }
43 return __syscall_lchown(path, owner, group);
44 }
45
46 # endif
47
48 #endif
49