+2006-04-09 Bruno Haible <bruno@clisp.org>
+
+ * clean-temp.h: New file.
+ * clean-temp.c: New file.
+ * Makefile.am (libgettextlib_la_SOURCES): Add them.
+ * Makefile.msvc (OBJECTS): Add clean-temp.obj.
+ (clean-temp.obj): New rule.
+ * Makefile.vms (OBJECTS): Add clean-temp.obj.
+ (clean-temp.obj): New rule.
+
2006-04-09 Bruno Haible <bruno@clisp.org>
* fatal-signal.c: Don't include string.h.
c-strcase.h c-strcasecmp.c c-strncasecmp.c \
c-strcasestr.h c-strcasestr.c \
classpath.h classpath.c \
+ clean-temp.h clean-temp.c \
closeout.h closeout.c \
copy-file.h copy-file.c \
csharpcomp.h csharpcomp.c \
c-strcasecmp.obj \
c-strncasecmp.obj \
classpath.obj \
+ clean-temp.obj \
closeout.obj \
copy-file.obj \
csharpcomp.obj \
classpath.obj : classpath.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c classpath.c
+clean-temp.obj : clean-temp.c
+ $(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c clean-temp.c
+
closeout.obj : closeout.c
$(CC) $(INCLUDES) $(CFLAGS) $(PICFLAGS) -c closeout.c
c-strcasecmp.obj, \
c-strncasecmp.obj, \
classpath.obj, \
+ clean-temp.obj, \
closeout.obj, \
copy-file.obj, \
csharpcomp.obj, \
classpath.obj : classpath.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) classpath.c
+clean-temp.obj : clean-temp.c
+ $(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) clean-temp.c
+
closeout.obj : closeout.c
$(CC) $(INCLUDES) $(CFLAGS) /define=($(DEFS)) closeout.c
+2006-04-09 Bruno Haible <bruno@clisp.org>
+
+ * write-csharp.c: Include clean-temp.h. Don't include unistd.h,
+ mkdtemp.h, tmpdir.h, pathmax.h, fatal-signal.h, xallocsa.h.
+ (cleanup_list): Remove variable.
+ (cleanup): Remove function.
+ (msgdomain_write_csharp): Simplify handling of temporary directory.
+ * write-java.c: Include clean-temp.h. Don't include unistd.h,
+ mkdtemp.h, tmpdir.h, pathmax.h, fatal-signal.h.
+ (cleanup_list): Remove variable.
+ (cleanup): Remove function.
+ (msgdomain_write_java): Simplify handling of temporary directory.
+
2006-04-03 Bruno Haible <bruno@clisp.org>
* x-glade.c (p_XML_GetCurrentLineNumber, p_XML_GetCurrentColumnNumber):
/* Writing C# satellite assemblies.
- Copyright (C) 2003-2005 Free Software Foundation, Inc.
+ Copyright (C) 2003-2006 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2003.
This program is free software; you can redistribute it and/or modify
# define S_IXOTH (S_IXUSR >> 6)
#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
#ifdef __MINGW32__
/* mingw's mkdir() function has 1 argument, but we pass 2 arguments.
Therefore we have to disable the argument count checking. */
#include "xerror.h"
#include "csharpcomp.h"
#include "message.h"
-#include "mkdtemp.h"
#include "msgfmt.h"
#include "msgl-iconv.h"
-#include "pathmax.h"
#include "plural-exp.h"
#include "po-charset.h"
#include "xalloc.h"
-#include "xallocsa.h"
#include "pathname.h"
-#include "fatal-signal.h"
#include "fwriteerror.h"
-#include "tmpdir.h"
+#include "clean-temp.h"
#include "utf8-ucs4.h"
#include "gettext.h"
}
-/* Asynchronously cleaning up temporary files, when we receive any of the
- usually occurring signals whose default action is to terminate the
- program. */
-
-static struct
-{
- const char *tmpdir;
- const char *file_name;
-} cleanup_list;
-
-/* The signal handler. It gets called asynchronously. */
-static void
-cleanup ()
-{
- /* First cleanup the files in the subdirectory. */
- {
- const char *filename = cleanup_list.file_name;
-
- if (filename != NULL)
- unlink (filename);
- }
-
- /* Then cleanup the main temporary directory. */
- {
- const char *filename = cleanup_list.tmpdir;
-
- if (filename != NULL)
- rmdir (filename);
- }
-}
-
-
int
msgdomain_write_csharp (message_list_ty *mlp, const char *canon_encoding,
const char *resource_name, const char *locale_name,
const char *directory)
{
int retval;
- char *template;
- char *tmpdir;
+ struct temp_dir *tmpdir;
char *culture_name;
char *output_file;
char *class_name;
/* Convert the messages to Unicode. */
iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
- cleanup_list.tmpdir = NULL;
- cleanup_list.file_name = NULL;
- {
- static bool cleanup_already_registered = false;
- if (!cleanup_already_registered)
- {
- at_fatal_signal (&cleanup);
- cleanup_already_registered = true;
- }
- }
-
/* Create a temporary directory where we can put the C# file.
A simple temporary file would also be possible but would require us to
define our own variant of mkstemp(): On one hand the functions mktemp(),
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. */
- template = (char *) xallocsa (PATH_MAX);
- if (path_search (template, PATH_MAX, NULL, "msg", 1))
- {
- error (0, errno,
- _("cannot find a temporary directory, try setting $TMPDIR"));
- goto quit1;
- }
- block_fatal_signals ();
- tmpdir = mkdtemp (template);
- cleanup_list.tmpdir = tmpdir;
- unblock_fatal_signals ();
+ tmpdir = create_temp_dir ("msg");
if (tmpdir == NULL)
- {
- error (0, errno,
- _("cannot create a temporary directory using template \"%s\""),
- template);
- goto quit1;
- }
+ goto quit1;
/* Assign a default value to the resource name. */
if (resource_name == NULL)
culture_name = xstrdup ("uz-UZ-Latn");
}
}
-
/* Compute the output file name. This code must be kept consistent with
intl.cs, function GetSatelliteAssembly(). */
{
error (0, errno, _("failed to create directory \"%s\""), output_dir);
free (output_dir);
- goto quit3;
+ goto quit2;
}
output_file =
/* Compute the temporary C# file name. It must end in ".cs", so that
the C# compiler recognizes that it is C# source code. */
- csharp_file_name = concatenated_pathname (tmpdir, "resset.cs", NULL);
+ csharp_file_name =
+ concatenated_pathname (tmpdir->dir_name, "resset.cs", NULL);
/* Create the C# file. */
- cleanup_list.file_name = csharp_file_name;
+ enqueue_temp_file (tmpdir, csharp_file_name);
csharp_file = fopen (csharp_file_name, "w");
if (csharp_file == NULL)
{
error (0, errno, _("failed to create \"%s\""), csharp_file_name);
- goto quit4;
+ dequeue_temp_file (tmpdir, csharp_file_name);
+ goto quit3;
}
write_csharp_code (csharp_file, culture_name, class_name, mlp);
{
error (0, errno, _("error while writing \"%s\" file"), csharp_file_name);
fclose (csharp_file);
- goto quit5;
+ goto quit3;
}
/* Make it possible to override the .dll location. This is
output_file, true, false, verbose))
{
error (0, 0, _("compilation of C# class failed, please try --verbose"));
- goto quit5;
+ goto quit3;
}
retval = 0;
- quit5:
- unlink (csharp_file_name);
- quit4:
- cleanup_list.file_name = NULL;
+ quit3:
free (csharp_file_name);
free (class_name);
free (output_file);
- quit3:
+ quit2:
free (culture_name);
- rmdir (tmpdir);
+ cleanup_temp_dir (tmpdir);
quit1:
- cleanup_list.tmpdir = NULL;
- freesa (template);
- /* Here we could unregister the cleanup() handler. */
return retval;
}
/* Writing Java ResourceBundles.
- Copyright (C) 2001-2003, 2005 Free Software Foundation, Inc.
+ Copyright (C) 2001-2003, 2005-2006 Free Software Foundation, Inc.
Written by Bruno Haible <haible@clisp.cons.org>, 2001.
This program is free software; you can redistribute it and/or modify
# define S_IXUSR 00100
#endif
-#if HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
#ifdef __MINGW32__
/* mingw's mkdir() function has 1 argument, but we pass 2 arguments.
Therefore we have to disable the argument count checking. */
#include "xerror.h"
#include "javacomp.h"
#include "message.h"
-#include "mkdtemp.h"
#include "msgfmt.h"
#include "msgl-iconv.h"
-#include "pathmax.h"
#include "plural-exp.h"
#include "po-charset.h"
#include "xalloc.h"
#include "xallocsa.h"
#include "pathname.h"
-#include "fatal-signal.h"
#include "fwriteerror.h"
-#include "tmpdir.h"
+#include "clean-temp.h"
#include "utf8-ucs4.h"
#include "gettext.h"
}
-/* Asynchronously cleaning up temporary files, when we receive any of the
- usually occurring signals whose default action is to terminate the
- program. */
-
-static struct
-{
- const char *tmpdir;
- unsigned int subdir_count;
- const char * const *subdir;
- const char *file_name;
-} cleanup_list;
-
-/* The signal handler. It gets called asynchronously. */
-static void
-cleanup ()
-{
- unsigned int i;
-
- /* First cleanup the files in the subdirectory. */
- {
- const char *filename = cleanup_list.file_name;
-
- if (filename != NULL)
- unlink (filename);
- }
-
- /* Then cleanup the subdirectories. */
- for (i = cleanup_list.subdir_count; i > 0; )
- {
- const char *filename = cleanup_list.subdir[--i];
-
- rmdir (filename);
- }
-
- /* Then cleanup the main temporary directory. */
- {
- const char *filename = cleanup_list.tmpdir;
-
- if (filename != NULL)
- rmdir (filename);
- }
-}
-
-
int
msgdomain_write_java (message_list_ty *mlp, const char *canon_encoding,
const char *resource_name, const char *locale_name,
bool assume_java2)
{
int retval;
- char *template;
- char *tmpdir;
+ struct temp_dir *tmpdir;
int ndots;
char *class_name;
char **subdirs;
/* Convert the messages to Unicode. */
iconv_message_list (mlp, canon_encoding, po_charset_utf8, NULL);
- cleanup_list.tmpdir = NULL;
- cleanup_list.subdir_count = 0;
- cleanup_list.file_name = NULL;
- {
- static bool cleanup_already_registered = false;
- if (!cleanup_already_registered)
- {
- at_fatal_signal (&cleanup);
- cleanup_already_registered = true;
- }
- }
-
/* Create a temporary directory where we can put the Java file. */
- template = (char *) xallocsa (PATH_MAX);
- if (path_search (template, PATH_MAX, NULL, "msg", 1))
- {
- error (0, errno,
- _("cannot find a temporary directory, try setting $TMPDIR"));
- goto quit1;
- }
- block_fatal_signals ();
- tmpdir = mkdtemp (template);
- cleanup_list.tmpdir = tmpdir;
- unblock_fatal_signals ();
+ tmpdir = create_temp_dir ("msg");
if (tmpdir == NULL)
- {
- error (0, errno,
- _("cannot create a temporary directory using template \"%s\""),
- template);
- goto quit1;
- }
+ goto quit1;
/* Assign a default value to the resource name. */
if (resource_name == NULL)
const char *last_dir;
int i;
- last_dir = tmpdir;
+ last_dir = tmpdir->dir_name;
p = resource_name;
for (i = 0; i < ndots; i++)
{
{
int i;
- cleanup_list.subdir = (const char * const *) subdirs;
- cleanup_list.subdir_count = 0;
for (i = 0; i < ndots; i++)
{
- cleanup_list.subdir_count = i + 1;
+ enqueue_temp_subdir (tmpdir, subdirs[i]);
if (mkdir (subdirs[i], S_IRUSR | S_IWUSR | S_IXUSR) < 0)
{
error (0, errno, _("failed to create \"%s\""), subdirs[i]);
- while (i-- > 0)
- rmdir (subdirs[i]);
+ dequeue_temp_subdir (tmpdir, subdirs[i]);
goto quit3;
}
}
}
/* Create the Java file. */
- cleanup_list.file_name = java_file_name;
+ enqueue_temp_file (tmpdir, java_file_name);
java_file = fopen (java_file_name, "w");
if (java_file == NULL)
{
error (0, errno, _("failed to create \"%s\""), java_file_name);
- goto quit4;
+ dequeue_temp_file (tmpdir, java_file_name);
+ goto quit3;
}
write_java_code (java_file, class_name, mlp, assume_java2);
{
error (0, errno, _("error while writing \"%s\" file"), java_file_name);
fclose (java_file);
- goto quit5;
+ goto quit3;
}
/* Compile the Java file to a .class file.
{
error (0, 0, _("\
compilation of Java class failed, please try --verbose or set $JAVAC"));
- goto quit5;
+ goto quit3;
}
retval = 0;
- quit5:
- unlink (java_file_name);
- quit4:
- cleanup_list.file_name = NULL;
- {
- int i;
- for (i = ndots; i-- > 0; )
- rmdir (subdirs[i]);
- }
quit3:
- cleanup_list.subdir_count = 0;
{
int i;
free (java_file_name);
freesa (subdirs);
free (class_name);
quit2:
- rmdir (tmpdir);
+ cleanup_temp_dir (tmpdir);
quit1:
- cleanup_list.tmpdir = NULL;
- freesa (template);
- /* Here we could unregister the cleanup() handler. */
return retval;
}