Skip to content

Commit fd819e4

Browse files
[do-not-upstream][semihost] open sys call doesn't handle "rb+" mode
According to the ISO/IEC_9899_1999, section:7.19.5.3 Opening file with `r+` mode just open text file for update (reading and writing) but dosen't create it. if the file isn't exist `open()` returns NULL. So, to create and open a file to update (reading and writing), we should open with "a+" or "w+" modes. Signed-off-by: Mostafa Salman <[email protected]>
1 parent 1ecf5b0 commit fd819e4

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

semihost/open.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,10 @@ open(const char *pathname, int flags, ...)
6969
default:
7070
if (flags & O_TRUNC)
7171
semiflags = SH_OPEN_W_PLUS_B; /* 'wb+' */
72-
else
72+
else if (flags & O_APPEND)
7373
semiflags = SH_OPEN_A_PLUS_B; /* 'ab+' */
74+
else
75+
semiflags = SH_OPEN_R_PLUS_B; /* 'rb+' */
7476
break;
7577
}
7678

0 commit comments

Comments
 (0)