bitwiseworks / libc

LIBC Next (kLIBC fork)
9 stars 4 forks source link

Check behaviour of opendir()/readdir() #18

Closed warped-rudi closed 5 years ago

warped-rudi commented 5 years ago

I don't know if this applies to your fork as well, but I recently learned that when the functions opendir()/readdir() are asked to retrieve the content of a root directory (i.e. "X:/*"), they erroneously return the content of the current directory on that drive. The problem can be avoided by specifying "X:/./*" as search pattern.

dmik commented 5 years ago

This looks like a false alarm. I've just tested this simple program:

#include <stdio.h>
#include <dirent.h>

int main ()
{
  DIR *dir = opendir ("D:/");
  if (!dir)
  {
    perror ("opendir");
    return 1;
  }

  struct dirent *de;
  while ((de = readdir (dir)))
    printf ("[%s]\n", de->d_name);
  closedir (dir);

  return 0;
}

and it works as expected here: shows the contents of the root directory of drive D:. Are you sure you didn't specify X: instead of X:/ in your case? As the former will indeed return the contents of the current directory on drive X rather than root. This is the standard OS/2 behavior.

dmik commented 5 years ago

And also note that opendir doesn't accept wildcards (*). It will simply return ENOENT on them.

warped-rudi commented 5 years ago

It appears that the (Linux-)code that prepares the directory name does, indeed, remove the trailing slash! I didn't spot that in the first place. Sorry for wasting your time. Closing this issue...