From 3ba5b23dab4b6e24b40a7584a9107804ca8cf28d Mon Sep 17 00:00:00 2001 From: Jan Nieuwenhuizen Date: Sun, 10 Jun 2018 07:51:10 +0200 Subject: [PATCH] mescc: Support binutils-2.10.1: opentype `r+'. * lib/libc+tcc.c (fopen): Support opentype `r+'. --- lib/libc+tcc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/libc+tcc.c b/lib/libc+tcc.c index b7bdd0f2..bd4bbfb9 100644 --- a/lib/libc+tcc.c +++ b/lib/libc+tcc.c @@ -189,12 +189,14 @@ fopen (char const *file_name, char const *opentype) { int fd; int mode = 0600; - if (opentype[0] == 'a' && !access (file_name, O_RDONLY)) + if ((opentype[0] == 'a' || !strcmp (opentype, "r+")) + && !access (file_name, O_RDONLY)) { fd = open (file_name, O_RDWR, mode); - lseek (fd, 0, SEEK_END); + if (opentype[0] == 'a') + lseek (fd, 0, SEEK_END); } - else if (opentype[0] == 'w' || opentype[0] == 'a') + else if (opentype[0] == 'w' || opentype[0] == 'a' || !strcmp (opentype, "r+")) { char *plus_p = strchr (opentype, '+'); int flags = plus_p ? O_RDWR | O_CREAT : O_WRONLY | O_CREAT | O_TRUNC;