[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
setenv, unsetenv fixes
From: |
Bruno Haible |
Subject: |
setenv, unsetenv fixes |
Date: |
Wed, 26 Dec 2007 16:21:29 +0100 |
User-agent: |
KMail/1.5.4 |
Hi,
It was reported in [1] that there is a conflict between the unsetenv()
declarations on MacOS X and in gnulib under some conditions. The error message
is this:
In file included from ../gnulib-lib/relocwrapper.c:56:
../gnulib-lib/setenv.h:47: error: conflicting types for `unsetenv'
/usr/include/stdlib.h:248: error: previous declaration of `unsetenv'
This occurs in a package that uses the setenv() function but not the
unsetenv() function. setenv.h contains the declaration of unsetenv, but
since gl_FUNC_UNSETENV has not been called, HAVE_UNSETENV is not set; this
leads to the error.
The fix is to use a @GNULIB_UNSETENV@ macro. While at it, I also
- move the declaration to <stdlib.h>, getting rid of setenv.h,
- update the documentation about unsetenv,
- split the module into a 'setenv' module and an 'unsetenv' module.
This is a backward-incompatible change; please see the NEWS entry.
2007-12-24 Bruno Haible <address@hidden>
Split setenv module into setenv and unsetenv. Get rid of setenv.h.
* lib/setenv.h: Remove file.
* lib/stdlib.in.h (setenv, unsetenv): New declarations, moved here from
lib/setenv.h.
* modules/setenv (Files): Remove lib/setenv.h, lib/unsetenv.c.
(Depends-on): Add stdlib.
(configure.ac): Invoke gl_STDLIB_MODULE_INDICATOR. Don't invoke
gl_FUNC_UNSETENV.
(Include): Replace setenv.h with <stdlib.h>.
* modules/unsetenv: New file.
* lib/setenv.c: Include <stdlib.h> first, after alloca.h.
* lib/unsetenv.c: Include <stdlib.h> first.
* m4/setenv.m4 (gl_FUNC_SETENV, gl_FUNC_SETENV_SEPARATE): Require
gl_STDLIB_H_DEFAULTS. Conditionally set HAVE_SETENV to 0.
(gl_FUNC_UNSETENV): Require gl_STDLIB_H_DEFAULTS. Conditionally set
HAVE_UNSETENV to 0. Set VOID_UNSETENV as an AC_SUBSTed variable.
* modules/stdlib (Makefile.am): Substitute also GNULIB_SETENV,
HAVE_SETENV, GNULIB_UNSETENV, HAVE_UNSETENV, VOID_UNSETENV.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_SETENV,
HAVE_SETENV, GNULIB_UNSETENV, HAVE_UNSETENV, VOID_UNSETENV.
* doc/functions/unsetenv.texi: Update.
* modules/xsetenv (Depends-on): Add unsetenv.
* modules/getdate (Depends-on): Likewise.
* lib/xsetenv.h: Include <stdlib.h> instead of setenv.h.
* lib/xsetenv.c: Don't include setenv.h.
* lib/getdate.y: Likewise.
* lib/relocwrapper.c: Likewise.
* modules/relocatable-prog-wrapper (Files): Remove lib/setenv.h.
(Depends-on): Add stdlib.
* NEWS: Mention the changes.
Reported by Левашев Иван <address@hidden>.
*** NEWS.orig 2007-12-24 22:46:29.000000000 +0100
--- NEWS 2007-12-24 20:50:38.000000000 +0100
***************
*** 6,11 ****
--- 6,16 ----
Date Modules Changes
+ 2007-12-24 setenv The include file is changed from "setenv.h" to
+ <stdlib.h>. Also, the unsetenv function is no
+ longer declared in this module; use the 'unsetenv'
+ module if you need it.
+
2007-12-03 getpagesize The include file is changed from "getpagesize.h"
to <unistd.h>.
*** doc/functions/unsetenv.texi.orig 2007-12-24 22:46:29.000000000 +0100
--- doc/functions/unsetenv.texi 2007-12-24 22:33:48.000000000 +0100
***************
*** 11,21 ****
@item
This function is missing on some platforms:
AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, mingw, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
- @item
- This function has the return type @samp{void} instead of @samp{int} on some
- platforms.
@end itemize
--- 11,22 ----
@item
This function is missing on some platforms:
AIX 5.1, HP-UX 11, IRIX 6.5, Solaris 9, mingw, BeOS.
+ @item
+ This function has the return type @samp{void} instead of @samp{int} on some
+ platforms:
+ MacOS X 10.3, FreeBSD 6.0, NetBSD 1.6, OpenBSD 3.8, OSF/1 5.1.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
@end itemize
*** lib/getdate.y.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/getdate.y 2007-12-24 21:12:22.000000000 +0100
***************
*** 66,72 ****
#include <stdlib.h>
#include <string.h>
- #include "setenv.h"
#include "xalloc.h"
--- 66,71 ----
*** lib/relocwrapper.c.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/relocwrapper.c 2007-12-24 21:12:40.000000000 +0100
***************
*** 53,59 ****
#include "progname.h"
#include "relocatable.h"
- #include "setenv.h"
#include "c-ctype.h"
/* Return a copy of the filename, with an extra ".bin" at the end.
--- 53,58 ----
*** lib/setenv.c.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/setenv.c 2007-12-24 20:51:48.000000000 +0100
***************
*** 19,30 ****
#endif
#include <alloca.h>
#include <errno.h>
#ifndef __set_errno
# define __set_errno(ev) ((errno) = (ev))
#endif
- #include <stdlib.h>
#include <string.h>
#if _LIBC || HAVE_UNISTD_H
# include <unistd.h>
--- 19,32 ----
#endif
#include <alloca.h>
+ /* Specification. */
+ #include <stdlib.h>
+
#include <errno.h>
#ifndef __set_errno
# define __set_errno(ev) ((errno) = (ev))
#endif
#include <string.h>
#if _LIBC || HAVE_UNISTD_H
# include <unistd.h>
*** lib/stdlib.in.h.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/stdlib.in.h 2007-12-24 20:46:23.000000000 +0100
***************
*** 1,6 ****
/* A GNU-like <stdlib.h>.
! Copyright (C) 1995, 2001-2002, 2006-2007 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
--- 1,6 ----
/* A GNU-like <stdlib.h>.
! Copyright (C) 1995, 2001-2004, 2006-2007 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
***************
*** 176,181 ****
--- 176,204 ----
#endif
+ #if @GNULIB_SETENV@
+ # if address@hidden@
+ /* Set NAME to VALUE in the environment.
+ If REPLACE is nonzero, overwrite an existing value. */
+ extern int setenv (const char *name, const char *value, int replace);
+ # endif
+ #endif
+
+
+ #if @GNULIB_UNSETENV@
+ # if @HAVE_UNSETENV@
+ # if @VOID_UNSETENV@
+ /* On some systems, unsetenv() returns void.
+ This is the case for MacOS X 10.3, FreeBSD 4.8, NetBSD 1.6, OpenBSD 3.4.
*/
+ # define unsetenv(name) ((unsetenv)(name), 0)
+ # endif
+ # else
+ /* Remove the variable NAME from the environment. */
+ extern int unsetenv (const char *name);
+ # endif
+ #endif
+
+
#ifdef __cplusplus
}
#endif
*** lib/unsetenv.c.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/unsetenv.c 2007-12-24 20:52:18.000000000 +0100
***************
*** 1,4 ****
! /* Copyright (C) 1992,1995-1999,2000-2002,2005-2006 Free Software Foundation,
Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
--- 1,4 ----
! /* Copyright (C) 1992,1995-1999,2000-2002,2005-2007 Free Software Foundation,
Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
***************
*** 16,27 ****
#include <config.h>
#include <errno.h>
#if !_LIBC
# define __set_errno(ev) ((errno) = (ev))
#endif
- #include <stdlib.h>
#include <string.h>
#include <unistd.h>
--- 16,29 ----
#include <config.h>
+ /* Specification. */
+ #include <stdlib.h>
+
#include <errno.h>
#if !_LIBC
# define __set_errno(ev) ((errno) = (ev))
#endif
#include <string.h>
#include <unistd.h>
*** lib/xsetenv.c.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/xsetenv.c 2007-12-24 21:12:55.000000000 +0100
***************
*** 21,27 ****
#include <stdlib.h>
- #include "setenv.h"
#include "error.h"
#include "gettext.h"
--- 21,26 ----
*** lib/xsetenv.h.orig 2007-12-24 22:46:29.000000000 +0100
--- lib/xsetenv.h 2007-12-24 21:13:22.000000000 +0100
***************
*** 15,21 ****
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Get unsetenv(). It can be used without error checking. */
! #include "setenv.h"
#ifdef __cplusplus
extern "C" {
--- 15,21 ----
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* Get unsetenv(). It can be used without error checking. */
! #include <stdlib.h>
#ifdef __cplusplus
extern "C" {
*** m4/setenv.m4.orig 2007-12-24 22:46:29.000000000 +0100
--- m4/setenv.m4 2007-12-24 21:05:01.000000000 +0100
***************
*** 1,4 ****
! # setenv.m4 serial 8
dnl Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
--- 1,4 ----
! # setenv.m4 serial 9
dnl Copyright (C) 2001-2004, 2006-2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
***************
*** 6,13 ****
--- 6,15 ----
AC_DEFUN([gl_FUNC_SETENV],
[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_CHECK_FUNCS_ONCE([setenv])
if test $ac_cv_func_setenv = no; then
+ HAVE_SETENV=0
AC_LIBOBJ([setenv])
gl_PREREQ_SETENV
fi
***************
*** 16,29 ****
--- 18,37 ----
# Like gl_FUNC_SETENV, except prepare for separate compilation (no AC_LIBOBJ).
AC_DEFUN([gl_FUNC_SETENV_SEPARATE],
[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_CHECK_FUNCS_ONCE([setenv])
+ if test $ac_cv_func_setenv = no; then
+ HAVE_SETENV=0
+ fi
gl_PREREQ_SETENV
])
AC_DEFUN([gl_FUNC_UNSETENV],
[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_CHECK_FUNCS([unsetenv])
if test $ac_cv_func_unsetenv = no; then
+ HAVE_UNSETENV=0
AC_LIBOBJ([unsetenv])
gl_PREREQ_UNSETENV
else
***************
*** 40,46 ****
#endif
], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
if test $gt_cv_func_unsetenv_ret = 'void'; then
! AC_DEFINE(VOID_UNSETENV, 1, [Define if unsetenv() returns void, not
int.])
fi
fi
])
--- 48,54 ----
#endif
], , gt_cv_func_unsetenv_ret='int', gt_cv_func_unsetenv_ret='void')])
if test $gt_cv_func_unsetenv_ret = 'void'; then
! VOID_UNSETENV=1
fi
fi
])
*** m4/stdlib_h.m4.orig 2007-12-24 22:46:29.000000000 +0100
--- m4/stdlib_h.m4 2007-12-24 20:58:35.000000000 +0100
***************
*** 1,4 ****
! # stdlib_h.m4 serial 4
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
--- 1,4 ----
! # stdlib_h.m4 serial 5
dnl Copyright (C) 2007 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
***************
*** 26,37 ****
--- 26,42 ----
GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
+ GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
+ GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
dnl Assume proper GNU behavior unless another module says otherwise.
HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX])
HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
+ HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
+ HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV])
REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
+ VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV])
])
*** modules/getdate.orig 2007-12-24 22:46:29.000000000 +0100
--- modules/getdate 2007-12-24 21:17:57.000000000 +0100
***************
*** 15,20 ****
--- 15,21 ----
intprops
mktime
setenv
+ unsetenv
time
verify
xalloc
*** modules/relocatable-prog-wrapper.orig 2007-12-24 22:46:29.000000000
+0100
--- modules/relocatable-prog-wrapper 2007-12-24 21:00:40.000000000 +0100
***************
*** 19,25 ****
lib/malloca.c
lib/relocatable.h
lib/relocatable.c
- lib/setenv.h
lib/setenv.c
lib/strerror.c
lib/c-ctype.h
--- 19,24 ----
***************
*** 38,43 ****
--- 37,43 ----
pathmax
ssize_t
stdbool
+ stdlib
unistd
configure.ac:
*** modules/setenv.orig 2007-12-24 22:46:29.000000000 +0100
--- modules/setenv 2007-12-24 21:00:17.000000000 +0100
***************
*** 1,26 ****
Description:
setenv() function: set an environment variable.
- unsetenv() function: remove an environment variable.
Files:
- lib/setenv.h
lib/setenv.c
- lib/unsetenv.c
m4/setenv.m4
Depends-on:
malloca
alloca-opt
unistd
configure.ac:
gl_FUNC_SETENV
! gl_FUNC_UNSETENV
Makefile.am:
Include:
! "setenv.h"
License:
LGPL
--- 1,24 ----
Description:
setenv() function: set an environment variable.
Files:
lib/setenv.c
m4/setenv.m4
Depends-on:
+ stdlib
malloca
alloca-opt
unistd
configure.ac:
gl_FUNC_SETENV
! gl_STDLIB_MODULE_INDICATOR([setenv])
Makefile.am:
Include:
! <stdlib.h>
License:
LGPL
*** modules/stdlib.orig 2007-12-24 22:46:29.000000000 +0100
--- modules/stdlib 2007-12-24 20:56:50.000000000 +0100
***************
*** 30,42 ****
--- 30,47 ----
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
+ -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \
+ -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \
-e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \
-e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
-e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
-e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
-e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
+ -e 's|@''HAVE_SETENV''@|$(HAVE_SETENV)|g' \
+ -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
+ -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
< $(srcdir)/stdlib.in.h; \
} > address@hidden
*** modules/xsetenv.orig 2007-12-24 22:46:29.000000000 +0100
--- modules/xsetenv 2007-12-24 21:17:37.000000000 +0100
***************
*** 8,13 ****
--- 8,14 ----
Depends-on:
setenv
+ unsetenv
error
exit
gettext-h
*** /dev/null 2003-09-23 19:59:22.000000000 +0200
--- modules/unsetenv 2007-12-24 21:00:21.000000000 +0100
***************
*** 0 ****
--- 1,26 ----
+ Description:
+ unsetenv() function: remove an environment variable.
+
+ Files:
+ lib/unsetenv.c
+ m4/setenv.m4
+
+ Depends-on:
+ stdlib
+ unistd
+
+ configure.ac:
+ gl_FUNC_UNSETENV
+ gl_STDLIB_MODULE_INDICATOR([unsetenv])
+
+ Makefile.am:
+
+ Include:
+ <stdlib.h>
+
+ License:
+ LGPL
+
+ Maintainer:
+ Bruno Haible
+
[1] http://lists.gnu.org/archive/html/bug-gnu-utils/2007-12/msg00001.html
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- setenv, unsetenv fixes,
Bruno Haible <=