annotate lib/clean-temp.h @ 14379:2330aac2ae54

maint: adjust cpp indentation to reflect nesting depth I.e., in a block of code that begins with an unnested "#if", put one space between the "#" in column 1 and following token. For example, -#include <sys/vfs.h> +# include <sys/vfs.h> Do this only in .c files that are part of a module I maintain. * lib/linkat.c: Filter through cppi. * lib/nanosleep.c: Likewise. * lib/openat.c: Likewise. * lib/openat-die.c: Likewise. * lib/dup3.c: Likewise. * lib/fchownat.c: Likewise. * lib/flock.c: Likewise. * lib/fsync.c: Likewise. * lib/fts.c: Likewise. * lib/getpass.c: Likewise. * lib/gettimeofday.c: Likewise. * lib/userspec.c: Likewise. * Makefile (sc_cpp_indent_check): New rule, to check this.
author Jim Meyering <meyering@redhat.com>
date Sun, 20 Feb 2011 23:02:43 +0100
parents 97fc9a21a8fb
children e38cec555642
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Temporary directories and temporary files with automatic cleanup.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2006.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 7422
diff changeset
5 This program is free software: you can redistribute it and/or modify
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
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: 7422
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: 7422
diff changeset
8 (at your option) any later version.
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 GNU General Public License for more details.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
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: 7422
diff changeset
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 #ifndef _CLEAN_TEMP_H
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #define _CLEAN_TEMP_H
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdbool.h>
7411
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
22 #include <stdio.h>
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
23 #include <sys/types.h>
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #ifdef __cplusplus
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 extern "C" {
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #endif
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 /* Temporary directories and temporary files should be automatically removed
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 when the program exits either normally or through a fatal signal. We can't
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 rely on the "unlink before close" idiom, because it works only on Unix and
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 also - if no signal blocking is used - leaves a time window where a fatal
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 signal would not clean up the temporary file.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
7411
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
36 Also, open file descriptors need to be closed before the temporary files
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
37 and the temporary directories can be removed, because only on Unix
7422
fd5a9db5be5b Comment changes.
Bruno Haible <bruno@clisp.org>
parents: 7417
diff changeset
38 (excluding Cygwin) can one remove directories containing open files.
7411
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
39
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 This module provides support for temporary directories and temporary files
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 inside these temporary directories. Temporary files without temporary
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 directories are not supported here. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 struct temp_dir
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 {
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* The absolute pathname of the directory. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 const char * const dir_name;
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 /* Whether errors during explicit cleanup are reported to standard error. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 bool cleanup_verbose;
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* More fields are present here, but not public. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 };
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 /* Create a temporary directory.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 PREFIX is used as a prefix for the name of the temporary directory. It
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 should be short and still give an indication about the program.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 PARENTDIR can be used to specify the parent directory; if NULL, a default
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 parent directory is used (either $TMPDIR or /tmp or similar).
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 CLEANUP_VERBOSE determines whether errors during explicit cleanup are
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 reported to standard error.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 Return a fresh 'struct temp_dir' on success. Upon error, an error message
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 is shown and NULL is returned. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 extern struct temp_dir * create_temp_dir (const char *prefix,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
63 const char *parentdir,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
64 bool cleanup_verbose);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 /* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 needs to be removed before DIR can be removed.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 Should be called before the file ABSOLUTE_FILE_NAME is created. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 extern void register_temp_file (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
70 const char *absolute_file_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 /* Unregister the given ABSOLUTE_FILE_NAME as being a file inside DIR, that
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 needs to be removed before DIR can be removed.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 extern void unregister_temp_file (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
76 const char *absolute_file_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 /* Register the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 that needs to be removed before DIR can be removed.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 extern void register_temp_subdir (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
82 const char *absolute_dir_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Unregister the given ABSOLUTE_DIR_NAME as being a subdirectory inside DIR,
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 that needs to be removed before DIR can be removed.
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 Should be called when the subdirectory ABSOLUTE_DIR_NAME could not be
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 created. */
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 extern void unregister_temp_subdir (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
89 const char *absolute_dir_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
7415
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
91 /* Remove the given ABSOLUTE_FILE_NAME and unregister it.
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
92 Return 0 upon success, or -1 if there was some problem. */
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
93 extern int cleanup_temp_file (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
94 const char *absolute_file_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95
7415
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
96 /* Remove the given ABSOLUTE_DIR_NAME and unregister it.
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
97 Return 0 upon success, or -1 if there was some problem. */
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
98 extern int cleanup_temp_subdir (struct temp_dir *dir,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
99 const char *absolute_dir_name);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100
7415
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
101 /* Remove all registered files and subdirectories inside DIR.
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
102 Return 0 upon success, or -1 if there was some problem. */
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
103 extern int cleanup_temp_dir_contents (struct temp_dir *dir);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 /* Remove all registered files and subdirectories inside DIR and DIR itself.
7415
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
106 DIR cannot be used any more after this call.
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
107 Return 0 upon success, or -1 if there was some problem. */
66b32599c835 Return an error indicator.
Bruno Haible <bruno@clisp.org>
parents: 7411
diff changeset
108 extern int cleanup_temp_dir (struct temp_dir *dir);
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109
7411
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
110 /* Open a temporary file in a temporary directory.
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
111 Registers the resulting file descriptor to be closed. */
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
112 extern int open_temp (const char *file_name, int flags, mode_t mode);
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
113 extern FILE * fopen_temp (const char *file_name, const char *mode);
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
114
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
115 /* Close a temporary file in a temporary directory.
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
116 Unregisters the previously registered file descriptor. */
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
117 extern int close_temp (int fd);
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
118 extern int fclose_temp (FILE *fp);
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
119
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
120 /* Like fwriteerror.
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
121 Unregisters the previously registered file descriptor. */
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
122 extern int fwriteerror_temp (FILE *fp);
67235cf9199a Have clean-temp register file open descriptors to temporary files.
Bruno Haible <bruno@clisp.org>
parents: 7044
diff changeset
123
7417
fa9e9b096831 * clean-temp.h (close_stream_temp): New declaration.
Eric Blake <ebb9@byu.net>
parents: 7415
diff changeset
124 /* Like close_stream.
fa9e9b096831 * clean-temp.h (close_stream_temp): New declaration.
Eric Blake <ebb9@byu.net>
parents: 7415
diff changeset
125 Unregisters the previously registered file descriptor. */
fa9e9b096831 * clean-temp.h (close_stream_temp): New declaration.
Eric Blake <ebb9@byu.net>
parents: 7415
diff changeset
126 extern int close_stream_temp (FILE *fp);
fa9e9b096831 * clean-temp.h (close_stream_temp): New declaration.
Eric Blake <ebb9@byu.net>
parents: 7415
diff changeset
127
7044
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 #ifdef __cplusplus
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 }
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 #endif
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132
4165bec5f3a2 New module 'clean-temp'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 #endif /* _CLEAN_TEMP_H */