1 /* Private interface between modules 'clean-temp-simple' and 'clean-temp'.
2 Copyright (C) 2006-2021 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17 #ifndef _CLEAN_TEMP_PRIVATE_H
18 #define _CLEAN_TEMP_PRIVATE_H
23 #include "asyncsafe-spin.h"
25 /* The use of 'volatile' in the types below (and ISO C 99 section 5.1.2.3.(5))
26 ensure that while constructing or modifying the data structures, the field
27 values are written to memory in the order of the C statements. So the
28 signal handler can rely on these field values to be up to date. */
30 /* Registry for a single temporary directory.
31 'struct temp_dir' from the public header file overlaps with this. */
34 /* The absolute pathname of the directory. */
35 char * volatile dirname;
36 /* Whether errors during explicit cleanup are reported to standard error. */
38 /* Absolute pathnames of subdirectories. */
39 gl_list_t /* <char *> */ volatile subdirs;
40 /* Absolute pathnames of files. */
41 gl_list_t /* <char *> */ volatile files;
44 /* List of all temporary directories. */
47 struct tempdir * volatile * volatile tempdir_list;
48 size_t volatile tempdir_count;
49 size_t tempdir_allocated;
51 #define dir_cleanup_list clean_temp_dir_cleanup_list
52 extern struct all_tempdirs dir_cleanup_list;
54 /* A file descriptor to be closed.
55 In multithreaded programs, it is forbidden to close the same fd twice,
56 because you never know what unrelated open() calls are being executed in
57 other threads. So, the 'close (fd)' must be guarded by a once-only guard. */
60 /* The file descriptor to close. */
62 /* Set to true when it has been closed. */
64 /* Lock that protects the fd from being closed twice. */
65 asyncsafe_spinlock_t lock;
66 /* Tells whether this list element has been done and can be freed. */
69 #define descriptors clean_temp_descriptors
70 extern gl_list_t /* <closeable_fd *> */ volatile descriptors;
72 extern bool clean_temp_string_equals (const void *x1, const void *x2);
73 extern size_t clean_temp_string_hash (const void *x);
75 extern _GL_ASYNC_SAFE int clean_temp_asyncsafe_close (struct closeable_fd *element);
76 extern void clean_temp_init_asyncsafe_close (void);
78 extern int clean_temp_init (void);
80 extern int clean_temp_unlink (const char *absolute_file_name, bool cleanup_verbose);
82 #endif /* _CLEAN_TEMP_PRIVATE_H */