Theodore Ts'o <tytso@xxxxxxx> writes: > I wonder if the better approach is to just simply have some > easy-to-use library routines that do a readdir/sort in userspace. The > spd_readdir does basically this, and as we can see it's good enough > for most purposes. The problem is danger when using this in threaded > programs, or if you have programs doing really strange things with > telldir/seekdir, etc. > > But it wouldn't be that hard to write a generic library function which > if it were used for find, ls, tar, and a few other key programs, would > solve the problem for most use cases. Many times I've used scandir(3) to do this. (copying out of notmuch/notmuch-new.c): static int dirent_sort_inode (const struct dirent **a, const struct dirent **b) { return ((*a)->d_ino < (*b)->d_ino) ? -1 : 1; } (as then doing stat() on each file is *much* faster in inode order) glibc provides alphasort() (POSIX.1-2008) and versionsort() (GNU extension), it'd probably be great if it also provided inodesort() -- Stewart Smith
Attachment:
pgpPbCm1fB2F6.pgp
Description: PGP signature