annotate lib/write-any-file.c @ 16201:8250f2777afc

maint: update all copyright year number ranges Run "make update-copyright".
author Jim Meyering <meyering@redhat.com>
date Sun, 01 Jan 2012 10:04:58 +0100
parents 97fc9a21a8fb
children 9009d83acea4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
1 /* Determine whether we can write any file.
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
2
16201
8250f2777afc maint: update all copyright year number ranges
Jim Meyering <meyering@redhat.com>
parents: 14079
diff changeset
3 Copyright (C) 2007, 2009-2012 Free Software Foundation, Inc.
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
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: 8592
diff changeset
5 This program is free software: you can redistribute it and/or modify
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
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: 8592
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: 8592
diff changeset
8 (at your option) any later version.
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
9
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
13 GNU General Public License for more details.
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
14
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
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: 8592
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
17
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
18 /* Written by Paul Eggert. */
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
19
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
20 #include <config.h>
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
21
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
22 #include "write-any-file.h"
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 9309
diff changeset
23 #include "priv-set.h"
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
24
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
25 #include <unistd.h>
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
26
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
27 /* Return true if we know that we can write any file, including
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
28 writing directories. */
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
29
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
30 bool
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
31 can_write_any_file (void)
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
32 {
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
33 static bool initialized;
8592
e91286e73129 * lib/write-any-file.c (can_write_any_file): Fix else-else bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 8504
diff changeset
34 static bool can_write;
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
35
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
36 if (! initialized)
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
37 {
8592
e91286e73129 * lib/write-any-file.c (can_write_any_file): Fix else-else bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 8504
diff changeset
38 bool can = false;
11538
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 9309
diff changeset
39 #if defined PRIV_FILE_DAC_WRITE
af683213eeb0 priv-set: new module and accompanying tests; adapt write-any-file
David Bartley <dtbartle@csclub.uwaterloo.ca>
parents: 9309
diff changeset
40 can = (priv_set_ismember (PRIV_FILE_DAC_WRITE) == 1);
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
41 #else
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
42 /* In traditional Unix, only root can unlink directories. */
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
43 can = (geteuid () == 0);
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
44 #endif
8592
e91286e73129 * lib/write-any-file.c (can_write_any_file): Fix else-else bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 8504
diff changeset
45 can_write = can;
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
46 initialized = true;
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
47 }
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
48
8592
e91286e73129 * lib/write-any-file.c (can_write_any_file): Fix else-else bug
Paul Eggert <eggert@cs.ucla.edu>
parents: 8504
diff changeset
49 return can_write;
8504
24420da38757 * MODULES.html.sh (File system functions): New module write-any-file.
Paul Eggert <eggert@cs.ucla.edu>
parents:
diff changeset
50 }