2010-01-11 Eric Blake <ebb9@byu.net>
+ unistd: warn on use of environ without module
+ * modules/unistd (Depends-on): Add warn-on-use.
+ (Makefile.am): Provide new substitutions.
+ * m4/unistd_h.m4 (gl_UNISTD_H): Check for inline and environ.
+ * lib/unistd.in.h (environ): Wrap with a warning helper function.
+
stdio: warn on suspicious uses
* modules/stdio (Depends-on): Add warn-on-use.
(Makefile.am): Provide new substitutions.
/* The definition of _GL_ARG_NONNULL is copied here. */
+/* The definition of _GL_WARN_ON_USE is copied here. */
+
/* OS/2 EMX lacks these macros. */
#ifndef STDIN_FILENO
# endif
# endif
#elif defined GNULIB_POSIXCHECK
-# undef environ
-# define environ \
- (GL_LINK_WARNING ("environ is unportable - " \
- "use gnulib module environ for portability"), \
- environ)
+# if HAVE_RAW_DECL_ENVIRON
+static inline char ***
+rpl_environ (void)
+{
+ return &environ;
+}
+_GL_WARN_ON_USE (rpl_environ, "environ is unportable - "
+ "use gnulib module environ for portability");
+# undef environ
+# define environ (*rpl_environ ())
+# endif
#endif
-# unistd_h.m4 serial 37
+# unistd_h.m4 serial 38
dnl Copyright (C) 2006-2010 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl Use AC_REQUIRE here, so that the default behavior below is expanded
dnl once only, before all statements that occur in other macros.
AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
+ AC_REQUIRE([AC_C_INLINE])
gl_CHECK_NEXT_HEADERS([unistd.h])
HAVE_UNISTD_H=0
fi
AC_SUBST([HAVE_UNISTD_H])
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use.
+ gl_WARN_ON_USE_PREPARE([[#include <unistd.h>
+/* Some systems declare environ in the wrong header. */
+#ifndef __GLIBC__
+# include <stdlib.h>
+#endif
+ ]], [environ])
])
AC_DEFUN([gl_UNISTD_MODULE_INDICATOR],
lib/unistd.in.h
Depends-on:
+arg-nonnull
include_next
link-warning
-arg-nonnull
stddef
+warn-on-use
configure.ac:
gl_UNISTD_H
# We need the following in order to create an empty placeholder for
# <unistd.h> when the system doesn't have one.
-unistd.h: unistd.in.h $(LINK_WARNING_H) $(ARG_NONNULL_H)
+unistd.h: unistd.in.h $(LINK_WARNING_H) $(WARN_ON_USE_H) $(ARG_NONNULL_H)
$(AM_V_GEN)rm -f $@-t $@ && \
{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
sed -e 's|@''HAVE_UNISTD_H''@|$(HAVE_UNISTD_H)|g' \
-e 's|@''UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS''@|$(UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS)|g' \
-e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
-e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
< $(srcdir)/unistd.in.h; \
} > $@-t && \
mv $@-t $@