Sfoglia il codice sorgente

fix errno value when fdopendir is given an invalid file descriptor

this resolves an issue reported by Vasiliy Kulikov
Rich Felker 13 anni fa
parent
commit
fa845669ce
1 ha cambiato i file con 4 aggiunte e 1 eliminazioni
  1. 4 1
      src/dirent/fdopendir.c

+ 4 - 1
src/dirent/fdopendir.c

@@ -12,7 +12,10 @@ DIR *fdopendir(int fd)
 	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;
 	}