diff options
-rw-r--r-- | src/libmdsserver/macros.h | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/libmdsserver/macros.h b/src/libmdsserver/macros.h index f5c6808..14ce80b 100644 --- a/src/libmdsserver/macros.h +++ b/src/libmdsserver/macros.h @@ -444,15 +444,18 @@ if (dir == NULL) \ perror(*argv); /* Well, that is just unfortunate, but we cannot really do anything. */ \ else \ - while ((file = readdir(dir)) != NULL) \ - if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \ - { \ - int fd = atoi(file->d_name); \ - if (condition) \ - xclose(fd); \ - } \ - \ - closedir(dir); \ + { \ + int dfd = dirfd(dir); \ + while ((file = readdir(dir)) != NULL) \ + if (strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) \ + { \ + int fd = atoi(file->d_name); \ + if (fd != dfd) \ + if (condition) \ + xclose(fd); \ + } \ + closedir(dir); \ + } \ } \ while (0) |