浏览代码

freopen: reset stream orientation (byte/wide) and encoding rule

this is a requirement of the C language (orientation) and POSIX
(encoding rule) that was somehow overlooked.

we rely on the fact that the buffer pointers have been reset by
fflush, so that any future stdio operations on the stream will go
through the same code paths they would on a newly-opened file without
an orientation set, thereby setting the orientation as they should.
Rich Felker 2 年之前
父节点
当前提交
37e18b7bf3
共有 1 个文件被更改,包括 2 次插入0 次删除
  1. 2 0
      src/stdio/freopen.c

+ 2 - 0
src/stdio/freopen.c

@@ -40,6 +40,8 @@ FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *re
 		fclose(f2);
 		fclose(f2);
 	}
 	}
 
 
+	f->mode = 0;
+	f->locale = 0;
 	FUNLOCK(f);
 	FUNLOCK(f);
 	return f;
 	return f;