root/maint/gnulib/lib/clean-temp-private.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


   1 /* Private interface between modules 'clean-temp-simple' and 'clean-temp'.
   2    Copyright (C) 2006-2021 Free Software Foundation, Inc.
   3 
   4    This file is free software: you can redistribute it and/or modify
   5    it under the terms of the GNU Lesser General Public License as
   6    published by the Free Software Foundation; either version 2.1 of the
   7    License, or (at your option) any later version.
   8 
   9    This file 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 Lesser General Public License for more details.
  13 
  14    You should have received a copy of the GNU Lesser General Public License
  15    along with this program.  If not, see <https://www.gnu.org/licenses/>.  */
  16 
  17 #ifndef _CLEAN_TEMP_PRIVATE_H
  18 #define _CLEAN_TEMP_PRIVATE_H
  19 
  20 #include <stdbool.h>
  21 #include <stddef.h>
  22 #include "gl_list.h"
  23 #include "asyncsafe-spin.h"
  24 
  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.  */
  29 
  30 /* Registry for a single temporary directory.
  31    'struct temp_dir' from the public header file overlaps with this.  */
  32 struct tempdir
  33 {
  34   /* The absolute pathname of the directory.  */
  35   char * volatile dirname;
  36   /* Whether errors during explicit cleanup are reported to standard error.  */
  37   bool cleanup_verbose;
  38   /* Absolute pathnames of subdirectories.  */
  39   gl_list_t /* <char *> */ volatile subdirs;
  40   /* Absolute pathnames of files.  */
  41   gl_list_t /* <char *> */ volatile files;
  42 };
  43 
  44 /* List of all temporary directories.  */
  45 struct all_tempdirs
  46 {
  47   struct tempdir * volatile * volatile tempdir_list;
  48   size_t volatile tempdir_count;
  49   size_t tempdir_allocated;
  50 };
  51 #define dir_cleanup_list clean_temp_dir_cleanup_list
  52 extern struct all_tempdirs dir_cleanup_list;
  53 
  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.  */
  58 struct closeable_fd
  59 {
  60   /* The file descriptor to close.  */
  61   int volatile fd;
  62   /* Set to true when it has been closed.  */
  63   bool volatile 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.  */
  67   bool volatile done;
  68 };
  69 #define descriptors clean_temp_descriptors
  70 extern gl_list_t /* <closeable_fd *> */ volatile descriptors;
  71 
  72 extern bool clean_temp_string_equals (const void *x1, const void *x2);
  73 extern size_t clean_temp_string_hash (const void *x);
  74 
  75 extern _GL_ASYNC_SAFE int clean_temp_asyncsafe_close (struct closeable_fd *element);
  76 extern void clean_temp_init_asyncsafe_close (void);
  77 
  78 extern int clean_temp_init (void);
  79 
  80 extern int clean_temp_unlink (const char *absolute_file_name, bool cleanup_verbose);
  81 
  82 #endif /* _CLEAN_TEMP_PRIVATE_H */

/* [previous][next][first][last][top][bottom][index][help] */