summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib/syscall_write.c
diff options
context:
space:
mode:
authorqingehao <[email protected]>2021-11-16 17:39:35 +0800
committerGitHub <[email protected]>2021-11-16 17:39:35 +0800
commit0a123c307e406d85a55749be99e2c45b5ee37c52 (patch)
treeab27ed7fb1636b5e46f7e6b01fbcf3a21d33336a /components/libc/compilers/dlib/syscall_write.c
parente1c281c95d9b7c4b8917d043b6fc33bf1a38e205 (diff)
parentc1d7eaa0152bd3873adc4a31aa2bb2452dc7fa97 (diff)
Merge branch 'RT-Thread:master' into master
Diffstat (limited to 'components/libc/compilers/dlib/syscall_write.c')
-rw-r--r--components/libc/compilers/dlib/syscall_write.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index 72bac6ba49..9a7707e9d3 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -9,7 +9,7 @@
*/
#include <rtthread.h>
-#include <yfuns.h>
+#include <LowLevelIOInterface.h>
#include <unistd.h>
#ifdef RT_USING_POSIX_STDIO
#include "libc.h"
@@ -19,6 +19,20 @@
#define DBG_LVL DBG_INFO
#include <rtdbg.h>
+/*
+ * The "__write" function should output "size" number of bytes from
+ * "buffer" in some application-specific way. It should return the
+ * number of characters written, or _LLIO_ERROR on failure.
+ *
+ * If "buffer" is zero then __write should perform flushing of
+ * internal buffers, if any. In this case "handle" can be -1 to
+ * indicate that all handles should be flushed.
+ *
+ * The template implementation below assumes that the application
+ * provides the function "MyLowLevelPutchar". It should return the
+ * character written, or -1 on failure.
+ */
+
#pragma module_name = "?__write"
size_t __write(int handle, const unsigned char *buf, size_t len)
@@ -29,36 +43,31 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
{
-#ifdef RT_USING_POSIX_STDIO
- 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)
+#ifdef RT_USING_CONSOLE
rt_device_t console_device;
console_device = rt_console_get_device();
- if (console_device != 0)
+ if (console_device)
{
rt_device_write(console_device, 0, buf, len);
}
- return len;
+ return len; /* return the length of the data written */
#else
return _LLIO_ERROR;
-#endif /* RT_USING_POSIX */
+#endif /* RT_USING_CONSOLE */
}
else if (handle == _LLIO_STDIN)
{
return _LLIO_ERROR;
}
-
+ else
+ {
#ifdef RT_USING_POSIX
- size = write(handle, buf, len);
- return size;
+ size = write(handle, buf, len);
+ return size; /* return the length of the data written */
#else
- return _LLIO_ERROR;
+ return _LLIO_ERROR;
#endif /* RT_USING_POSIX */
+ }
}