On Jul 15, 2020, at 11:49 AM, Sven Hartge <sven@svenhartge.de> wrote:
OK, please see the attached diff.
Nothing was attached. :(
Please note that I have no idea what I am doing, this may be memleaky as hell (although I think I added the free(namelist) to the correct places) and is not tested in any way.
I just adapted the example code from the scandir(3) man-page and massaged it a bit to fit the existing code.
Also note: if one uses scandir one could technically use its own filter to remove '.' and '..' from the list of entries but I wanted to change to be as minimal as possible.
Sure. The larger issue is that I tested it on OSX, and scandir() returns *duplicates*. i.e. it seems to randomly return the same file multiple times. So that's useless. Quite frankly, it's not a lot more code to just readdir() the entire directory, and put the files into an ordered heap. The "read file" code can then just pop entries from the heap. Alan DeKok.