]> git.ipfire.org Git - thirdparty/gettext.git/commitdiff
Always check the setenv() return value.
authorBruno Haible <bruno@clisp.org>
Wed, 2 Jan 2002 11:09:56 +0000 (11:09 +0000)
committerBruno Haible <bruno@clisp.org>
Sun, 21 Jun 2009 22:30:00 +0000 (00:30 +0200)
lib/ChangeLog
lib/Makefile.am
lib/classpath.c
lib/javacomp.c
lib/javaexec.c
lib/xsetenv.c [new file with mode: 0644]
lib/xsetenv.h [new file with mode: 0644]
src/ChangeLog
src/msgexec.c
src/msginit.c

index 05fa3cd1cee0c5c00c786195bf34707c9ae16e09..ddc8919c517dd6de4da52d7fe7313f57065f3d13 100644 (file)
@@ -1,3 +1,13 @@
+2001-12-23  Bruno Haible  <bruno@clisp.org>
+
+       * xsetenv.h: New file.
+       * xsetenv.c: New file.
+       * Makefile.am (libgettextlib_la_SOURCES): Add them.
+       * classpath.c (set_classpath): Use xsetenv instead of setenv.
+       (reset_classpath): Likewise.
+       * javacomp.c (compile_java_class): Likewise.
+       * javaexec.c (execute_java_class): Likewise.
+
 2001-12-23  Bruno Haible  <bruno@clisp.org>
 
        * Makefile.am (libgettextlib_la_SOURCES): Add the contents of
index 0bcdf72dd08bf4fa9c128a3d90e422bc56ed189b..95ae48def8d68218dc9d087096e63b290b6ebecc 100644 (file)
@@ -54,7 +54,8 @@ libgettextlib_la_SOURCES = \
   tmpdir.h tmpdir.c \
   wait-process.h wait-process.c \
   xerror.h xerror.c \
-  xmalloc.h xmalloc.c xstrdup.c
+  xmalloc.h xmalloc.c xstrdup.c \
+  xsetenv.h xsetenv.c
 
 # Sources that are compiled only on platforms that lack the functions.
 
index 05fb45a761739c0d366e20dd780298c80ecf67a7..949702a21ccabde0ac80d78927d88287c2c9a32b 100644 (file)
@@ -104,7 +104,7 @@ set_classpath (classpaths, classpaths_count, use_minimal_classpath, verbose)
   if (verbose)
     printf ("CLASSPATH=%s ", new_CLASSPATH);
 
-  setenv ("CLASSPATH", new_CLASSPATH, 1);
+  xsetenv ("CLASSPATH", new_CLASSPATH, 1);
 
   free (new_CLASSPATH);
 
