Mercurial > hg > octave-lyh > gnulib-hg
changeset 7415:66b32599c835
Return an error indicator.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Fri, 06 Oct 2006 21:37:28 +0000 |
parents | 368fbbd8e59d |
children | 0350284ebb9c |
files | lib/ChangeLog lib/clean-temp.c lib/clean-temp.h |
diffstat | 3 files changed, 72 insertions(+), 32 deletions(-) [+] |
line wrap: on
line diff
--- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,3 +1,13 @@ +2006-10-06 Bruno Haible <bruno@clisp.org> + + * clean-temp.h (cleanup_temp_file, cleanup_temp_subdir, + cleanup_temp_dir_contents, cleanup_temp_dir): Change return type to + int. + * clean-temp.c (do_unlink, do_rmdir, cleanup_temp_file, + cleanup_temp_subdir, cleanup_temp_dir_contents, cleanup_temp_dir): + Return an error indicator. + Suggested by Eric Blake. + 2006-10-06 Bruno Haible <bruno@clisp.org> * clean-temp.c (PATH_MAX): Provide a fallback for GNU Hurd.
--- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -408,48 +408,70 @@ } } -/* Remove a file, with optional error message. */ -static void +/* Remove a file, with optional error message. + Return 0 upon success, or -1 if there was some problem. */ +static int do_unlink (struct temp_dir *dir, const char *absolute_file_name) { if (unlink (absolute_file_name) < 0 && dir->cleanup_verbose && errno != ENOENT) - error (0, errno, _("cannot remove temporary file %s"), absolute_file_name); + { + error (0, errno, _("cannot remove temporary file %s"), absolute_file_name); + return -1; + } + return 0; } -/* Remove a directory, with optional error message. */ -static void +/* Remove a directory, with optional error message. + Return 0 upon success, or -1 if there was some problem. */ +static int do_rmdir (struct temp_dir *dir, const char *absolute_dir_name) { if (rmdir (absolute_dir_name) < 0 && dir->cleanup_verbose && errno != ENOENT) - error (0, errno, - _("cannot remove temporary directory %s"), absolute_dir_name); + { + error (0, errno, + _("cannot remove temporary directory %s"), absolute_dir_name); + return -1; + } + return 0; } -/* Remove the given ABSOLUTE_FILE_NAME and unregister it. */ -void +/* Remove the given ABSOLUTE_FILE_NAME and unregister it. + Return 0 upon success, or -1 if there was some problem. */ +int cleanup_temp_file (struct temp_dir *dir, const char *absolute_file_name) { - do_unlink (dir, absolute_file_name); + int err; + + err = do_unlink (dir, absolute_file_name); unregister_temp_file (dir, absolute_file_name); + + return err; } -/* Remove the given ABSOLUTE_DIR_NAME and unregister it. */ -void +/* Remove the given ABSOLUTE_DIR_NAME and unregister it. + Return 0 upon success, or -1 if there was some problem. */ +int cleanup_temp_subdir (struct temp_dir *dir, const char *absolute_dir_name) { - do_rmdir (dir, absolute_dir_name); + int err; + + err = do_rmdir (dir, absolute_dir_name); unregister_temp_subdir (dir, absolute_dir_name); + + return err; } -/* Remove all registered files and subdirectories inside DIR. */ -void +/* Remove all registered files and subdirectories inside DIR. + Return 0 upon success, or -1 if there was some problem. */ +int cleanup_temp_dir_contents (struct temp_dir *dir) { struct tempdir *tmpdir = (struct tempdir *)dir; + int err = 0; gl_list_t list; gl_list_iterator_t iter; const void *element; @@ -462,7 +484,7 @@ { char *file = (char *) element; - do_unlink (dir, file); + err |= do_unlink (dir, file); gl_list_remove_node (list, node); /* Now only we can free file. */ free (file); @@ -476,24 +498,28 @@ { char *subdir = (char *) element; - do_rmdir (dir, subdir); + err |= do_rmdir (dir, subdir); gl_list_remove_node (list, node); /* Now only we can free subdir. */ free (subdir); } gl_list_iterator_free (&iter); + + return err; } /* Remove all registered files and subdirectories inside DIR and DIR itself. - DIR cannot be used any more after this call. */ -void + DIR cannot be used any more after this call. + Return 0 upon success, or -1 if there was some problem. */ +int cleanup_temp_dir (struct temp_dir *dir) { struct tempdir *tmpdir = (struct tempdir *)dir; + int err = 0; size_t i; - cleanup_temp_dir_contents (dir); - do_rmdir (dir, tmpdir->dirname); + err |= cleanup_temp_dir_contents (dir); + err |= do_rmdir (dir, tmpdir->dirname); for (i = 0; i < cleanup_list.tempdir_count; i++) if (cleanup_list.tempdir_list[i] == tmpdir) @@ -510,7 +536,7 @@ /* Now only we can free the tmpdir->dirname and tmpdir itself. */ free (tmpdir->dirname); free (tmpdir); - return; + return err; } /* The user passed an invalid DIR argument. */
--- a/lib/clean-temp.h +++ b/lib/clean-temp.h @@ -89,20 +89,24 @@ extern void unregister_temp_subdir (struct temp_dir *dir, const char *absolute_dir_name); -/* Remove the given ABSOLUTE_FILE_NAME and unregister it. */ -extern void cleanup_temp_file (struct temp_dir *dir, - const char *absolute_file_name); +/* Remove the given ABSOLUTE_FILE_NAME and unregister it. + Return 0 upon success, or -1 if there was some problem. */ +extern int cleanup_temp_file (struct temp_dir *dir, + const char *absolute_file_name); -/* Remove the given ABSOLUTE_DIR_NAME and unregister it. */ -extern void cleanup_temp_subdir (struct temp_dir *dir, - const char *absolute_dir_name); +/* Remove the given ABSOLUTE_DIR_NAME and unregister it. + Return 0 upon success, or -1 if there was some problem. */ +extern int cleanup_temp_subdir (struct temp_dir *dir, + const char *absolute_dir_name); -/* Remove all registered files and subdirectories inside DIR. */ -extern void cleanup_temp_dir_contents (struct temp_dir *dir); +/* Remove all registered files and subdirectories inside DIR. + Return 0 upon success, or -1 if there was some problem. */ +extern int cleanup_temp_dir_contents (struct temp_dir *dir); /* Remove all registered files and subdirectories inside DIR and DIR itself. - DIR cannot be used any more after this call. */ -extern void cleanup_temp_dir (struct temp_dir *dir); + DIR cannot be used any more after this call. + Return 0 upon success, or -1 if there was some problem. */ +extern int cleanup_temp_dir (struct temp_dir *dir); /* Open a temporary file in a temporary directory. Registers the resulting file descriptor to be closed. */