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.
This commit is contained in:
parent
fec3038524
commit
dcdafd0e92
@ -94,13 +94,13 @@ __opendir2(const char *name, int flags)
|
||||
|
||||
/*
|
||||
* POSIX 2008 and XSI 7 require alphasort() to call strcoll() for
|
||||
* directory entries ordering. Use local copy that uses strcmp().
|
||||
* directory entries ordering.
|
||||
*/
|
||||
static int
|
||||
opendir_alphasort(const void *p1, const void *p2)
|
||||
{
|
||||
|
||||
return (strcmp((*(const struct dirent **)p1)->d_name,
|
||||
return (strcoll((*(const struct dirent **)p1)->d_name,
|
||||
(*(const struct dirent **)p2)->d_name));
|
||||
}
|
||||
|
||||
|
@ -127,17 +127,13 @@ fail:
|
||||
/*
|
||||
* Alphabetic order comparison routine for those who want it.
|
||||
*
|
||||
* XXXKIB POSIX 2008 requires the alphasort() to use strcoll(). Keep
|
||||
* strcmp() for now, since environment locale settings could have no
|
||||
* relevance for the byte sequence of the file name. Moreover, it
|
||||
* might be even invalid sequence in current locale, and then
|
||||
* behaviour of alphasort would be undefined.
|
||||
* POSIX 2008 requires the alphasort() to use strcoll().
|
||||
*/
|
||||
int
|
||||
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));
|
||||
}
|
||||
|
||||
static int
|
||||
|
Loading…
x
Reference in New Issue
Block a user