@@ -118,7 +118,7 @@ reset_classpath (old_classpath)
 {
   if (old_classpath != NULL)
     {
-      setenv ("CLASSPATH", old_classpath, 1);
+      xsetenv ("CLASSPATH", old_classpath, 1);
       free (old_classpath);
     }
   else
index 5f1f51fc8d5122891e65174edafb666ef332fe98..858296bbdfaa5698666b20fe520c363bf3422a72 100644 (file)
@@ -31,7 +31,7 @@
 #include "execute.h"
 #include "pipe.h"
 #include "wait-process.h"
-#include "setenv.h"
+#include "xsetenv.h"
 #include "sh-quote.h"
 #include "safe-read.h"
 #include "xmalloc.h"
@@ -443,7 +443,7 @@ compile_java_class (java_sources, java_sources_count,
  done2:
   if (old_JAVA_HOME != NULL)
     {
-      setenv ("JAVA_HOME", old_JAVA_HOME, 1);
+      xsetenv ("JAVA_HOME", old_JAVA_HOME, 1);
       free (old_JAVA_HOME);
     }
 
index d2a595e2920d8f17a5467856123c7f00fa9a1352..fd11f5c9385fe2da0ad934c37c08c38c99b72d92 100644 (file)
@@ -29,7 +29,7 @@
 #include <string.h>
 
 #include "execute.h"
-#include "setenv.h"
+#include "xsetenv.h"
 #include "sh-quote.h"
 #include "xmalloc.h"
 #include "error.h"
@@ -382,7 +382,7 @@ execute_java_class (class_name,
  done2:
   if (old_JAVA_HOME != NULL)
     {
-      setenv ("JAVA_HOME", old_JAVA_HOME, 1);
+      xsetenv ("JAVA_HOME", old_JAVA_HOME, 1);
       free (old_JAVA_HOME);
     }
 
diff --git a/lib/xsetenv.c b/lib/xsetenv.c
new file mode 100644 (file)
index 0000000..f20d1a9
--- /dev/null
@@ -0,0 +1,44 @@
+/* Setting environment variables, with out-of-memory checking.
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+/* Specification.  */
+#include "xsetenv.h"
+
+#include "setenv.h"
+#include "error.h"
+#include "exit.h"
+#include "gettext.h"
+
+#define _(str) gettext (str)
+
+
+/* Set NAME to VALUE in the environment.
+   If REPLACE is nonzero, overwrite an existing value.
+   With error checking.  */
+void
+xsetenv (name, value, replace)
+     const char *name;
+     const char *value;
+     int replace;
+{
+  if (setenv (name, value, replace) < 0)
+    error (EXIT_FAILURE, 0, _("memory exhausted"));
+}
diff --git a/lib/xsetenv.h b/lib/xsetenv.h
new file mode 100644 (file)
index 0000000..20f4b69
--- /dev/null
@@ -0,0 +1,24 @@
+/* Setting environment variables, with out-of-memory checking.
+   Copyright (C) 2001 Free Software Foundation, Inc.
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, write to the Free Software Foundation,
+   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
+
+/* Get unsetenv().  It can be used without error checking.  */
+#include "setenv.h"
+
+/* Set NAME to VALUE in the environment.
+   If REPLACE is nonzero, overwrite an existing value.
+   With error checking.  */
+extern void xsetenv PARAMS ((const char *name, const char *value, int replace));
index 1b38169833d28ffac70e288dd34888fba8c15032..8abc5374207ac8348ac1c18c6a5f65f3bb689b3b 100644 (file)
@@ -1,3 +1,9 @@
+2001-12-23  Bruno Haible  <bruno@clisp.org>
+
+       * msgexec.c (process_string): Use xsetenv instead of setenv.
+       * msginit.c (canonical_locale_charset): Likewise.
+       (get_title): Likewise.
+
 2001-12-22  Bruno Haible  <bruno@clisp.org>
 
        * dir-list.c: Include <stddef.h> instead of <stdlib.h>.
index 7dbdae91f66af3d637396654e1c1858e12ad9ce4..7e02bdb4b9fe6c149075eab301bacbc974b6e788 100644 (file)
@@ -46,7 +46,7 @@
 #include "findprog.h"
 #include "pipe.h"
 #include "wait-process.h"
-#include "setenv.h"
+#include "xsetenv.h"
 #include "gettext.h"
 
 #define _(str) gettext (str)
@@ -321,10 +321,10 @@ process_string (mp, str, len)
       int exitstatus;
 
       /* Set environment variables for the subprocess.  */
-      setenv ("MSGEXEC_MSGID", mp->msgid, 1);
+      xsetenv ("MSGEXEC_MSGID", mp->msgid, 1);
       location = xasprintf ("%s:%ld", mp->pos.file_name,
                            (long) mp->pos.line_number);
-      setenv ("MSGEXEC_LOCATION", location, 1);
+      xsetenv ("MSGEXEC_LOCATION", location, 1);
       free (location);
 
       /* Open a pipe to a subprocess.  */
index f999765d5a3481af27fc8698bd57655d6c3fc736..83ffb1ef956a98bf5126bb19da8d05d788544901 100644 (file)
@@ -82,7 +82,7 @@
 #include "pipe.h"
 #include "wait-process.h"
 #include "getline.h"
-#include "setenv.h"
+#include "xsetenv.h"
 #include "str-list.h"
 #include "gettext.h"
 
@@ -648,7 +648,7 @@ canonical_locale_charset ()
   tmp = getenv ("LC_ALL");
   old_LC_ALL = (tmp != NULL ? xstrdup (tmp) : NULL);
 
-  setenv ("LC_ALL", locale, 1);
+  xsetenv ("LC_ALL", locale, 1);
 
 #ifdef HAVE_SETLOCALE
   if (setlocale (LC_ALL, "") == NULL)
@@ -662,7 +662,7 @@ canonical_locale_charset ()
   /* Restore LC_ALL environment variable.  */
 
   if (old_LC_ALL != NULL)
-    setenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL);
+    xsetenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL);
   else
     unsetenv ("LC_ALL");
 
@@ -1439,9 +1439,9 @@ get_title ()
   tmp = getenv ("OUTPUT_CHARSET");
   old_OUTPUT_CHARSET = (tmp != NULL ? xstrdup (tmp) : NULL);
 
-  setenv ("LC_ALL", locale, 1);
+  xsetenv ("LC_ALL", locale, 1);
   unsetenv ("LANGUAGE");
-  setenv ("OUTPUT_CHARSET", encoding, 1);
+  xsetenv ("OUTPUT_CHARSET", encoding, 1);
 
 #ifdef HAVE_SETLOCALE
   if (setlocale (LC_ALL, "") == NULL)
@@ -1467,17 +1467,17 @@ get_title ()
   /* Restore LC_ALL, LANGUAGE, OUTPUT_CHARSET environment variables.  */
 
   if (old_LC_ALL != NULL)
-    setenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL);
+    xsetenv ("LC_ALL", old_LC_ALL, 1), free (old_LC_ALL);
   else
     unsetenv ("LC_ALL");
 
   if (old_LANGUAGE != NULL)
-    setenv ("LANGUAGE", old_LANGUAGE, 1), free (old_LANGUAGE);
+    xsetenv ("LANGUAGE", old_LANGUAGE, 1), free (old_LANGUAGE);
   else
     unsetenv ("LANGUAGE");
 
   if (old_OUTPUT_CHARSET != NULL)
-    setenv ("OUTPUT_CHARSET", old_OUTPUT_CHARSET, 1), free (old_OUTPUT_CHARSET);
+    xsetenv ("OUTPUT_CHARSET", old_OUTPUT_CHARSET, 1), free (old_OUTPUT_CHARSET);
   else
     unsetenv ("OUTPUT_CHARSET");