/bin/ls sorting bug?

Scott Mitchell scott+freebsd at fishballoon.org
Sat Jun 19 22:54:40 GMT 2004


On Sat, Jun 19, 2004 at 10:06:01PM +0200, Dimitry Andric wrote:
> 
> Looking through ls source shows that the sorting is done by passing a
> comparison function to fts_open(3).  In the case of sorting by
> modification time, the *only* comparison made is of the mtime fields:

You did see the patch attached to my original post, right?  It modifies all
of these comparison functions to sort the two items by name (or reverse
name) in the case that their timestamps are equal.

> Note also that the fts(3) functions use qsort(3), which isn't stable,
> so you will not always get the order in which these entries are listed
> in the directory itself.

Indeed.  The proposed change will always give you a predictable ordering
for a given set of entries.

	Scott

-- 
===========================================================================
Scott Mitchell           | PGP Key ID | "Eagles may soar, but weasels
Cambridge, England       | 0x54B171B9 |  don't get sucked into jet engines"
scott at fishballoon.org | 0xAA775B8B |      -- Anon


More information about the freebsd-hackers mailing list