source: trunk/essentials/app-arch/cpio/lib/lchown.c

Last change on this file was 3332, checked in by bird, 18 years ago

cpio 2.7

File size: 1.6 KB
Line 
1/* Provide a stub lchown function for systems that lack it.
2
3 Copyright (C) 1998, 1999, 2002, 2004, 2006 Free Software
4 Foundation, Inc.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software Foundation,
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
19
20/* written by Jim Meyering */
21
22#include <config.h>
23
24#include <sys/types.h>
25#include <sys/stat.h>
26#include <errno.h>
27
28#include "lchown.h"
29#include "stat-macros.h"
30
31/* Declare chown to avoid a warning. Don't include unistd.h,
32 because it may have a conflicting prototype for lchown. */
33int chown ();
34
35/* Work just like chown, except when FILE is a symbolic link.
36 In that case, set errno to EOPNOTSUPP and return -1.
37 But if autoconf tests determined that chown modifies
38 symlinks, then just call chown. */
39
40int
41lchown (const char *file, uid_t uid, gid_t gid)
42{
43#if ! CHOWN_MODIFIES_SYMLINK
44 struct stat stats;
45
46 if (lstat (file, &stats) == 0 && S_ISLNK (stats.st_mode))
47 {
48 errno = EOPNOTSUPP;
49 return -1;
50 }
51#endif
52
53 return chown (file, uid, gid);
54}
Note: See TracBrowser for help on using the repository browser.