From 9d33c622ce10de9c68fdd84cb3b77c5b0a75fe02 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 18 Jan 2009 12:40:22 +0100 Subject: [PATCH] New module 'alphasort'. --- ChangeLog | 14 ++++++++++++++ doc/posix-functions/alphasort.texi | 12 +++++++++--- lib/alphasort.c | 28 ++++++++++++++++++++++++++++ lib/dirent.in.h | 13 +++++++++++++ m4/alphasort.m4 | 23 +++++++++++++++++++++++ m4/dirent_h.m4 | 8 +++++--- modules/alphasort | 26 ++++++++++++++++++++++++++ modules/dirent | 2 ++ 8 files changed, 120 insertions(+), 6 deletions(-) create mode 100644 lib/alphasort.c create mode 100644 m4/alphasort.m4 create mode 100644 modules/alphasort diff --git a/ChangeLog b/ChangeLog index fd7c3d9de0..d9b6b253d9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2009-01-18 Bruno Haible + + 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 New module 'scandir'. diff --git a/doc/posix-functions/alphasort.texi b/doc/posix-functions/alphasort.texi index 2d2a02b683..ba7f5cb349 100644 --- 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 diff --git a/lib/alphasort.c b/lib/alphasort.c new file mode 100644 index 0000000000..041a7b3ef0 --- /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 + +#include + +#include + +int +alphasort (const struct dirent **a, const struct dirent **b) +{ + return strcoll ((*a)->d_name, (*b)->d_name); +} diff --git a/lib/dirent.in.h b/lib/dirent.in.h index 40824c56b7..15f0245b09 100644 --- a/lib/dirent.in.h +++ b/lib/dirent.in.h @@ -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 index 0000000000..149129d4f8 --- /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 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], [:]) diff --git a/m4/dirent_h.m4 b/m4/dirent_h.m4 index 38cc118474..e507e3de8c 100644 --- 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_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 index 0000000000..319eccc0bb --- /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: + + +License: +LGPL + +Maintainer: +all, glibc + diff --git a/modules/dirent b/modules/dirent index cfe36ceae9..ca784f844a 100644 --- a/modules/dirent +++ b/modules/dirent @@ -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; \ -- 2.30.2