]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/s390/s390-32/chown.c
(CFLAGS-tst-align.c): Add -mpreferred-stack-boundary=4.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / s390 / s390-32 / chown.c
CommitLineData
a334319f 1/* Copyright (C) 2000, 2001, 2002, 2003, 2004 Free Software Foundation, Inc.
ba55e591
AJ
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
ba55e591
AJ
8
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
41bdb6e2 12 Lesser General Public License for more details.
ba55e591 13
41bdb6e2
AJ
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, write to the Free
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17 02111-1307 USA. */
ba55e591
AJ
18
19#include <errno.h>
20#include <unistd.h>
21
22#include <sysdep.h>
23#include <sys/syscall.h>
24#include <shlib-compat.h>
25#include <bp-checks.h>
26
27#include <linux/posix_types.h>
a334319f 28#include "kernel-features.h"
ba55e591
AJ
29
30/*
31 In Linux 2.1.x the chown functions have been changed. A new function lchown
32 was introduced. The new chown now follows symlinks - the old chown and the
33 new lchown do not follow symlinks.
34 The new lchown function has the same number as the old chown had and the
35 new chown has a new number. When compiling with headers from Linux > 2.1.8x
36 it's impossible to run this libc with older kernels. In these cases libc
37 has therefore to route calls to chown to the old chown function.
38*/
39
ba55e591
AJ
40/* Running under Linux > 2.1.80. */
41
42#ifdef __NR_chown32
ba55e591
AJ
43# if __ASSUME_32BITUIDS == 0
44/* This variable is shared with all files that need to check for 32bit
45 uids. */
46extern int __libc_missing_32bit_uids;
47# endif
48#endif /* __NR_chown32 */
49
50int
51__real_chown (const char *file, uid_t owner, gid_t group)
52{
c3293cba
UD
53#if __ASSUME_32BITUIDS > 0
54 return INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
55#else
ba55e591
AJ
56 static int __libc_old_chown;
57 int result;
58
59 if (!__libc_old_chown)
60 {
61 int saved_errno = errno;
c3293cba 62# ifdef __NR_chown32
ba55e591
AJ
63 if (__libc_missing_32bit_uids <= 0)
64 {
65 int result;
66 int saved_errno = errno;
67
68 result = INLINE_SYSCALL (chown32, 3, CHECK_STRING (file), owner, group);
69 if (result == 0 || errno != ENOSYS)
70 return result;
71
72 __set_errno (saved_errno);
73 __libc_missing_32bit_uids = 1;
74 }
c3293cba 75# endif /* __NR_chown32 */
ba55e591
AJ
76 if (((owner + 1) > (uid_t) ((__kernel_uid_t) -1U))
77 || ((group + 1) > (gid_t) ((__kernel_gid_t) -1U)))
78 {
79 __set_errno (EINVAL);
80 return -1;
81 }
82
83 result = INLINE_SYSCALL (chown, 3, CHECK_STRING (file), owner, group);
84
85 if (result >= 0 || errno != ENOSYS)
86 return result;
87
88 __set_errno (saved_errno);
89 __libc_old_chown = 1;
90 }
91
92 return __lchown (file, owner, group);
c3293cba 93#endif
ba55e591
AJ
94}
95
96
97#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
98/* Compiling for compatibiity. */
99int
d3a4a571 100attribute_compat_text_section
ba55e591
AJ
101__chown_is_lchown (const char *file, uid_t owner, gid_t group)
102{
103 return __lchown (file, owner, group);
104}
105#endif
106
107#if SHLIB_COMPAT (libc, GLIBC_2_0, GLIBC_2_1)
108strong_alias (__chown_is_lchown, _chown_is_lchown)
109compat_symbol (libc, __chown_is_lchown, __chown, GLIBC_2_0);
110compat_symbol (libc, _chown_is_lchown, chown, GLIBC_2_0);
111
112strong_alias (__real_chown, _real_chown)
113versioned_symbol (libc, __real_chown, __chown, GLIBC_2_1);
114versioned_symbol (libc, _real_chown, chown, GLIBC_2_1);
37ba7d66 115libc_hidden_ver (__real_chown, __chown)
ba55e591
AJ
116#else
117strong_alias (__real_chown, __chown)
37ba7d66 118libc_hidden_def (__chown)
ba55e591
AJ
119weak_alias (__real_chown, chown)
120#endif