- Copyright (C) 2001, 2003, 2006-2007 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2003, 2006-2007, 2009-2013 Free Software Foundation,
+ Inc.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- along with this program; if not, write to the Free Software Foundation,
- Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
- gl_list_iterator_t iter;
- const void *element;
-
- iter = gl_list_iterator (fds);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- int fd = (int) (uintptr_t) element;
- close (fd);
- }
- gl_list_iterator_free (&iter);
+ gl_list_iterator_t iter;
+ const void *element;
+
+ iter = gl_list_iterator (fds);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ int fd = (int) (uintptr_t) element;
+ close (fd);
+ }
+ gl_list_iterator_free (&iter);
- {
- gl_list_iterator_t iter;
- const void *element;
-
- /* First cleanup the files in the subdirectories. */
- iter = gl_list_iterator (dir->files);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- const char *file = (const char *) element;
- unlink (file);
- }
- gl_list_iterator_free (&iter);
-
- /* Then cleanup the subdirectories. */
- iter = gl_list_iterator (dir->subdirs);
- while (gl_list_iterator_next (&iter, &element, NULL))
- {
- const char *subdir = (const char *) element;
- rmdir (subdir);
- }
- gl_list_iterator_free (&iter);
-
- /* Then cleanup the temporary directory itself. */
- rmdir (dir->dirname);
- }
+ {
+ gl_list_iterator_t iter;
+ const void *element;
+
+ /* First cleanup the files in the subdirectories. */
+ iter = gl_list_iterator (dir->files);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ const char *file = (const char *) element;
+ unlink (file);
+ }
+ gl_list_iterator_free (&iter);
+
+ /* Then cleanup the subdirectories. */
+ iter = gl_list_iterator (dir->subdirs);
+ while (gl_list_iterator_next (&iter, &element, NULL))
+ {
+ const char *subdir = (const char *) element;
+ rmdir (subdir);
+ }
+ gl_list_iterator_free (&iter);
+
+ /* Then cleanup the temporary directory itself. */
+ rmdir (dir->dirname);
+ }
is shown and NULL is returned. */
struct temp_dir *
create_temp_dir (const char *prefix, const char *parentdir,
is shown and NULL is returned. */
struct temp_dir *
create_temp_dir (const char *prefix, const char *parentdir,
- {
- /* Note that we cannot use xrealloc(), because then the cleanup()
- function could access an already deallocated array. */
- struct tempdir * volatile *old_array = cleanup_list.tempdir_list;
- size_t old_allocated = cleanup_list.tempdir_allocated;
- size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1;
- struct tempdir * volatile *new_array =
- XNMALLOC (new_allocated, struct tempdir * volatile);
-
- if (old_allocated == 0)
- /* First use of this facility. Register the cleanup handler. */
- at_fatal_signal (&cleanup);
- else
- {
- /* Don't use memcpy() here, because memcpy takes non-volatile
- arguments and is therefore not guaranteed to complete all
- memory stores before the next statement. */
- size_t k;
-
- for (k = 0; k < old_allocated; k++)
- new_array[k] = old_array[k];
- }
-
- cleanup_list.tempdir_list = new_array;
- cleanup_list.tempdir_allocated = new_allocated;
-
- /* Now we can free the old array. */
- if (old_array != NULL)
- free ((struct tempdir **) old_array);
- }
+ {
+ /* Note that we cannot use xrealloc(), because then the cleanup()
+ function could access an already deallocated array. */
+ struct tempdir * volatile *old_array = cleanup_list.tempdir_list;
+ size_t old_allocated = cleanup_list.tempdir_allocated;
+ size_t new_allocated = 2 * cleanup_list.tempdir_allocated + 1;
+ struct tempdir * volatile *new_array =
+ XNMALLOC (new_allocated, struct tempdir * volatile);
+
+ if (old_allocated == 0)
+ /* First use of this facility. Register the cleanup handler. */
+ at_fatal_signal (&cleanup);
+ else
+ {
+ /* Don't use memcpy() here, because memcpy takes non-volatile
+ arguments and is therefore not guaranteed to complete all
+ memory stores before the next statement. */
+ size_t k;
+
+ for (k = 0; k < old_allocated; k++)
+ new_array[k] = old_array[k];
+ }
+
+ cleanup_list.tempdir_list = new_array;
+ cleanup_list.tempdir_allocated = new_allocated;
+
+ /* Now we can free the old array. */
+ if (old_array != NULL)
+ free ((struct tempdir **) old_array);
+ }
tmpdirp = &cleanup_list.tempdir_list[cleanup_list.tempdir_count];
/* Initialize *tmpdirp before incrementing tempdir_count, so that
tmpdirp = &cleanup_list.tempdir_list[cleanup_list.tempdir_count];
/* Initialize *tmpdirp before incrementing tempdir_count, so that
/* Create the temporary directory. */
xtemplate = (char *) xmalloca (PATH_MAX);
if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
{
error (0, errno,
/* Create the temporary directory. */
xtemplate = (char *) xmalloca (PATH_MAX);
if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
{
error (0, errno,
Should be called before the file ABSOLUTE_FILE_NAME is created. */
void
register_temp_file (struct temp_dir *dir,
Should be called before the file ABSOLUTE_FILE_NAME is created. */
void
register_temp_file (struct temp_dir *dir,
Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
void
unregister_temp_file (struct temp_dir *dir,
Should be called when the file ABSOLUTE_FILE_NAME could not be created. */
void
unregister_temp_file (struct temp_dir *dir,
Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
void
register_temp_subdir (struct temp_dir *dir,
Should be called before the subdirectory ABSOLUTE_DIR_NAME is created. */
void
register_temp_subdir (struct temp_dir *dir,
Return 0 upon success, or -1 if there was some problem. */
int
cleanup_temp_file (struct temp_dir *dir,
Return 0 upon success, or -1 if there was some problem. */
int
cleanup_temp_file (struct temp_dir *dir,
Return 0 upon success, or -1 if there was some problem. */
int
cleanup_temp_subdir (struct temp_dir *dir,
Return 0 upon success, or -1 if there was some problem. */
int
cleanup_temp_subdir (struct temp_dir *dir,
- /* Remove cleanup_list.tempdir_list[i]. */
- if (i + 1 == cleanup_list.tempdir_count)
- {
- while (i > 0 && cleanup_list.tempdir_list[i - 1] == NULL)
- i--;
- cleanup_list.tempdir_count = i;
- }
- else
- cleanup_list.tempdir_list[i] = NULL;
- /* Now only we can free the tmpdir->dirname and tmpdir itself. */
- free (tmpdir->dirname);
- free (tmpdir);
- return err;
+ /* Remove cleanup_list.tempdir_list[i]. */
+ if (i + 1 == cleanup_list.tempdir_count)
+ {
+ while (i > 0 && cleanup_list.tempdir_list[i - 1] == NULL)
+ i--;
+ cleanup_list.tempdir_count = i;
+ }
+ else
+ cleanup_list.tempdir_list[i] = NULL;
+ /* Now only we can free the tmpdir->dirname, tmpdir->subdirs,
+ tmpdir->files, and tmpdir itself. */
+ gl_list_free (tmpdir->files);
+ gl_list_free (tmpdir->subdirs);
+ free (tmpdir->dirname);
+ free (tmpdir);
+ return err;
{
if (descriptors == NULL)
descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL,
{
if (descriptors == NULL)
descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL,