]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Add more parameters to create_temp_dir function.
authorBruno Haible <bruno@clisp.org>
Fri, 30 Jun 2006 14:43:55 +0000 (14:43 +0000)
committerBruno Haible <bruno@clisp.org>
Tue, 23 Jun 2009 10:13:28 +0000 (12:13 +0200)
gettext-tools/lib/ChangeLog
gettext-tools/lib/clean-temp.c
gettext-tools/lib/clean-temp.h
gettext-tools/lib/javacomp.c
gettext-tools/src/ChangeLog
gettext-tools/src/write-csharp.c
gettext-tools/src/write-java.c

index a8b044aefd3a9dffaebefa923638c6af312fcdd8..9264c1549fc98aed4fa75afc005e5bcd090b8f9c 100644 (file)
@@ -1,3 +1,18 @@
+2006-06-29  Bruno Haible  <bruno@clisp.org>
+
+       * clean-temp.h: Include <stdbool.h>.
+       (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  <bruno@clisp.org>
 
        Assume <dirent.h> on all Unix platforms. Assume closedir works.
index eb3ab413790e583b5d6fef92eebff9ea5b1bca05..557e8f865fcf148477ef3dc13208787587f6faa6 100644 (file)
@@ -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)
index 2d84e1693bb41be409a501d25f85f7ccc7ec7d48..e511c9c112a034502f1929337e90854aa3124b39 100644 (file)
@@ -19,6 +19,8 @@
 #ifndef _CLEAN_TEMP_H
 #define _CLEAN_TEMP_H
 
+#include <stdbool.h>
+
 #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.
index a6a31461560dd32cca0bbc4af7e5e3b2deeb530c..ee19b8951a1ef95735b8e51cb7aa3b60a11c8083 100644 (file)
@@ -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;
 
index cf2df682377142c2870ff16ed2e47be3cd5a235a..495f823b8c19279de42b0a415bd2ce1417b5ab2a 100644 (file)
@@ -1,3 +1,8 @@
+2006-06-29  Bruno Haible  <bruno@clisp.org>
+
+       * write-csharp.c (msgdomain_write_csharp): Update.
+       * write-java.c (msgdomain_write_java): Likewise.
+
 2006-06-28  Bruno Haible  <bruno@clisp.org>
 
        Assume <dirent.h> on all Unix platforms. Assume closedir works.
index 0511b18ba9bffce385b7724c71a2d5145fea49df..b2cf6bbd323de757ed32a4cb85763b6d1d1a7af1 100644 (file)
@@ -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;
 
index 43989cde2713b2c952c4d771e88cd224b8d06331..8b88ef40be53e063ad3ba740edb1000fefc78dd5 100644 (file)
@@ -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;