summaryrefslogtreecommitdiff
path: root/components/libc/compilers/dlib
diff options
context:
space:
mode:
authorguo <[email protected]>2021-09-27 21:36:53 +0800
committerGitHub <[email protected]>2021-09-27 21:36:53 +0800
commitb7903b293879e24c694c24710e521378576fdcf4 (patch)
treec0820262509270d6d880db7c9c87ab458670b433 /components/libc/compilers/dlib
parent94bd9f96a4b49e94916a2904eea882792e0460d2 (diff)
parent0a799653df4ae4bcaeef78620768a1c8d6242d94 (diff)
Merge pull request #5087 from mysterywolf/libc_stdio
[libc标准化][syscall]移除libc_stdio_read/write函数,优化syscall
Diffstat (limited to 'components/libc/compilers/dlib')
-rw-r--r--components/libc/compilers/dlib/libc.h9
-rw-r--r--components/libc/compilers/dlib/stdio.c9
-rw-r--r--components/libc/compilers/dlib/syscall_read.c16
-rw-r--r--components/libc/compilers/dlib/syscall_write.c22
4 files changed, 34 insertions, 22 deletions
diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h
index fc3cafca78..9643c1161f 100644
--- a/components/libc/compilers/dlib/libc.h
+++ b/components/libc/compilers/dlib/libc.h
@@ -11,17 +11,14 @@
#ifndef __RTT_LIBC_H__
#define __RTT_LIBC_H__
-#include <stddef.h>
-
#ifdef __cplusplus
extern "C" {
#endif
-int libc_system_init(void);
-int libc_stdio_set_console(const char* device_name, int mode);
+int libc_system_init(void);
int libc_stdio_get_console(void);
-int libc_stdio_read(void* buffer, size_t size);
-int libc_stdio_write(const void* buffer, size_t size);
+int libc_stdio_set_console(const char* device_name, int mode);
+
#ifdef __cplusplus
}
#endif
diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c
index c11157d759..ed3f5dfef9 100644
--- a/components/libc/compilers/dlib/stdio.c
+++ b/components/libc/compilers/dlib/stdio.c
@@ -46,13 +46,4 @@ int libc_stdio_get_console(void) {
return std_fd;
}
-int libc_stdio_read(void *buffer, size_t size)
-{
- return read(std_fd, buffer, size);
-}
-
-int libc_stdio_write(const void *buffer, size_t size)
-{
- return write(std_fd, buffer, size);
-}
#endif
diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c
index afb661bd93..ae980be6ca 100644
--- a/components/libc/compilers/dlib/syscall_read.c
+++ b/components/libc/compilers/dlib/syscall_read.c
@@ -15,6 +15,10 @@
#include <yfuns.h>
#include "libc.h"
+#define DBG_TAG "dlib.syscall_read"
+#define DBG_LVL DBG_INFO
+#include <rtdbg.h>
+
#pragma module_name = "?__read"
size_t __read(int handle, unsigned char *buf, size_t len)
{
@@ -25,14 +29,20 @@ size_t __read(int handle, unsigned char *buf, size_t len)
if (handle == _LLIO_STDIN)
{
#ifdef RT_USING_POSIX
- return libc_stdio_read(buf, len);
+ if (libc_stdio_get_console() < 0)
+ {
+ LOG_W("Do not invoke standard input before initializing libc");
+ return 0;
+ }
+ return read(STDIN_FILENO, buf, len);
#else
return _LLIO_ERROR;
#endif
}
-
- if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ else if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR))
+ {
return _LLIO_ERROR;
+ }
#ifndef RT_USING_DFS
return _LLIO_ERROR;
diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c
index de464530b8..ffee51882d 100644
--- a/components/libc/compilers/dlib/syscall_write.c
+++ b/components/libc/compilers/dlib/syscall_write.c
@@ -15,6 +15,10 @@
#include <yfuns.h>
#include "libc.h"
+#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)
@@ -30,19 +34,29 @@ size_t __write(int handle, const unsigned char *buf, size_t len)
#else
#ifdef RT_USING_POSIX
- return libc_stdio_write((void*)buf, len);
+ 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);
#else
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
}
-
- if (handle == _LLIO_STDIN) return _LLIO_ERROR;
+ else if (handle == _LLIO_STDIN)
+ {
+ return _LLIO_ERROR;
+ }
#ifndef RT_USING_DFS
return _LLIO_ERROR;