changeset 11039:8842f30244d1

New module 'alphasort'.
author Bruno Haible <bruno@clisp.org>
date Sun, 18 Jan 2009 12:40:22 +0100
parents 6c37790abb93
children cee1ca4b9566
files ChangeLog doc/posix-functions/alphasort.texi lib/alphasort.c lib/dirent.in.h m4/alphasort.m4 m4/dirent_h.m4 modules/alphasort modules/dirent
diffstat 8 files changed, 120 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2009-01-18  Bruno Haible  <bruno@clisp.org>
+
+	New module 'alphasort'.
+	* lib/dirent.in.h (alphasort): New declaration.
+	* lib/alphasort.c: New file, from glibc with modifications.
+	* m4/alphasort.m4: New file.
+	* modules/alphasort: New file.
+	* m4/dirent_h.m4 (gl_DIRENT_H_DEFAULTS): Initialize GNULIB_ALPHASORT,
+	HAVE_ALPHASORT.
+	* modules/dirent (Makefile.am): Substitute GNULIB_ALPHASORT,
+	HAVE_ALPHASORT.
+	* doc/posix-functions/alphasort.texi: Mention the new module and the
+	portability problems.
+
 2009-01-18  Bruno Haible  <bruno@clisp.org>
 
 	New module 'scandir'.
--- a/doc/posix-functions/alphasort.texi
+++ b/doc/posix-functions/alphasort.texi
@@ -4,15 +4,21 @@
 
 POSIX specification: @url{http://www.opengroup.org/onlinepubs/9699919799/functions/alphasort.html}
 
-Gnulib module: ---
+Gnulib module: alphasort
 
 Portability problems fixed by Gnulib:
 @itemize
+@item
+This function is missing on some platforms:
+Solaris 9, mingw, BeOS.
 @end itemize
 
 Portability problems not fixed by Gnulib:
 @itemize
 @item
-This function is missing on some platforms:
-Solaris 9, mingw, BeOS.
+The parameters of this function are declared as @code{const void *} on some platforms:
+glibc 2.3.6, MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, Interix 3.5.
+@item
+The parameters of this function are declared as @code{void *} on some platforms:
+AIX 5.1.
 @end itemize
new file mode 100644
--- /dev/null
+++ b/lib/alphasort.c
@@ -0,0 +1,28 @@
+/* Copyright (C) 1992, 1997, 1998, 2009 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 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#include <config.h>
+
+#include <dirent.h>
+
+#include <string.h>
+
+int
+alphasort (const struct dirent **a, const struct dirent **b)
+{
+  return strcoll ((*a)->d_name, (*b)->d_name);
+}
--- a/lib/dirent.in.h
+++ b/lib/dirent.in.h
@@ -76,6 +76,19 @@
      scandir (d, n, f, c))
 #endif
 
+#if @GNULIB_ALPHASORT@
+/* Compare two 'struct dirent' entries alphabetically.  */
+# if !@HAVE_ALPHASORT@
+extern int alphasort (const struct dirent **, const struct dirent **);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef alphasort
+# define alphasort(a,b) \
+    (GL_LINK_WARNING ("alphasort is unportable - " \
+                      "use gnulib module alphasort for portability"), \
+     alphasort (a, b))
+#endif
+
 #ifdef __cplusplus
 }
 #endif
new file mode 100644
--- /dev/null
+++ b/m4/alphasort.m4
@@ -0,0 +1,23 @@
+# alphasort.m4 serial 1
+dnl Copyright (C) 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,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_ALPHASORT],
+[
+  AC_REQUIRE([gl_DIRENT_H_DEFAULTS])
+
+  dnl Persuade glibc and Solaris <dirent.h> to declare alphasort().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS([alphasort])
+  if test $ac_cv_func_alphasort = no; then
+    HAVE_ALPHASORT=0
+    AC_LIBOBJ([alphasort])
+    gl_PREREQ_ALPHASORT
+  fi
+])
+
+# Prerequisites of lib/alphasort.c.
+AC_DEFUN([gl_PREREQ_ALPHASORT], [:])
--- a/m4/dirent_h.m4
+++ b/m4/dirent_h.m4
@@ -1,4 +1,4 @@
-# dirent_h.m4 serial 3
+# dirent_h.m4 serial 4
 dnl Copyright (C) 2008-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,
@@ -32,10 +32,12 @@
 AC_DEFUN([gl_DIRENT_H_DEFAULTS],
 [
   AC_REQUIRE([gl_UNISTD_H_DEFAULTS]) dnl for REPLACE_FCHDIR
-  GNULIB_DIRFD=0;    AC_SUBST([GNULIB_DIRFD])
-  GNULIB_SCANDIR=0;  AC_SUBST([GNULIB_SCANDIR])
+  GNULIB_DIRFD=0;     AC_SUBST([GNULIB_DIRFD])
+  GNULIB_SCANDIR=0;   AC_SUBST([GNULIB_SCANDIR])
+  GNULIB_ALPHASORT=0; AC_SUBST([GNULIB_ALPHASORT])
   dnl Assume proper GNU behavior unless another module says otherwise.
   HAVE_DECL_DIRFD=1; AC_SUBST([HAVE_DECL_DIRFD])
   HAVE_SCANDIR=1;    AC_SUBST([HAVE_SCANDIR])
+  HAVE_ALPHASORT=1;  AC_SUBST([HAVE_ALPHASORT])
   DIRENT_H='';       AC_SUBST([DIRENT_H])
 ])
new file mode 100644
--- /dev/null
+++ b/modules/alphasort
@@ -0,0 +1,26 @@
+Description:
+alphasort() function: compare entries of a directory alphabetically
+
+Files:
+lib/alphasort.c
+m4/alphasort.m4
+
+Depends-on:
+dirent
+extensions
+
+configure.ac:
+gl_FUNC_ALPHASORT
+gl_DIRENT_MODULE_INDICATOR([alphasort])
+
+Makefile.am:
+
+Include:
+<dirent.h>
+
+License:
+LGPL
+
+Maintainer:
+all, glibc
+
--- a/modules/dirent
+++ b/modules/dirent
@@ -26,8 +26,10 @@
 	      -e 's|@''NEXT_DIRENT_H''@|$(NEXT_DIRENT_H)|g' \
 	      -e 's|@''GNULIB_DIRFD''@|$(GNULIB_DIRFD)|g' \
 	      -e 's|@''GNULIB_SCANDIR''@|$(GNULIB_SCANDIR)|g' \
+	      -e 's|@''GNULIB_ALPHASORT''@|$(GNULIB_ALPHASORT)|g' \
 	      -e 's|@''HAVE_DECL_DIRFD''@|$(HAVE_DECL_DIRFD)|g' \
 	      -e 's|@''HAVE_SCANDIR''@|$(HAVE_SCANDIR)|g' \
+	      -e 's|@''HAVE_ALPHASORT''@|$(HAVE_ALPHASORT)|g' \
 	      -e 's|@''REPLACE_FCHDIR''@|$(REPLACE_FCHDIR)|g' \
 	      -e '/definition of GL_LINK_WARNING/r $(LINK_WARNING_H)' \
 	      < $(srcdir)/dirent.in.h; \