annotate lib/unlinkdir.c @ 17409:26a04e61f560

stdio: use __REDIRECT for fwrite, fwrite_unlocked * lib/stdio.in.h (fwrite): When working around bug 11959, use __REDIRECT rather than '#define fwrite(...) ... fwrite (...) ...'. This is a more-targeted way to fix the -Wunused-value issue with clang, and it works with GCC too. Problem with targeting reported by Eric Blake in <http://lists.gnu.org/archive/html/bug-gnulib/2013-05/msg00067.html>. (fwrite_unlocked): Treat like fwrite. I ran into this issue while debugging the fwrite issue.
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 15 May 2013 15:52:42 -0700
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
1 /* unlinkdir.c - determine whether we can unlink directories
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16951
diff changeset
3 Copyright (C) 2005-2006, 2009-2013 Free Software Foundation, Inc.
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
5 This program is free software: you can redistribute it and/or modify
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
7 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
8 (at your option) any later version.
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 GNU General Public License for more details.
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7302
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
18 /* Written by Paul Eggert, Jim Meyering, and David Bartley. */
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6275
diff changeset
20 #include <config.h>
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 #include "unlinkdir.h"
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
23 #include "priv-set.h"
16951
9009d83acea4 root-uid: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
24 #include "root-uid.h"
6275
fd0ccce602e4 Sync from coreutils.
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
25 #include <unistd.h>
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27 #if ! UNLINK_CANNOT_UNLINK_DIR
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
28
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29 /* Return true if we cannot unlink directories, false if we might be
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
30 able to unlink directories. */
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 bool
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
33 cannot_unlink_dir (void)
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
34 {
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35 static bool initialized;
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 static bool cannot;
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
38 if (! initialized)
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
39 {
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
40 # if defined PRIV_SYS_LINKDIR
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41 /* We might be able to unlink directories if we cannot
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11538
diff changeset
42 determine our privileges, or if we have the
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 11538
diff changeset
43 PRIV_SYS_LINKDIR privilege. */
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 11257
diff changeset
44 cannot = (priv_set_ismember (PRIV_SYS_LINKDIR) == 0);
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
45 # else
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
46 /* In traditional Unix, only root can unlink directories. */
16951
9009d83acea4 root-uid: new module
Paul Eggert <eggert@cs.ucla.edu>
parents: 16201
diff changeset
47 cannot = (geteuid () != ROOT_UID);
5852
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
48 # endif
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
49 initialized = true;
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50 }
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
51
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
52 return cannot;
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
53 }
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
54
995d030c6a1f New unlinkdir module.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
55 #endif