diff options
author | Bruno Haible <bruno@clisp.org> | 2002-01-02 11:09:56 +0000 |
---|---|---|
committer | Bruno Haible <bruno@clisp.org> | 2009-06-22 00:30:00 +0200 |
commit | 2926f7270c08f711ca01b5affe49aac7e69f1385 (patch) | |
tree | ef9ff87fd9a5e2d58260ac6cf921f2882e7ccc27 | |
parent | 3208bae8f288423491eb4936666763279d59aa8e (diff) | |
download | external_gettext-2926f7270c08f711ca01b5affe49aac7e69f1385.zip external_gettext-2926f7270c08f711ca01b5affe49aac7e69f1385.tar.gz external_gettext-2926f7270c08f711ca01b5affe49aac7e69f1385.tar.bz2 |
Always check the setenv() return value.
-rw-r--r-- | lib/ChangeLog | 10 | ||||
-rw-r--r-- | lib/Makefile.am | 3 | ||||
-rw-r--r-- | lib/classpath.c | 4 | ||||
-rw-r--r-- | lib/javacomp.c | 4 | ||||
-rw-r--r-- | lib/javaexec.c | 4 | ||||
-rw-r--r-- | lib/xsetenv.c | 44 | ||||
-rw-r--r-- | lib/xsetenv.h | 24 | ||||
-rw-r--r-- | src/ChangeLog | 6 | ||||
-rw-r--r-- | src/msgexec.c | 6 | ||||
-rw-r--r-- | src/msginit.c | 16 |
10 files changed, 103 insertions, 18 deletions
diff --git a/lib/ChangeLog b/lib/ChangeLog index 05fa3cd..ddc8919 100644 --- a/lib/ChangeLog +++ b/lib/ChangeLog @@ -1,5 +1,15 @@ 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 libgettextlib_la_HEADER, except liballoca.h. (LIBADD_SOURCE): Add the contents of LIBADD_HEADER, plus liballoca.h. diff --git a/lib/Makefile.am b/lib/Makefile.am index 0bcdf72..95ae48d 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -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. diff --git a/lib/classpath.c b/lib/classpath.c index 05fb45a..949702a 100644 --- a/lib/classpath.c +++ b/lib/classpath.c @@ -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 diff --git a/lib/javacomp.c b/lib/javacomp.c index 5f1f51f..858296b 100644 --- a/lib/javacomp.c +++ b/lib/javacomp.c @@ -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); } diff --git a/lib/javaexec.c b/lib/javaexec.c index d2a595e..fd11f5c 100644 --- a/lib/javaexec.c +++ b/lib/javaexec.c @@ -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 index 0000000..f20d1a9 --- /dev/null +++ b/lib/xsetenv.c @@ -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 index 0000000..20f4b69 --- /dev/null +++ b/lib/xsetenv.h @@ -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)); diff --git a/src/ChangeLog b/src/ChangeLog index 1b38169..8abc537 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -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>. diff --git a/src/msgexec.c b/src/msgexec.c index 7dbdae9..7e02bdb 100644 --- a/src/msgexec.c +++ b/src/msgexec.c @@ -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. */ diff --git a/src/msginit.c b/src/msginit.c index f999765..83ffb1e 100644 --- a/src/msginit.c +++ b/src/msginit.c @@ -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"); |