svn commit: r202572 - head/lib/libc/gen

Bruce Evans brde at optusnet.com.au
Tue Jan 19 14:42:12 UTC 2010


On Mon, 18 Jan 2010, Andrey A. Chernov wrote:

> Log:
>  Double checking my commit I found that comment saying that
>  POSIX 2008 and XSI 7require strcoll() for opendir() is not true.
>  I can't find such requirement in POSIX 2008 and XSI 7.

The comment was correct.  It says that POSIX requires strcoll() for
alphasort(), not for opendir().  Since opendir() is not alphasort(),
and it wants plain ASCII sorting to support union file systems, it
intentionally doesn't use either alphasort() or strcoll().

>  So, back out that part of my commit, returning old strcmp(), and remove
>  this misleading comment.
>
> Modified:
>  head/lib/libc/gen/opendir.c
>
> Modified: head/lib/libc/gen/opendir.c
> ==============================================================================
> --- head/lib/libc/gen/opendir.c	Mon Jan 18 13:38:45 2010	(r202571)
> +++ head/lib/libc/gen/opendir.c	Mon Jan 18 13:44:44 2010	(r202572)
> @@ -92,15 +92,11 @@ __opendir2(const char *name, int flags)
> 	return __opendir_common(fd, name, flags);
> }
>
> -/*
> - * POSIX 2008 and XSI 7 require alphasort() to call strcoll() for
> - * directory entries ordering.
> - */

Was correct, but it could have been clearer by saying ", so opendir()
uses this comparison function instead of alphasort()".

> static int
> -opendir_alphasort(const void *p1, const void *p2)
> +opendir_sort(const void *p1, const void *p2)

I forget what the old name was.  Having alphasort in the name here was
wrong 3 layers deep, since this is not alphasort(), and alphasort() is not
an alpha sorting function -- it is a lexicographically-on-the-whole-
character-set comparison function.

fts's internal comparison function is named correctly -- fts_compar.

> {
>
> -	return (strcoll((*(const struct dirent **)p1)->d_name,
> +	return (strcmp((*(const struct dirent **)p1)->d_name,
> 	    (*(const struct dirent **)p2)->d_name));

Now correct (was broken by previous commit).

> }
>
> @@ -253,7 +249,7 @@ __opendir_common(int fd, const char *nam
> 				 * This sort must be stable.
> 				 */
> 				mergesort(dpv, n, sizeof(*dpv),
> -				    opendir_alphasort);
> +				    opendir_sort);

Correct modulo the name.

>
> 				dpv[n] = NULL;
> 				xp = NULL;
>

New bug in a comment in scandir(): now has an extra blank line, due to
partial removal.

Bruce


More information about the svn-src-all mailing list