freopen: reset stream orientation (byte/wide) and encoding rule
authorRich Felker <dalias@aerifal.cx>
Wed, 17 Aug 2022 22:34:07 +0000 (18:34 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 17 Aug 2022 22:34:07 +0000 (18:34 -0400)
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.

src/stdio/freopen.c

index 615d4b4..96bfbb4 100644 (file)
@@ -40,6 +40,8 @@ FILE *freopen(const char *restrict filename, const char *restrict mode, FILE *re
                fclose(f2);
        }
 
+       f->mode = 0;
+       f->locale = 0;
        FUNLOCK(f);
        return f;