What determines the order directory entries are returned by getdents?

前端 未结 2 2055
慢半拍i
慢半拍i 2021-02-15 13:31

Background is I have an existing application which lists directory entries; strace reveals it just calls getdents and lists them in the order returned. I would like them display

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-15 14:08

    No, there is no way you can manipulate the filesystem metadata to have getdents(2) return directory entires in the same order as the sort order that ls(1) applies to the directory entires.

    You can always modify your program to sort entries using the same algorithms that ls(1) provides, though this requires at least O(N) memory and O(N Log N) time for sorting a directory with N entries. You'll have to decide if it is worth the implementation, memory, and time, to sort in the same manner as ls(1).

提交回复
热议问题