summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib/syscall_write.c
diff options
context:
space:
mode:
authorWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
committerWayne Lin <[email protected]>2021-11-10 16:01:38 +0800
commit9b44e57a6022b8eb46eda7037b719ec918fdcc55 (patch)
tree26be9facf0f37d1c38b9e4b6e4abc99d6f8b5a8d /components/libc/compilers/dlib/syscall_write.c
parent37f5236dfa45b98d02e867536a10ac0b6622b80b (diff)
parentfdbaa2a808d12d522ad90702795c08ae8443aab9 (diff)
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'components/libc/compilers/dlib/syscall_write.c')
-rw-r--r--components/libc/compilers/dlib/syscall_write.c52
1 files changed, 31 insertions, 21 deletions
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index de464530b8..ab011c1096 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -9,46 +9,56 @@
*/
#include <rtthread.h>
-#ifdef RT_USING_DFS
-#include <dfs_posix.h>
-#endif
#include <yfuns.h>
+#include <unistd.h>
+#ifdef RT_USING_POSIX
#include "libc.h"
+#endif
+
+#define DBG_TAG "dlib.syscall_write"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
{
-#ifdef RT_USING_DFS
+#ifdef RT_USING_POSIX
int size;
-#endif
+#endif /* RT_USING_POSIX */
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifndef RT_USING_CONSOLE
- return _LLIO_ERROR;
-#else
-
#ifdef RT_USING_POSIX
- return libc_stdio_write((void*)buf, len);
-#else
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard output before initializing libc");
+ return 0;
+ }
+ return write(STDOUT_FILENO, (void*)buf, len);
+#elif defined(RT_USING_CONSOLE)
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device != 0) rt_device_write(console_device, 0, buf, len);
+ if (console_device != 0)
+ {
+ rt_device_write(console_device, 0, buf, len);
+ }
return len;
-#endif
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
+ }
+ else if (handle == _LLIO_STDIN)
+ {
+ return _LLIO_ERROR;
}
- if (handle == _LLIO_STDIN) return _LLIO_ERROR;
-
-#ifndef RT_USING_DFS
- return _LLIO_ERROR;
-#else
+#ifdef RT_USING_POSIX
size = write(handle, buf, len);
return size;
-#endif
+#else
+ return _LLIO_ERROR;
+#endif /* RT_USING_POSIX */
}
-