summaryrefslogtreecommitdiff
path: root/components/libc/compilers
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-11-10 18:33:43 -0500
committerMeco Man <[email protected]>2021-11-10 18:33:43 -0500
commitcb8d5c5d9d3fed61114ed1824b6f0615c31e86c3 (patch)
tree567d108615e171d2fd40f0a203eb94ac8ce37c22 /components/libc/compilers
parente6ae01e3326a5feb6d11176c3407bee7c920399c (diff)
[libc][gcc] 重新梳理fread fwrite桩函数实现
Diffstat (limited to 'components/libc/compilers')
-rw-r--r--components/libc/compilers/gcc/newlib/syscalls.c53
1 files changed, 37 insertions, 16 deletions
diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c
index e957aaf003..7c25ffac3f 100644
--- a/components/libc/compilers/gcc/newlib/syscalls.c
+++ b/components/libc/compilers/gcc/newlib/syscalls.c
@@ -216,13 +216,27 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode)
_ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes)
{
-#ifdef RT_USING_POSIX_STDIO
+#ifdef RT_USING_POSIX
_ssize_t rc;
- if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO)
+ if (fd == STDIN_FILENO)
{
- LOG_W("Do not invoke standard input before initializing libc");
- return 0;
+#ifdef RT_USING_POSIX_STDIO
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_POSIX_STDIO */
+ }
+ else if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
+ {
+ ptr->_errno = ENOTSUP;
+ return -1;
}
+
rc = read(fd, buf, nbytes);
return rc;
#else
@@ -271,27 +285,34 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
{
#ifdef RT_USING_POSIX
_ssize_t rc;
-#ifdef RT_USING_POSIX_STDIO
- if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO)
- {
- LOG_W("Do not invoke standard output before initializing libc");
- return 0;
- }
-#endif /* RT_USING_POSIX_STDIO */
- rc = write(fd, buf, nbytes);
- return rc;
-#elif defined(RT_USING_CONSOLE)
- if (STDOUT_FILENO == fd)
+#endif /* RT_USING_POSIX */
+
+ if (fd == STDOUT_FILENO || fd == STDERR_FILENO)
{
+#ifdef RT_USING_CONSOLE
rt_device_t console;
console = rt_console_get_device();
if (console)
return rt_device_write(console, -1, buf, nbytes);
+#else
+ ptr->_errno = ENOTSUP;
+ return -1;
+#endif /* RT_USING_CONSOLE */
}
-#endif /* RT_USING_POSIX */
+ else if (fd == STDIN_FILENO)
+ {
+ ptr->_errno = ENOTSUP;
+ return -1;
+ }
+
+#ifdef RT_USING_POSIX
+ rc = write(fd, buf, nbytes);
+ return rc;
+#else
ptr->_errno = ENOTSUP;
return -1;
+#endif /* RT_USING_POSIX */
}
/* for exit() and abort() */