fix errno value when fdopendir is given an invalid file descriptor
authorRich Felker <dalias@aerifal.cx>
Fri, 22 Jul 2011 01:15:14 +0000 (21:15 -0400)
committerRich Felker <dalias@aerifal.cx>
Fri, 22 Jul 2011 01:15:14 +0000 (21:15 -0400)
this resolves an issue reported by Vasiliy Kulikov

src/dirent/fdopendir.c

index c4b8e61..c684a86 100644 (file)
@@ -12,7 +12,10 @@ DIR *fdopendir(int fd)
        DIR *dir;
        struct stat st;
 
        DIR *dir;
        struct stat st;
 
-       if (fstat(fd, &st) < 0 || !S_ISDIR(st.st_mode)) {
+       if (fstat(fd, &st) < 0) {
+               return 0;
+       }
+       if (!S_ISDIR(st.st_mode)) {
                errno = ENOTDIR;
                return 0;
        }
                errno = ENOTDIR;
                return 0;
        }