diff options
| author | Meco Man <[email protected]> | 2021-09-21 12:51:26 -0400 |
|---|---|---|
| committer | Meco Man <[email protected]> | 2021-09-21 12:51:26 -0400 |
| commit | c8c632512aa6c87211871fe0a85e77b72d4ebe06 (patch) | |
| tree | b6d51850cf0b940973a670ece8341ec469c85693 /components/libc/compilers/armlibc | |
| parent | 13b0b60b1466b4a3eae34b5437ff35432de32c5e (diff) | |
[libc][syscall]移除libc_stdio_read/write函数,优化syscall
Diffstat (limited to 'components/libc/compilers/armlibc')
| -rw-r--r-- | components/libc/compilers/armlibc/libc.h | 9 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/stdio.c | 26 | ||||
| -rw-r--r-- | components/libc/compilers/armlibc/syscalls.c | 15 |
3 files changed, 13 insertions, 37 deletions
diff --git a/components/libc/compilers/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h index aecf8cdc50..5c1613728e 100644 --- a/components/libc/compilers/armlibc/libc.h +++ b/components/libc/compilers/armlibc/libc.h @@ -10,17 +10,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/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c index c786c78aa5..7dd9dbfe3f 100644 --- a/components/libc/compilers/armlibc/stdio.c +++ b/components/libc/compilers/armlibc/stdio.c @@ -21,6 +21,7 @@ #define STDIO_DEVICE_NAME_MAX 32 static int std_fd = -1; + int libc_stdio_set_console(const char* device_name, int mode) { int fd; @@ -47,29 +48,4 @@ int libc_stdio_get_console(void) return std_fd; } -int libc_stdio_read(void *buffer, size_t size) -{ - if (std_fd >= 0) - { - return read(std_fd, buffer, size); - } - else - { - rt_kprintf("Illegal stdio input!\n"); - return 0; - } -} - -int libc_stdio_write(const void *buffer, size_t size) -{ - if (std_fd >= 0) - { - return write(std_fd, buffer, size); - } - else - { - rt_kprintf("Illegal stdio output!\n"); - return size; - } -} #endif diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index be6041a663..d942bdb984 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -146,16 +146,17 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) if (fh == STDIN) { #ifdef RT_USING_POSIX - size = libc_stdio_read(buf, len); + size = read(STDIN_FILENO, buf, len); return len - size; #else /* no stdin */ return -1; #endif } - - if ((fh == STDOUT) || (fh == STDERR)) + else if ((fh == STDOUT) || (fh == STDERR)) + { return -1; + } #ifndef RT_USING_DFS return 0; @@ -185,7 +186,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; #else #ifdef RT_USING_POSIX - size = libc_stdio_write(buf, len); + size = write(STDOUT_FILENO, buf, len); return len - size; #else if (rt_console_get_device()) @@ -198,8 +199,10 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) #endif #endif } - - if (fh == STDIN) return -1; + else if (fh == STDIN) + { + return -1; + } #ifndef RT_USING_DFS return 0; |
