Skip to content

Commit 8425401

Browse files
committed
Close stdio files before POSIX file descriptors
1 parent 32fe105 commit 8425401

File tree

3 files changed

+6
-3
lines changed

3 files changed

+6
-3
lines changed

mos-platform/commodore/open.s

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@
1818
;--------------------------------------------------------------------------
1919
; closeallfiles: Close all open files.
2020

21-
.section .fini,"axR",@progbits
21+
; This must happen after fclosing all stdio files.
22+
23+
.section .fini.200,"axR",@progbits
2224
closeallfiles:
2325

2426
ldx #MAX_FDS-1

mos-platform/commodore/write.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
;--------------------------------------------------------------------------
2424
; initstdout: Open the stdout and stderr file descriptors for the screen.
2525

26-
.section .init,"aR",@progbits
26+
.section .init,"axR",@progbits
2727
jsr initstdout
2828

2929
.text

mos-platform/common/c/stdio-full.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ FILE *stderr = &serr;
6161

6262
static FILE *filelist = &sin;
6363

64-
asm(".section .fini,\"axR\",@progbits\n"
64+
// This must happen before all POSIX open files are closed.
65+
asm(".section .fini.100,\"axR\",@progbits\n"
6566
" jsr _stdio_closeall\n");
6667

6768
void _stdio_closeall(void) {

0 commit comments

Comments
 (0)