"Chip Davis" <cdavis(a)codeweavers.com> wrote:
Alexandre Julliard <julliard(a)winehq.org> wrote:
+static int is_directory_empty( struct fd *fd ) +{ + DIR *dir; + int count = 0; + + if ((dir = fdopendir( fd->unix_fd ))) + { + while (readdir( dir ) != NULL && count <= 2) + count++; + + closedir( dir ); + }
This won't work, closedir() is going to close the file descriptor.
What would you suggest to use instead? I'd be glad to consider any other ways to detect a non-empty directory.
fstat(2) the directory file and check that st_nlink is greater than 2.
Thanks for the suggestion, unfortunately this approach doesn't seem to work for me under Linux, I always get st_nlink = 2 using the following test app: #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/stat.h> int main(void) { char cwd[1024]; struct stat st; if (!getcwd(cwd, sizeof(cwd))) printf("getcwd failed\n"); else printf("cwd: %s\n", cwd); stat(cwd, &st); printf("st.st_nlink: %ld\n", st.st_nlink); return 0; } -- Dmitry.