summaryrefslogtreecommitdiff
path: root/lib/clean-temp.c
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2009-12-10 20:28:30 +0100
committerBruno Haible <bruno@clisp.org>2009-12-10 20:28:30 +0100
commit441aa3044f43e5572f58c354f01e6bc070acd5c7 (patch)
treebef236e8058dd3469da28ffcd5a6a287222a4c50 /lib/clean-temp.c
parent039ae97b8ae35a2446c5d62d72b21689c97da7e2 (diff)
downloadgnulib-441aa3044f43e5572f58c354f01e6bc070acd5c7.tar.gz
Use spaces for indentation, not tabs.
Diffstat (limited to 'lib/clean-temp.c')
-rw-r--r--lib/clean-temp.c208
1 files changed, 104 insertions, 104 deletions
diff --git a/lib/clean-temp.c b/lib/clean-temp.c
index 283d8af236..99c81d1465 100644
--- a/lib/clean-temp.c
+++ b/lib/clean-temp.c
@@ -199,16 +199,16 @@ cleanup ()
if (fds != NULL)
{
- 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);
}
}
@@ -217,31 +217,31 @@ cleanup ()
struct tempdir *dir = cleanup_list.tempdir_list[i];
if (dir != NULL)
- {
- 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);
+ }
}
}
@@ -256,7 +256,7 @@ cleanup ()
is shown and NULL is returned. */
struct temp_dir *
create_temp_dir (const char *prefix, const char *parentdir,
- bool cleanup_verbose)
+ bool cleanup_verbose)
{
struct tempdir * volatile *tmpdirp = NULL;
struct tempdir *tmpdir;
@@ -269,47 +269,47 @@ create_temp_dir (const char *prefix, const char *parentdir,
for (i = 0; i < cleanup_list.tempdir_count; i++)
if (cleanup_list.tempdir_list[i] == NULL)
{
- tmpdirp = &cleanup_list.tempdir_list[i];
- break;
+ tmpdirp = &cleanup_list.tempdir_list[i];
+ break;
}
if (tmpdirp == NULL)
{
/* See whether the array needs to be extended. */
if (cleanup_list.tempdir_count == cleanup_list.tempdir_allocated)
- {
- /* 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
- cleanup() will skip this entry before it is fully initialized. */
+ cleanup() will skip this entry before it is fully initialized. */
*tmpdirp = NULL;
cleanup_list.tempdir_count++;
}
@@ -319,18 +319,18 @@ create_temp_dir (const char *prefix, const char *parentdir,
tmpdir->dirname = NULL;
tmpdir->cleanup_verbose = cleanup_verbose;
tmpdir->subdirs = gl_list_create_empty (GL_LINKEDHASH_LIST,
- string_equals, string_hash, NULL,
- false);
+ string_equals, string_hash, NULL,
+ false);
tmpdir->files = gl_list_create_empty (GL_LINKEDHASH_LIST,
- string_equals, string_hash, NULL,
- false);
+ string_equals, string_hash, NULL,
+ false);
/* Create the temporary directory. */
xtemplate = (char *) xmalloca (PATH_MAX);
if (path_search (xtemplate, PATH_MAX, parentdir, prefix, parentdir == NULL))
{
error (0, errno,
- _("cannot find a temporary directory, try setting $TMPDIR"));
+ _("cannot find a temporary directory, try setting $TMPDIR"));
goto quit;
}
block_fatal_signals ();
@@ -344,8 +344,8 @@ create_temp_dir (const char *prefix, const char *parentdir,
if (tmpdirname == NULL)
{
error (0, errno,
- _("cannot create a temporary directory using template \"%s\""),
- xtemplate);
+ _("cannot create a temporary directory using template \"%s\""),
+ xtemplate);
goto quit;
}
/* Replace tmpdir->dirname with a copy that has indefinite extent.
@@ -366,7 +366,7 @@ create_temp_dir (const char *prefix, const char *parentdir,
Should be called before the file ABSOLUTE_FILE_NAME is created. */
void
register_temp_file (struct temp_dir *dir,
- const char *absolute_file_name)
+ const char *absolute_file_name)
{
struct tempdir *tmpdir = (struct tempdir *)dir;
@@ -380,7 +380,7 @@ 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,
- const char *absolute_file_name)
+ const char *absolute_file_name)
{
struct tempdir *tmpdir = (struct tempdir *)dir;
gl_list_t list = tmpdir->files;
@@ -401,7 +401,7 @@ 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,
- const char *absolute_dir_name)
+ const char *absolute_dir_name)
{
struct tempdir *tmpdir = (struct tempdir *)dir;
@@ -416,7 +416,7 @@ register_temp_subdir (struct temp_dir *dir,
created. */
void
unregister_temp_subdir (struct temp_dir *dir,
- const char *absolute_dir_name)
+ const char *absolute_dir_name)
{
struct tempdir *tmpdir = (struct tempdir *)dir;
gl_list_t list = tmpdir->subdirs;
@@ -455,7 +455,7 @@ do_rmdir (struct temp_dir *dir, const char *absolute_dir_name)
&& errno != ENOENT)
{
error (0, errno,
- _("cannot remove temporary directory %s"), absolute_dir_name);
+ _("cannot remove temporary directory %s"), absolute_dir_name);
return -1;
}
return 0;
@@ -465,7 +465,7 @@ do_rmdir (struct temp_dir *dir, const char *absolute_dir_name)
Return 0 upon success, or -1 if there was some problem. */
int
cleanup_temp_file (struct temp_dir *dir,
- const char *absolute_file_name)
+ const char *absolute_file_name)
{
int err;
@@ -479,7 +479,7 @@ 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,
- const char *absolute_dir_name)
+ const char *absolute_dir_name)
{
int err;
@@ -548,19 +548,19 @@ cleanup_temp_dir (struct temp_dir *dir)
for (i = 0; i < cleanup_list.tempdir_count; i++)
if (cleanup_list.tempdir_list[i] == tmpdir)
{
- /* 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 and tmpdir itself. */
+ free (tmpdir->dirname);
+ free (tmpdir);
+ return err;
}
/* The user passed an invalid DIR argument. */
@@ -585,9 +585,9 @@ supports_delete_on_close ()
OSVERSIONINFO v;
if (GetVersionEx (&v))
- known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1);
+ known = (v.dwPlatformId == VER_PLATFORM_WIN32_NT ? 1 : -1);
else
- known = -1;
+ known = -1;
}
return (known > 0);
}
@@ -601,7 +601,7 @@ register_fd (int fd)
{
if (descriptors == NULL)
descriptors = gl_list_create_empty (GL_LINKEDHASH_LIST, NULL, NULL, NULL,
- false);
+ false);
gl_list_add_first (descriptors, (void *) (uintptr_t) fd);
}
@@ -682,11 +682,11 @@ fopen_temp (const char *file_name, const char *mode)
if (fp != NULL)
{
/* It is sufficient to register fileno (fp) instead of the entire fp,
- because at cleanup time there is no need to do an fflush (fp); a
- close (fileno (fp)) will be enough. */
+ because at cleanup time there is no need to do an fflush (fp); a
+ close (fileno (fp)) will be enough. */
int fd = fileno (fp);
if (!(fd >= 0))
- abort ();
+ abort ();
register_fd (fd);
}
unblock_fatal_signals ();
@@ -702,12 +702,12 @@ close_temp (int fd)
if (fd >= 0)
{
/* No blocking of signals is needed here, since a double close of a
- file descriptor is harmless. */
+ file descriptor is harmless. */
int result = close (fd);
int saved_errno = errno;
/* No race condition here: we assume a single-threaded program, hence
- fd cannot be re-opened here. */
+ fd cannot be re-opened here. */
unregister_fd (fd);