Skip to content

Commit ba8025f

Browse files
cfriedthenrikbrixandersen
authored andcommitted
newlib: correct signature of _open() for xtensa
Previously, in libc-hooks.c, the signature of `_open()` was as shown below. ```cpp int _open(const char *name, int mode); ``` This conflicted with the signature of `_open()` from newlib, which is ```cpp int _open(const char *name, int flags, ...); ``` Moreover, the mode and flags field were reversed, but only for the Xtensa architecture due to the `_open_r()` hook that is present in `libc-hooks.c`. This manifested itself via a call to `fopen(file, "w+")`, where the expected flags should include `O_CREAT | O_TRUNC`, or `0x200 | 0x400`. Instead, the unexpected flags passed to the underlying `zvfs_open()` call were `0x1b6`. This change corrects the function signature and order of the arguments. Signed-off-by: Chris Friedt <[email protected]>
1 parent 4d60f0a commit ba8025f

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

lib/libc/newlib/libc-hooks.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
int _fstat(int fd, struct stat *st);
2727
int _read(int fd, void *buf, int nbytes);
2828
int _write(int fd, const void *buf, int nbytes);
29-
int _open(const char *name, int mode);
29+
int _open(const char *name, int flags, ...);
3030
int _close(int file);
3131
int _lseek(int file, int ptr, int dir);
3232
int _kill(int pid, int sig);
@@ -239,7 +239,7 @@ int _write(int fd, const void *buf, int nbytes)
239239
}
240240
__weak FUNC_ALIAS(_write, write, int);
241241

242-
int _open(const char *name, int mode)
242+
int _open(const char *name, int flags, ...)
243243
{
244244
return -1;
245245
}
@@ -518,7 +518,7 @@ int _open_r(struct _reent *r, const char *name, int flags, int mode)
518518
ARG_UNUSED(r);
519519
ARG_UNUSED(flags);
520520

521-
return _open(name, mode);
521+
return _open(name, flags, mode);
522522
}
523523

524524
int _close_r(struct _reent *r, int file)

0 commit comments

Comments
 (0)