News for hackers. Stuff that matters.
Re:Fibers: An Elegant Windows API by RcouF1uZ4gsC on Friday March 29, 2019 @04:14PM (#19525208)
FindFile, FindNextFile are an iterator pattern.

In C++, you have

    auto iterator = container.begin();
    while(iterator != container.end()){
      ++iterator;
    }
In Java you have

    Iterator<String> iterator = container.iterator();
    while(iterator.hasNext()) {
        iterator.next(); 
    }
Similarly with FindFile you have (leaving off some parameters)

  auto handle = FindFirstFile();
  while(FindNextFile(handle)){}
  CloseFile(handle);
Separating the creation of the iterator from advancing the iterator is a good thing.
Re:Fibers: An Elegant Windows API by asveikau on Friday March 29, 2019 @06:48PM (#19526302)
You are correct. The actual pattern you want to use in practice with this API is more of a do ... while:

    WIN32_FIND_DATA data;
    HANDLE handle;

    handle = FindFirstFile(str, &data);
    // TODO - error check

    do
    {
        // TODO: process "data" which is a file.
    } while (FindNextFile(handle, &data));

    FindClose(handle);
So the loop body is the same for the "first" and "next" files.