summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib/syscall_write.c
diff options
context:
space:
mode:
authorBernard Xiong <[email protected]>2021-11-15 23:27:27 +0800
committerGitHub <[email protected]>2021-11-15 23:27:27 +0800
commit0bcab2892a81960ceb394b5cde4bc78eed3326eb (patch)
tree2f6cf7554548f407edb8a51136c76a7a7658a375 /components/libc/compilers/dlib/syscall_write.c
parentef05ecf7c47a8265de19ce8367583de690fb1860 (diff)
parent4fe93881b071ea664b9a5b89c073ad46b9d3e312 (diff)
Merge pull request #5268 from mysterywolf/SYSCALL
[libc]重新梳理read write桩函数实现
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 */
+ }
}