May 28, 2020 5:40 AM, "Daniel Lehman" <dlehman25(a)gmail.com> wrote:
diff --git a/server/fd.c b/server/fd.c index 06d1d81bdb..e75d489748 100644 --- a/server/fd.c +++ b/server/fd.c @@ -2364,6 +2367,36 @@ static struct fd *get_handle_fd_obj( struct process *process, obj_handle_t handl return fd; }
+static int is_dir_empty( int fd ) +{ +#ifdef HAVE_DIRENT_H + DIR *dir; + int empty; + struct dirent *de; + + if ((fd = dup( fd )) == -1) + return -1; + + if (!(dir = fdopendir( fd ))) + { + close( fd ); + return -1; + } + + empty = 1; + while (empty && (de = readdir( dir ))) + { + if (!strcmp( de->d_name, "." ) || !strcmp( de->d_name, ".." )) continue; + empty = 0;
You could probably break from the loop after this point, since you found what you were looking for.
+ } + closedir( dir ); + close( fd );
This close(2) call shouldn't be necessary, since closedir(3) does that for you. It's the reason I suggested dup(2)'ing the fd in the first place. Leaving this in will set errno to EBADF, which may not be desirable.
+ return empty; +#else + return 1; +#endif +} + /* set disposition for the fd */ static void set_fd_disposition( struct fd *fd, int unlink ) {
Chip