Replace FSF snail mail address with URLs.
[glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / chown.c
blobbc471454e46202242630c5b2b50b8b362f8737da
1 /* Copyright (C) 2000,2001,2002,2003,2004,2006 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <http://www.gnu.org/licenses/>. */
18 #include <errno.h>
19 #include <unistd.h>
21 #include <sysdep.h>
22 #include <sys/syscall.h>
23 #include <shlib-compat.h>
24 #include <bp-checks.h>
26 #include <linux/posix_types.h>
27 #include <kernel-features.h>
30 In Linux 2.1.x the chown functions have been changed. A new function lchown
31 was introduced. The new chown now follows symlinks - the old chown and the
32 new lchown do not follow symlinks.
33 The new lchown function has the same number as the old chown had and the
34 new chown has a new number. When compiling with headers from Linux > 2.1.8x
35 it's impossible to run this libc with older kernels. In these cases libc
36 has therefore to route calls to chown to the old chown function.
39 /* Running under Linux > 2.1.80. */
41 #ifdef __NR_chown32
42 # if __ASSUME_32BITUIDS == 0
43 /* This variable is shared with all files that need to check for 32bit
44 uids. */
45 extern int __libc_missing_32bit_uids;
46 # endif
47 #endif /* __NR_chown32 */
49 int
50 __real_chown (const char *file, uid_t owner, gid_t group)
52 #if __ASSUME_32BITUIDS > 0
53 return INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
54 #else
55 static int __libc_old_chown;
56 int result;
58 if (!__libc_old_chown)
60 int saved_errno = errno;
61 # ifdef __NR_chown32
62 if (__libc_missing_32bit_uids <= 0)
64 int result;
65 int saved_errno = errno;
67 result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
68 if (result == 0 || errno != ENOSYS)
69 return result;
71 __set_errno (saved_errno);
72 __libc_missing_32bit_uids = 1;
74 # endif /* __NR_chown32 */
75 if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
76 || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
78 __set_errno (EINVAL);
79 return -1;
82 result = INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
84 if (result >= 0 || errno != ENOSYS)
85 return result;
87 __set_errno (saved_errno);
88 __libc_old_chown = 1;
91 return __lchown (file, owner, group);
92 #endif
96 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
97 /* Compiling for compatibiity. */
98 int
99 attribute_compat_text_section
100 __chown_is_lchown (const char *file, uid_t owner, gid_t group)
102 return __lchown (file, owner, group);
104 #endif
106 #if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
107 strong_alias (__chown_is_lchown, _chown_is_lchown)
108 compat_symbol (libc, __chown_is_lchown, __chown, GLIBC_2_0);
109 compat_symbol (libc, _chown_is_lchown, chown, GLIBC_2_0);
111 strong_alias (__real_chown, _real_chown)
112 versioned_symbol (libc, __real_chown, __chown, GLIBC_2_1);
113 versioned_symbol (libc, _real_chown, chown, GLIBC_2_1);
114 libc_hidden_ver (__real_chown, __chown)
115 #else
116 strong_alias (__real_chown, __chown)
117 libc_hidden_def (__chown)
118 weak_alias (__real_chown, chown)
119 #endif