Skip to content

Commit ad4dcef

Browse files
committed
Don't call SetMode on restore_streams if old BPTRs are NULL
1 parent c1c7f60 commit ad4dcef

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

library/stdio/file_init.c

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,22 @@ workbench_exit() {
3333
}
3434

3535
if (__clib4->restore_streams) {
36-
SelectInput(__clib4->old_input);
37-
SetMode(__clib4->old_input, DOSFALSE);
38-
__clib4->old_input = BZERO;
39-
40-
SelectOutput(__clib4->old_output);
41-
SetMode(__clib4->old_output, DOSFALSE);
42-
__clib4->old_output = BZERO;
43-
44-
SelectErrorOutput(__clib4->old_error);
45-
SetMode(__clib4->old_error, DOSFALSE);
46-
__clib4->old_error = BZERO;
47-
36+
if (__clib4->old_input != BZERO) {
37+
SelectInput(__clib4->old_input);
38+
SetMode(__clib4->old_input, DOSFALSE);
39+
__clib4->old_input = BZERO;
40+
}
41+
if (__clib4->old_output != BZERO) {
42+
SelectOutput(__clib4->old_output);
43+
SetMode(__clib4->old_output, DOSFALSE);
44+
__clib4->old_output = BZERO;
45+
}
46+
if (__clib4->old_error != BZERO) {
47+
SelectErrorOutput(__clib4->old_error);
48+
SetMode(__clib4->old_error, DOSFALSE);
49+
__clib4->old_error = BZERO;
50+
}
51+
4852
__clib4->restore_streams = FALSE;
4953
}
5054

0 commit comments

Comments
 (0)