Add tests with filenames containing newline and backslash characters.
[coreutils.git] / lib / chown.c
blob63b89c27e8a03ba6783fa793ff6a2db9b2fc2ff5
1 /* provide consistent interface to chown for systems that don't interpret
2 an ID of -1 as meaning `don't change the corresponding ID'.
3 Copyright (C) 1997 Free Software Foundation, Inc.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2, or (at your option)
8 any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software Foundation,
17 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19 /* written by Jim Meyering */
21 #include <config.h>
23 /* Disable the definition of chown to rpl_chown (from config.h) in this
24 file. Otherwise, we'd get conflicting prototypes for rpl_chown on
25 most systems. */
26 #undef chown
28 #include <sys/types.h>
29 #include <sys/stat.h>
30 #if HAVE_UNISTD_H
31 # include <unistd.h>
32 #endif
34 /* FIXME: describe. */
36 int
37 rpl_chown (file, uid, gid)
38 const char *file;
39 uid_t uid;
40 gid_t gid;
42 if (gid == (gid_t) -1 || uid == (uid_t) -1)
44 struct stat file_stats;
46 /* Stat file to get id(s) that should remain unchanged. */
47 if (stat (file, &file_stats))
48 return 1;
50 if (gid == (gid_t) -1)
51 gid = file_stats.st_gid;
53 if (uid == (uid_t) -1)
54 uid = file_stats.st_uid;
57 return chown (file, uid, gid);