From: Bruno Haible Date: Fri, 30 Jun 2006 14:43:55 +0000 (+0000) Subject: Add more parameters to create_temp_dir function. X-Git-Tag: v0.15~58 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=214460c0a25957e1893dc186044e527415069784;p=thirdparty%2Fgettext.git Add more parameters to create_temp_dir function. --- diff --git a/gettext-tools/lib/ChangeLog b/gettext-tools/lib/ChangeLog index a8b044aef..9264c1549 100644 --- a/gettext-tools/lib/ChangeLog +++ b/gettext-tools/lib/ChangeLog @@ -1,3 +1,18 @@ +2006-06-29 Bruno Haible + + * clean-temp.h: Include . + (struct temp_dir): Add cleanup_verbose field. + (create_temp_dir): Add parentdir, cleanup_verbose arguments. + * clean-temp.c (struct tempdir): Add cleanup_verbose field. + (create_temp_dir): Add parentdir, cleanup_verbose arguments. + (do_unlink. do_rmdir): New functions. + (cleanup_temp_file, cleanup_temp_subdir, cleanup_temp_dir_contents, + cleanup_temp_dir): Use them. + * javacomp.c (is_envjavac_gcj_14_14_usable, + is_envjavac_gcj_14_13_usable, is_envjavac_nongcj_usable, + is_gcj_present, is_gcj_14_14_usable, is_gcj_14_13_usable, + is_javac_usable): Update. + 2006-06-28 Bruno Haible Assume on all Unix platforms. Assume closedir works. diff --git a/gettext-tools/lib/clean-temp.c b/gettext-tools/lib/clean-temp.c index eb3ab4137..557e8f865 100644 --- a/gettext-tools/lib/clean-temp.c +++ b/gettext-tools/lib/clean-temp.c @@ -53,6 +53,8 @@ struct tempdir { /* The absolute pathname of the directory. */ char * volatile dirname; + /* Whether errors during explicit cleanup are reported to standard error. */ + bool cleanup_verbose; /* Absolute pathnames of subdirectories. */ char * volatile * volatile subdir; size_t volatile subdir_count; @@ -116,10 +118,15 @@ cleanup () /* Create a temporary directory. PREFIX is used as a prefix for the name of the temporary directory. It should be short and still give an indication about the program. + PARENTDIR can be used to specify the parent directory; if NULL, a default + parent directory is used (either $TMPDIR or /tmp or similar). + CLEANUP_VERBOSE determines whether errors during explicit cleanup are + reported to standard error. Return a fresh 'struct temp_dir' on success. Upon error, an error message is shown and NULL is returned. */ struct temp_dir * -create_temp_dir (const char *prefix) +create_temp_dir (const char *prefix, const char *parentdir, + bool cleanup_verbose) { struct tempdir * volatile *tmpdirp = NULL; struct tempdir *tmpdir; @@ -178,9 +185,10 @@ create_temp_dir (const char *prefix) cleanup_list.tempdir_count++; } - /* Initialize a 'struct tmpdir'. */ + /* Initialize a 'struct tempdir'. */ tmpdir = (struct tempdir *) xmalloc (sizeof (struct tempdir)); tmpdir->dirname = NULL; + tmpdir->cleanup_verbose = cleanup_verbose; tmpdir->subdir = NULL; tmpdir->subdir_count = 0; tmpdir->subdir_allocated = 0; @@ -190,7 +198,7 @@ create_temp_dir (const char *prefix) /* Create the temporary directory. */ template = (char *) xallocsa (PATH_MAX); - if (path_search (template, PATH_MAX, NULL, prefix, true)) + if (path_search (template, PATH_MAX, parentdir, prefix, parentdir == NULL)) { error (0, errno, _("cannot find a temporary directory, try setting $TMPDIR")); @@ -380,12 +388,31 @@ dequeue_temp_subdir (struct temp_dir *dir, } } +/* Remove a file, with optional error message. */ +static void +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); +} + +/* Remove a directory, with optional error message. */ +static void +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); +} + /* Remove the given ABSOLUTE_FILE_NAME and unregister it. */ void cleanup_temp_file (struct temp_dir *dir, const char *absolute_file_name) { - unlink (absolute_file_name); + do_unlink (dir, absolute_file_name); dequeue_temp_file (dir, absolute_file_name); } @@ -394,7 +421,7 @@ void cleanup_temp_subdir (struct temp_dir *dir, const char *absolute_dir_name) { - rmdir (absolute_dir_name); + do_rmdir (dir, absolute_dir_name); dequeue_temp_subdir (dir, absolute_dir_name); } @@ -411,7 +438,7 @@ cleanup_temp_dir_contents (struct temp_dir *dir) { char *file = tmpdir->file[--j]; if (file != NULL) - unlink (file); + do_unlink (dir, file); tmpdir->file_count = j; /* Now only we can free file. */ if (file != NULL) @@ -426,7 +453,7 @@ cleanup_temp_dir_contents (struct temp_dir *dir) { char *subdir = tmpdir->subdir[--j]; if (subdir != NULL) - rmdir (subdir); + do_rmdir (dir, subdir); tmpdir->subdir_count = j; /* Now only we can free subdir. */ if (subdir != NULL) @@ -445,7 +472,7 @@ cleanup_temp_dir (struct temp_dir *dir) size_t i; cleanup_temp_dir_contents (dir); - rmdir (tmpdir->dirname); + do_rmdir (dir, tmpdir->dirname); for (i = 0; i < cleanup_list.tempdir_count; i++) if (cleanup_list.tempdir_list[i] == tmpdir) diff --git a/gettext-tools/lib/clean-temp.h b/gettext-tools/lib/clean-temp.h index 2d84e1693..e511c9c11 100644 --- a/gettext-tools/lib/clean-temp.h +++ b/gettext-tools/lib/clean-temp.h @@ -19,6 +19,8 @@ #ifndef _CLEAN_TEMP_H #define _CLEAN_TEMP_H +#include + #ifdef __cplusplus extern "C" { #endif @@ -38,15 +40,23 @@ struct temp_dir { /* The absolute pathname of the directory. */ const char * const dir_name; + /* Whether errors during explicit cleanup are reported to standard error. */ + bool cleanup_verbose; /* More fields are present here, but not public. */ }; /* Create a temporary directory. PREFIX is used as a prefix for the name of the temporary directory. It should be short and still give an indication about the program. + PARENTDIR can be used to specify the parent directory; if NULL, a default + parent directory is used (either $TMPDIR or /tmp or similar). + CLEANUP_VERBOSE determines whether errors during explicit cleanup are + reported to standard error. Return a fresh 'struct temp_dir' on success. Upon error, an error message is shown and NULL is returned. */ -extern struct temp_dir * create_temp_dir (const char *prefix); +extern struct temp_dir * create_temp_dir (const char *prefix, + const char *parentdir, + bool cleanup_verbose); /* Register the given ABSOLUTE_FILE_NAME as being a file inside DIR, that needs to be removed before DIR can be removed. diff --git a/gettext-tools/lib/javacomp.c b/gettext-tools/lib/javacomp.c index a6a314615..ee19b8951 100644 --- a/gettext-tools/lib/javacomp.c +++ b/gettext-tools/lib/javacomp.c @@ -606,7 +606,7 @@ is_envjavac_gcj_14_14_usable (const char *javac, bool *usablep) const char *java_sources[1]; struct stat statbuf; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; @@ -667,7 +667,7 @@ is_envjavac_gcj_14_13_usable (const char *javac, char *javac_noassert; bool javac_noassert_works; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; @@ -807,7 +807,7 @@ is_envjavac_nongcj_usable (const char *javac, const char *java_sources[1]; struct stat statbuf; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; @@ -1100,7 +1100,7 @@ is_gcj_present (void) /* See if libgcj.jar is well installed. */ struct temp_dir *tmpdir; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) gcj_present = false; else @@ -1164,7 +1164,7 @@ is_gcj_14_14_usable (bool *usablep) const char *java_sources[1]; struct stat statbuf; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; @@ -1221,7 +1221,7 @@ is_gcj_14_13_usable (bool *usablep, bool *need_no_assert_option_p) const char *java_sources[1]; struct stat statbuf; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; @@ -1328,7 +1328,7 @@ is_javac_usable (const char *source_version, const char *target_version, const char *java_sources[1]; struct stat statbuf; - tmpdir = create_temp_dir ("java"); + tmpdir = create_temp_dir ("java", NULL, false); if (tmpdir == NULL) return true; diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index cf2df6823..495f823b8 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,8 @@ +2006-06-29 Bruno Haible + + * write-csharp.c (msgdomain_write_csharp): Update. + * write-java.c (msgdomain_write_java): Likewise. + 2006-06-28 Bruno Haible Assume on all Unix platforms. Assume closedir works. diff --git a/gettext-tools/src/write-csharp.c b/gettext-tools/src/write-csharp.c index 0511b18ba..b2cf6bbd3 100644 --- a/gettext-tools/src/write-csharp.c +++ b/gettext-tools/src/write-csharp.c @@ -633,7 +633,7 @@ but the C# .dll format doesn't support contexts\n"))); tmpnam(), tempnam() present a security risk, and on the other hand the function mkstemp() doesn't allow to specify a fixed suffix of the file. It is simpler to create a temporary directory. */ - tmpdir = create_temp_dir ("msg"); + tmpdir = create_temp_dir ("msg", NULL, false); if (tmpdir == NULL) goto quit1; diff --git a/gettext-tools/src/write-java.c b/gettext-tools/src/write-java.c index 43989cde2..8b88ef40b 100644 --- a/gettext-tools/src/write-java.c +++ b/gettext-tools/src/write-java.c @@ -930,7 +930,7 @@ but the Java ResourceBundle format doesn't support contexts\n"))); iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL); /* Create a temporary directory where we can put the Java file. */ - tmpdir = create_temp_dir ("msg"); + tmpdir = create_temp_dir ("msg", NULL, false); if (tmpdir == NULL) goto quit1;