From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 111968 invoked by alias); 1 Feb 2019 09:39:57 -0000 Mailing-List: contact newlib-cvs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: newlib-cvs-owner@sourceware.org Received: (qmail 111946 invoked by uid 10080); 1 Feb 2019 09:39:57 -0000 Date: Fri, 01 Feb 2019 09:39:00 -0000 Message-ID: <20190201093957.111945.qmail@sourceware.org> Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Sebastian Huber To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] a) Use strcoll() in opendir() and alphasort() X-Act-Checkin: newlib-cygwin X-Git-Author: ache X-Git-Refname: refs/heads/master X-Git-Oldrev: 2d3c2f4697481dc6df76528c9addabd4c80d3652 X-Git-Newrev: 67613cbbd87b5b3c5b10209e6272fc8ec6405b26 X-SW-Source: 2019-q1/txt/msg00021.txt.bz2 https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=67613cbbd87b5b3c5b10209e6272fc8ec6405b26 commit 67613cbbd87b5b3c5b10209e6272fc8ec6405b26 Author: ache Date: Mon Jan 18 10:17:51 2010 +0000 a) Use strcoll() in opendir() and alphasort() as POSIX 2008 requires. It also matches now how our 'ls' works for years. b) Remove comment expressed 2 fears: 1) One just simple describe how strcoll() works in _any_ context, not for directories only. Are we plan to remove strcoll() from everything just because it is little more complex than strcmp()? I doubt, and directories give nothing different here. Moreover, strcoll() used in 'ls' for years and nobody complaints yet. 2) Plain wrong statement about undefined strcoll() behaviour. strcoll() always gives predictable results, falling back to strcmp() on any trouble, see strcoll(3). No objections from -current list discussion. Diff: --- newlib/libc/posix/scandir.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/newlib/libc/posix/scandir.c b/newlib/libc/posix/scandir.c index 56de1b9..c39d9a4 100644 --- a/newlib/libc/posix/scandir.c +++ b/newlib/libc/posix/scandir.c @@ -142,12 +142,13 @@ fail: /* * Alphabetic order comparison routine for those who want it. + * POSIX 2008 requires that alphasort() uses strcoll(). */ int -alphasort (const struct dirent **d1, - const struct dirent **d2) +alphasort(const struct dirent **d1, const struct dirent **d2) { - return(strcmp((*d1)->d_name, (*d2)->d_name)); + + return (strcoll((*d1)->d_name, (*d2)->d_name)); } #endif /* ! HAVE_OPENDIR */