瀏覽代碼

fdopen should set errno when it fails due to invalid mode string

Rich Felker 13 年之前
父節點
當前提交
3b43d10faf
共有 1 個文件被更改,包括 4 次插入1 次删除
  1. 4 1
      src/stdio/__fdopen.c

+ 4 - 1
src/stdio/__fdopen.c

@@ -7,7 +7,10 @@ FILE *__fdopen(int fd, const char *mode)
 	int plus = !!strchr(mode, '+');
 
 	/* Check for valid initial mode character */
-	if (!strchr("rwa", *mode)) return 0;
+	if (!strchr("rwa", *mode)) {
+		errno = EINVAL;
+		return 0;
+	}
 
 	/* Allocate FILE+buffer or fail */
 	if (!(f=malloc(sizeof *f + UNGET + BUFSIZ))) return 0;