canonicalize, canonicalize-lgpl: use <stdlib.h>
authorEric Blake <ebb9@byu.net>
Fri, 11 Sep 2009 18:18:10 +0000 (12:18 -0600)
committerEric Blake <ebb9@byu.net>
Fri, 18 Sep 2009 01:16:24 +0000 (19:16 -0600)
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 <stdlib.h>.
(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 <stdlib.h>.

Signed-off-by: Eric Blake <ebb9@byu.net>
13 files changed:
ChangeLog
NEWS
doc/glibc-functions/canonicalize_file_name.texi
doc/posix-functions/realpath.texi
lib/canonicalize-lgpl.c
lib/canonicalize.h
lib/stdlib.in.h
m4/canonicalize-lgpl.m4
m4/stdlib_h.m4
modules/canonicalize
modules/canonicalize-lgpl
modules/stdlib
tests/test-canonicalize-lgpl.c

index 301d756..1d89bb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,23 @@
 2009-09-17  Eric Blake  <ebb9@byu.net>
 
+       canonicalize, canonicalize-lgpl: use <stdlib.h>
+       * modules/canonicalize-lgpl (Files): Drop canonicalize.h.
+       (Include): Mention <stdlib.h>.
+       (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 <stdlib.h>.
+
        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 f506cba..62c631f 100644 (file)
--- 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 <stdlib.h>.
+
 2009-09-04  link-follow     The macro LINK_FOLLOWS_SYMLINK is now tri-state,
                             rather than only defined to 1.
 
index c19a9b1..f034f81 100644 (file)
@@ -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
index 2515254..01ce781 100644 (file)
@@ -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.
index ce52cbc..c8f7e16 100644 (file)
 
 #include <config.h>
 
-/* Avoid a clash of our rpl_realpath() function with the prototype in
-   <stdlib.h> on Solaris 2.5.1.  */
-#undef realpath
-
 #if !HAVE_CANONICALIZE_FILE_NAME || defined _LIBC
 
 #include <alloca.h>
 
 /* Specification.  */
-#include "canonicalize.h"
+#include <stdlib.h>
 
 #include <stddef.h>
-#include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
 
@@ -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
index e068c20..bcf84f6 100644 (file)
@@ -17,7 +17,8 @@
 #ifndef CANONICALIZE_H_
 # define CANONICALIZE_H_
 
-# if GNULIB_CANONICALIZE
+#include <stdlib.h> /* 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 <stdlib.h>
-# 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_ */
index f05962e..a6512c5 100644 (file)
@@ -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.
index bd3a381..d040c68 100644 (file)
@@ -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
 ])
index b7cf18c..8cb5d48 100644 (file)
@@ -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])
 ])
index ec94c76..d039854 100644 (file)
@@ -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:
 
index 45a9a43..c5ecd4f 100644 (file)
@@ -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"
+<stdlib.h>
 
 License:
 LGPLv2+
index 507a8f6..c404ca2 100644 (file)
@@ -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)' \
index bc58d59..704c0ec 100644 (file)
 
 #include <config.h>
 
-#include "canonicalize.h"
+#include <stdlib.h>
 
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
-#include <stdlib.h>
 #include <string.h>
 #include <sys/stat.h>
 #include <unistd.h>