New module 'alphasort'.
authorBruno Haible <bruno@clisp.org>
Sun, 18 Jan 2009 11:40:22 +0000 (12:40 +0100)
committerBruno Haible <bruno@clisp.org>
Sun, 18 Jan 2009 11:40:22 +0000 (12:40 +0100)
ChangeLog
doc/posix-functions/alphasort.texi
lib/alphasort.c [new file with mode: 0644]
lib/dirent.in.h
m4/alphasort.m4 [new file with mode: 0644]
m4/dirent_h.m4
modules/alphasort [new file with mode: 0644]
modules/dirent

index fd7c3d9de0097dea134a0632989d569add0a1fc6..d9b6b253d9f7e1e1d2a9fc58d47cf012fe3fac89 100644 (file)
--- 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'.
index 2d2a02b6834c791a2b7fcb92ed66939f1c813eaf..ba7f5cb3492d8e4dbbf92d39e3c37fb3f332e009 100644 (file)
@@ -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
diff --git a/lib/alphasort.c b/lib/alphasort.c
new file mode 100644 (file)
index 0000000..041a7b3
--- /dev/null
@@ -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);
+}
index 40824c56b7bb1702003e14b63be291d8a74821b6..15f0245b0929efa68b39f57123ae1e9ba2daf0d9 100644 (file)
@@ -76,6 +76,19 @@ extern int scandir (const char *dir, struct dirent ***namelist,
      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
diff --git a/m4/alphasort.m4 b/m4/alphasort.m4
new file mode 100644 (file)
index 0000000..149129d
--- /dev/null
@@ -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], [:])
index 38cc118474c66b8d20430ad30f31f8df7627473b..e507e3de8c80c25dff857cc926c6b494aa90f20e 100644 (file)
@@ -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_MODULE_INDICATOR],
 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])
 ])
diff --git a/modules/alphasort b/modules/alphasort
new file mode 100644 (file)
index 0000000..319eccc
--- /dev/null
@@ -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
+
index cfe36ceae94de31ae6c1ca671e028cef24c2d5df..ca784f844aa9fc7f4f67732fab6c9bf02fa14f6d 100644 (file)
@@ -26,8 +26,10 @@ dirent.h: dirent.in.h
              -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; \