Skip to content

Commit f4fde6b

Browse files
committed
Fix missing O_TRUNC flag for fopen(..., "w")
1 parent ffecba9 commit f4fde6b

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

examples/stdlib.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2117,7 +2117,8 @@ static int stdio_parse_mode(const char *mode)
21172117
flags = (plus != '+'? O_RDONLY: O_RDWR);
21182118
break;
21192119
case 'w':
2120-
flags = (plus != '+'? O_WRONLY | O_CREAT: O_RDWR | O_CREAT);
2120+
flags = (plus != '+'? O_WRONLY | O_CREAT | O_TRUNC:
2121+
O_RDWR | O_CREAT | O_TRUNC);
21212122
break;
21222123
case 'a':
21232124
flags = (plus != '+'? O_WRONLY | O_CREAT | O_APPEND:

0 commit comments

Comments
 (0)