From 99ad8ac789556142ef090fcaefae36aabef00ca4 Mon Sep 17 00:00:00 2001 From: Eric Blake Date: Fri, 11 Sep 2009 12:18:10 -0600 Subject: [PATCH] canonicalize, canonicalize-lgpl: use Match current gnulib conventions of glibc functions being declared in the same header as glibc. This makes it easier to replace broken canonicalize_file_name. canonicalize still requires "canonicalize.h" because canonicalize_filename_mode is not in glibc. With this patch, canonicalize-lgpl always provides realpath and canonicalize_file_name, while canonicalize can provide canonicalize_file_name but not realpath; if both modules are in use, canonicalize_file_name comes from the LGPLv2+ sources, but the testing comes from canonicalize. * modules/canonicalize-lgpl (Files): Drop canonicalize.h. (Include): Mention . (configure.ac): Mention functions we provide. * modules/canonicalize (configure.ac): Likewise. * m4/canonicalize-lgpl.m4 (gl_CANONICALIZE_LGPL): Always replace realpath if canonicalize_file_name is missing. * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Provide defaults. * modules/stdlib (Makefile.am): Substitute witnesses. * lib/stdlib.in.h (canonicalize_file_name, realpath): Declare. * lib/canonicalize-lgpl.c (includes): Adjust accordingly. * lib/canonicalize.h (canonicalize_file_name): Drop declaration. * NEWS: Document this. * doc/glibc-functions/canonicalize_file_name.texi (canonicalize_file_name): Likewise. * doc/posix-functions/realpath.texi (realpath): Likewise. * tests/test-canonicalize-lgpl.c (includes): Use . Signed-off-by: Eric Blake --- ChangeLog | 18 ++++++++++++++++++ NEWS | 4 ++++ doc/glibc-functions/canonicalize_file_name.texi | 8 ++++---- doc/posix-functions/realpath.texi | 21 +++++++++++++-------- lib/canonicalize-lgpl.c | 9 ++------- lib/canonicalize.h | 15 ++------------- lib/stdlib.in.h | 25 +++++++++++++++++++++++++ m4/canonicalize-lgpl.m4 | 8 +++++--- m4/stdlib_h.m4 | 6 +++++- modules/canonicalize | 1 + modules/canonicalize-lgpl | 7 ++++--- modules/stdlib | 4 ++++ tests/test-canonicalize-lgpl.c | 3 +-- 13 files changed, 88 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 301d75624..1d89bb335 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,23 @@ 2009-09-17 Eric Blake + canonicalize, canonicalize-lgpl: use + * modules/canonicalize-lgpl (Files): Drop canonicalize.h. + (Include): Mention . + (configure.ac): Mention functions we provide. + * modules/canonicalize (configure.ac): Likewise. + * m4/canonicalize-lgpl.m4 (gl_CANONICALIZE_LGPL): Always replace + realpath if canonicalize_file_name is missing. + * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Provide defaults. + * modules/stdlib (Makefile.am): Substitute witnesses. + * lib/stdlib.in.h (canonicalize_file_name, realpath): Declare. + * lib/canonicalize-lgpl.c (includes): Adjust accordingly. + * lib/canonicalize.h (canonicalize_file_name): Drop declaration. + * NEWS: Document this. + * doc/glibc-functions/canonicalize_file_name.texi + (canonicalize_file_name): Likewise. + * doc/posix-functions/realpath.texi (realpath): Likewise. + * tests/test-canonicalize-lgpl.c (includes): Use . + test-canonicalize: consolidate into single C program * tests/test-canonicalize.sh: Delete; move setup into... * tests/test-canonicalize.c (main): ...the program, making it diff --git a/NEWS b/NEWS index f506cba99..62c631f1e 100644 --- a/NEWS +++ b/NEWS @@ -6,6 +6,10 @@ User visible incompatible changes Date Modules Changes +2009-09-16 canonicalize-lgpl + The include file is changed from "canonicalize.h" + to . + 2009-09-04 link-follow The macro LINK_FOLLOWS_SYMLINK is now tri-state, rather than only defined to 1. diff --git a/doc/glibc-functions/canonicalize_file_name.texi b/doc/glibc-functions/canonicalize_file_name.texi index c19a9b1d1..f034f8175 100644 --- a/doc/glibc-functions/canonicalize_file_name.texi +++ b/doc/glibc-functions/canonicalize_file_name.texi @@ -2,15 +2,15 @@ @subsection @code{canonicalize_file_name} @findex canonicalize_file_name -Gnulib module: --- +Gnulib module: canonicalize-lgpl Portability problems fixed by Gnulib: @itemize +@item +This function is missing on all non-glibc platforms: +MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on all non-glibc platforms: -MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS. @end itemize diff --git a/doc/posix-functions/realpath.texi b/doc/posix-functions/realpath.texi index 251525471..01ce781cf 100644 --- a/doc/posix-functions/realpath.texi +++ b/doc/posix-functions/realpath.texi @@ -4,22 +4,27 @@ POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/realpath.html} -Gnulib module: --- +Gnulib module: canonicalize-lgpl Portability problems fixed by Gnulib: @itemize +@item +This function is missing on some platforms: +mingw, BeOS. +@item +This function does not allow for a NULL @samp{resolved} parameter on +some platforms: +Solaris. +@item +This function does not always return an absolute path on some +platforms: +Solaris. @end itemize Portability problems not fixed by Gnulib: @itemize @item -This function is missing on some platforms: -mingw, BeOS. -@item This function does not allow to determine the required size of output buffer; +the use of a non-NULL @samp{resolved} buffer is non-portable, since PATH_MAX --- if it is defined --- is nothing more than a guess. @end itemize - -Extension: Gnulib provides a module @samp{canonicalize-lgpl} that defines a -function @code{canonicalize_file_name} that is like @code{realpath} but without -size limitations. diff --git a/lib/canonicalize-lgpl.c b/lib/canonicalize-lgpl.c index ce52cbc22..c8f7e167a 100644 --- a/lib/canonicalize-lgpl.c +++ b/lib/canonicalize-lgpl.c @@ -17,19 +17,14 @@ #include -/* Avoid a clash of our rpl_realpath() function with the prototype in - on Solaris 2.5.1. */ -#undef realpath - #if !HAVE_CANONICALIZE_FILE_NAME || defined _LIBC #include /* Specification. */ -#include "canonicalize.h" +#include #include -#include #include #include @@ -61,7 +56,7 @@ # define compat_symbol(lib, local, symbol, version) # define weak_alias(local, symbol) # define __canonicalize_file_name canonicalize_file_name -# define __realpath rpl_realpath +# define __realpath realpath # include "pathmax.h" # include "malloca.h" # if HAVE_GETCWD diff --git a/lib/canonicalize.h b/lib/canonicalize.h index e068c20ea..bcf84f6f9 100644 --- a/lib/canonicalize.h +++ b/lib/canonicalize.h @@ -17,7 +17,8 @@ #ifndef CANONICALIZE_H_ # define CANONICALIZE_H_ -# if GNULIB_CANONICALIZE +#include /* for canonicalize_file_name */ + enum canonicalize_mode_t { /* All components must exist. */ @@ -36,17 +37,5 @@ typedef enum canonicalize_mode_t canonicalize_mode_t; whether components must exist depends on the canonicalize_mode_t argument. */ char *canonicalize_filename_mode (const char *, canonicalize_mode_t); -# endif - -# if HAVE_CANONICALIZE_FILE_NAME -# include -# else -/* Return a malloc'd string containing the canonical absolute name of - the named file. If any file name component does not exist or is a - symlink to a nonexistent file, return NULL. A canonical name does - not contain any `.', `..' components nor any repeated file name - separators ('/') or symlinks. */ -char *canonicalize_file_name (const char *); -# endif #endif /* !CANONICALIZE_H_ */ diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index f05962ea5..a6512c59c 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -115,6 +115,18 @@ extern void * calloc (size_t nmemb, size_t size); calloc (n, s)) #endif +#if @GNULIB_CANONICALIZE_FILE_NAME@ +# if !@HAVE_CANONICALIZE_FILE_NAME@ +extern char *canonicalize_file_name (const char *name); +# endif +#elif defined GNULIB_POSIXCHECK +# undef canonicalize_file_name +# define canonicalize_file_name(n) \ + (GL_LINK_WARNING ("canonicalize_file_name is unportable - " \ + "use gnulib module canonicalize-lgpl for portability"), \ + canonicalize_file_name (n)) +#endif + #if @GNULIB_GETLOADAVG@ # if !@HAVE_DECL_GETLOADAVG@ /* Store max(NELEM,3) load average numbers in LOADAVG[]. @@ -292,6 +304,19 @@ extern void * realloc (void *ptr, size_t size); realloc (p, s)) #endif +#if @GNULIB_REALPATH@ +# if @REPLACE_REALPATH@ +# define realpath rpl_realpath +extern char *realpath (const char *name, char *resolved); +# endif +#elif defined GNULIB_POSIXCHECK +# undef realpath +# define realpath(n,r) \ + (GL_LINK_WARNING ("realpath is unportable - use gnulib module " \ + "canonicalize or canonicalize-lgpl for portability"), \ + realpath (n, r)) +#endif + #if @GNULIB_RPMATCH@ # if !@HAVE_RPMATCH@ /* Test a user response to a question. diff --git a/m4/canonicalize-lgpl.m4 b/m4/canonicalize-lgpl.m4 index bd3a38142..d040c6866 100644 --- a/m4/canonicalize-lgpl.m4 +++ b/m4/canonicalize-lgpl.m4 @@ -1,4 +1,4 @@ -# canonicalize-lgpl.m4 serial 6 +# canonicalize-lgpl.m4 serial 7 dnl Copyright (C) 2003, 2006-2007, 2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -10,10 +10,12 @@ AC_DEFUN([gl_CANONICALIZE_LGPL], dnl than the function name. AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) AC_CHECK_FUNCS_ONCE([canonicalize_file_name]) + dnl Assume that all platforms with canonicalize_file_name also have + dnl a working realpath; otherwise assume realpath is broken. if test $ac_cv_func_canonicalize_file_name = no; then + HAVE_CANONICALIZE_FILE_NAME=0 AC_LIBOBJ([canonicalize-lgpl]) - AC_DEFINE([realpath], [rpl_realpath], - [Define to a replacement function name for realpath().]) + REPLACE_REALPATH=1 gl_PREREQ_CANONICALIZE_LGPL fi ]) diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index b7cf18c3f..8cb5d484f 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 17 +# stdlib_h.m4 serial 18 dnl Copyright (C) 2007-2009 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -35,6 +35,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], [ GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL]) GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX]) + GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME]) GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG]) GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX]) @@ -44,6 +45,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV]) GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R]) GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX]) + GNULIB_REALPATH=0; AC_SUBST([GNULIB_REALPATH]) GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH]) GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV]) GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD]) @@ -53,6 +55,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], dnl Assume proper GNU behavior unless another module says otherwise. HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL]) HAVE_CALLOC_POSIX=1; AC_SUBST([HAVE_CALLOC_POSIX]) + HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME]) HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT]) HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX]) @@ -70,6 +73,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_UNSETENV=1; AC_SUBST([HAVE_UNSETENV]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) + REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH]) REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD]) VOID_UNSETENV=0; AC_SUBST([VOID_UNSETENV]) ]) diff --git a/modules/canonicalize b/modules/canonicalize index ec94c7670..d039854f1 100644 --- a/modules/canonicalize +++ b/modules/canonicalize @@ -22,6 +22,7 @@ xgetcwd configure.ac: gl_FUNC_CANONICALIZE_FILENAME_MODE gl_MODULE_INDICATOR([canonicalize]) +gl_STDLIB_MODULE_INDICATOR([canonicalize_file_name]) Makefile.am: diff --git a/modules/canonicalize-lgpl b/modules/canonicalize-lgpl index 45a9a432b..c5ecd4fd4 100644 --- a/modules/canonicalize-lgpl +++ b/modules/canonicalize-lgpl @@ -1,8 +1,7 @@ Description: -Canonical absolute file name (LGPLed version). +realpath, canonical_file_name: Provide canonical absolute file name Files: -lib/canonicalize.h lib/canonicalize-lgpl.c m4/canonicalize-lgpl.m4 @@ -21,11 +20,13 @@ sys_stat configure.ac: gl_CANONICALIZE_LGPL gl_MODULE_INDICATOR([canonicalize-lgpl]) +gl_STDLIB_MODULE_INDICATOR([canonicalize_file_name]) +gl_STDLIB_MODULE_INDICATOR([realpath]) Makefile.am: Include: -"canonicalize.h" + License: LGPLv2+ diff --git a/modules/stdlib b/modules/stdlib index 507a8f67a..c404ca26f 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -28,6 +28,7 @@ stdlib.h: stdlib.in.h -e 's|@''NEXT_STDLIB_H''@|$(NEXT_STDLIB_H)|g' \ -e 's|@''GNULIB_ATOLL''@|$(GNULIB_ATOLL)|g' \ -e 's|@''GNULIB_CALLOC_POSIX''@|$(GNULIB_CALLOC_POSIX)|g' \ + -e 's|@''GNULIB_CANONICALIZE_FILE_NAME''@|$(GNULIB_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \ -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ @@ -37,6 +38,7 @@ stdlib.h: stdlib.in.h -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \ -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \ -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \ + -e 's|@''GNULIB_REALPATH''@|$(GNULIB_REALPATH)|g' \ -e 's|@''GNULIB_RPMATCH''@|$(GNULIB_RPMATCH)|g' \ -e 's|@''GNULIB_SETENV''@|$(GNULIB_SETENV)|g' \ -e 's|@''GNULIB_STRTOD''@|$(GNULIB_STRTOD)|g' \ @@ -45,6 +47,7 @@ stdlib.h: stdlib.in.h -e 's|@''GNULIB_UNSETENV''@|$(GNULIB_UNSETENV)|g' \ -e 's|@''HAVE_ATOLL''@|$(HAVE_ATOLL)|g' \ -e 's|@''HAVE_CALLOC_POSIX''@|$(HAVE_CALLOC_POSIX)|g' \ + -e 's|@''HAVE_CANONICALIZE_FILE_NAME''@|$(HAVE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''HAVE_DECL_GETLOADAVG''@|$(HAVE_DECL_GETLOADAVG)|g' \ -e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \ -e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \ @@ -63,6 +66,7 @@ stdlib.h: stdlib.in.h -e 's|@''HAVE_UNSETENV''@|$(HAVE_UNSETENV)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ + -e 's|@''REPLACE_REALPATH''@|$(REPLACE_REALPATH)|g' \ -e 's|@''REPLACE_STRTOD''@|$(REPLACE_STRTOD)|g' \ -e 's|@''VOID_UNSETENV''@|$(VOID_UNSETENV)|g' \ -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \ diff --git a/tests/test-canonicalize-lgpl.c b/tests/test-canonicalize-lgpl.c index bc58d5904..704c0ecc5 100644 --- a/tests/test-canonicalize-lgpl.c +++ b/tests/test-canonicalize-lgpl.c @@ -18,12 +18,11 @@ #include -#include "canonicalize.h" +#include #include #include #include -#include #include #include #include -- 2.11.0