diff options
| author | Wayne Lin <[email protected]> | 2021-11-10 16:01:38 +0800 |
|---|---|---|
| committer | Wayne Lin <[email protected]> | 2021-11-10 16:01:38 +0800 |
| commit | 9b44e57a6022b8eb46eda7037b719ec918fdcc55 (patch) | |
| tree | 26be9facf0f37d1c38b9e4b6e4abc99d6f8b5a8d /components/libc/compilers/dlib | |
| parent | 37f5236dfa45b98d02e867536a10ac0b6622b80b (diff) | |
| parent | fdbaa2a808d12d522ad90702795c08ae8443aab9 (diff) | |
Merge branch 'master' of https://github.com/RT-Thread/rt-thread into nuvoton
Diffstat (limited to 'components/libc/compilers/dlib')
| -rw-r--r-- | components/libc/compilers/dlib/SConscript | 10 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/libc.c | 44 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/libc.h | 29 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/stdio.c | 58 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_close.c | 11 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_lseek.c | 9 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_open.c | 12 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_read.c | 36 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_remove.c | 12 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscall_write.c | 52 | ||||
| -rw-r--r-- | components/libc/compilers/dlib/syscalls.c | 7 |
11 files changed, 70 insertions, 210 deletions
diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 75a5812fab..39707abc61 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -1,26 +1,20 @@ from building import * - Import('rtconfig') src = Glob('*.c') -cwd = GetCurrentDir() group = [] -CPPPATH = [cwd] CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - - if GetDepend('RT_USING_DFS'): + if GetDepend('RT_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion CPPDEFINES = CPPDEFINES + ['_DLIB_FILE_DESCRIPTOR'] - if LooseVersion(IARVersion()) < LooseVersion("8.20.1"): CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT'] - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], - CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) + group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/dlib/libc.c b/components/libc/compilers/dlib/libc.c deleted file mode 100644 index d0dca7c5f6..0000000000 --- a/components/libc/compilers/dlib/libc.c +++ /dev/null @@ -1,44 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ -#include <stdio.h> -#include <stdlib.h> - -#include <rtthread.h> - -#include "libc.h" - -#ifdef RT_USING_PTHREADS -#include <pthread.h> -#endif - -int libc_system_init(void) -{ -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - #if defined(RT_USING_POSIX) - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - #else - libc_stdio_set_console(dev_console->parent.name, O_WRONLY); - #endif - } -#endif - -#if defined (RT_USING_PTHREADS) && !defined (RT_USING_COMPONENTS_INIT) - pthread_system_init(); -#endif - - return 0; -} -INIT_COMPONENT_EXPORT(libc_system_init); - diff --git a/components/libc/compilers/dlib/libc.h b/components/libc/compilers/dlib/libc.h deleted file mode 100644 index fc3cafca78..0000000000 --- a/components/libc/compilers/dlib/libc.h +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard the first version - */ - -#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_stdio_get_console(void); -int libc_stdio_read(void* buffer, size_t size); -int libc_stdio_write(const void* buffer, size_t size); -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/dlib/stdio.c b/components/libc/compilers/dlib/stdio.c deleted file mode 100644 index c11157d759..0000000000 --- a/components/libc/compilers/dlib/stdio.c +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2017/10/15 bernard implement stdio for IAR dlib. - */ - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - -#include <rtthread.h> -#include "libc.h" - -#if defined(RT_USING_DFS) && defined(RT_USING_DFS_DEVFS) -#include <dfs_posix.h> - -#define STDIO_DEVICE_NAME_MAX 32 - -static int std_fd = -1; -int libc_stdio_set_console(const char* device_name, int mode) -{ - int fd; - char name[STDIO_DEVICE_NAME_MAX]; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - fd = open(name, mode, 0); - if (fd >= 0) - { - if (std_fd >= 0) - { - close(std_fd); - } - std_fd = fd; - } - - return std_fd; -} - -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_close.c b/components/libc/compilers/dlib/syscall_close.c index 7ed1cc2f2d..2897c2418a 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -8,10 +8,8 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#ifdef RT_USING_DFS -#include <dfs_posix.h> -#endif #include <yfuns.h> +#include <unistd.h> #pragma module_name = "?__close" int __close(int handle) @@ -20,10 +18,9 @@ int __close(int handle) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; - -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX return close(handle); #else - return 0; -#endif + return _LLIO_ERROR; +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 47a069bf0a..4ea55ef1c3 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -8,10 +8,8 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#ifdef RT_USING_DFS -#include <dfs_posix.h> -#endif #include <yfuns.h> +#include <unistd.h> #pragma module_name = "?__lseek" long __lseek(int handle, long offset, int whence) @@ -20,10 +18,9 @@ long __lseek(int handle, long offset, int whence) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; - -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX return lseek(handle, offset, whence); #else return _LLIO_ERROR; -#endif +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 37bfcecb47..8fb3c3a11f 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -10,17 +10,13 @@ #include <rtthread.h> #include <yfuns.h> -#ifdef RT_USING_DFS -#include <dfs_posix.h> -#endif +#include <fcntl.h> #pragma module_name = "?__open" int __open(const char *filename, int mode) { -#ifndef RT_USING_DFS - return _LLIO_ERROR; -#else +#ifdef RT_USING_POSIX int handle; int open_mode = O_RDONLY; @@ -70,5 +66,7 @@ int __open(const char *filename, int mode) return _LLIO_ERROR; return handle; -#endif +#else + return _LLIO_ERROR; +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index afb661bd93..74cedb966a 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -9,35 +9,39 @@ */ #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_read" +#define DBG_LVL DBG_INFO +#include <rtdbg.h> #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_USING_DFS +#ifdef RT_USING_POSIX int size; -#endif if (handle == _LLIO_STDIN) { -#ifdef RT_USING_POSIX - return libc_stdio_read(buf, len); -#else - return _LLIO_ERROR; -#endif + if (libc_stdio_get_console() < 0) + { + LOG_W("Do not invoke standard input before initializing libc"); + return 0; + } + return read(STDIN_FILENO, buf, len); } - - 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; -#else size = read(handle, buf, len); return size; -#endif +#else + return _LLIO_ERROR; +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index 7d74236f4c..05bfbb67ae 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -8,17 +8,15 @@ * 2015-01-28 Bernard first version */ #include <rtthread.h> -#ifdef RT_USING_DFS -#include <dfs_posix.h> -#endif #include <yfuns.h> +#include <unistd.h> #pragma module_name = "?remove" int remove(const char *val) { -#ifndef RT_USING_DFS - return -1; -#else +#ifdef RT_USING_POSIX return unlink(val); -#endif +#else + return -1; +#endif /* RT_USING_POSIX */ } 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 */ } - diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c index e1c9562b3a..1ee6a3bc12 100644 --- a/components/libc/compilers/dlib/syscalls.c +++ b/components/libc/compilers/dlib/syscalls.c @@ -6,7 +6,6 @@ * Change Logs: * Date Author Notes * 2021-02-13 Meco Man implement exit() and abort() - * 2021-02-20 Meco Man add system() */ #include <rtthread.h> @@ -17,9 +16,3 @@ void __exit (int status) __rt_libc_exit(status); while(1); } - -int system(const char * string) -{ - extern int __rt_libc_system(const char *string); - return __rt_libc_system(string); -} |
