Commit 626f8d75 authored by Eric Pouech's avatar Eric Pouech Committed by Alexandre Julliard

msvcrt: Fix freopen() on FILE with invalid underlying fd.

parent 65b6e237
......@@ -4588,9 +4588,7 @@ FILE* CDECL _wfreopen(const wchar_t *path, const wchar_t *mode, FILE* file)
TRACE(":path (%s) mode (%s) file (%p) fd (%d)\n", debugstr_w(path), debugstr_w(mode), file, file ? file->_file : -1);
LOCK_FILES();
if (!file || ((fd = file->_file) < 0))
file = NULL;
else
if (file)
{
fclose(file);
if (msvcrt_get_flags(mode, &open_flags, &stream_flags) == -1)
......
......@@ -1236,6 +1236,25 @@ static void test_freopen( void )
ok(ret == EOF, "fclose(file) succeeded\n");
ok(errno == 0xdeadbeef, "errno is %d\n", errno);
file = fopen(filename1, "rb");
ok(file != NULL, "couldn't open %s\n", filename1);
close(file->_file);
file->_file = -1;
new = freopen(filename2, "rb", file);
ok(new == file, "freopen() didn't return same FILE*\n");
fd = fileno(file);
ok(fd > 0, "fileno() returned %d\n", fd);
ch = '#';
ret = fread(&ch, 1, 1, file);
ok(ret == 1, "fread() returned %d\n", ret);
ok(ch == '2', "Unexpected char\n");
ret = fclose(file);
ok(ret == 0, "fclose(file) returned %d\n", ret);
unlink(filename1);
unlink(filename2);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment