From a9910a780edc43df6b64bcd13c37785a15ec3428 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 26 Oct 2021 00:51:32 -0400 Subject: [posix][libc] 优化libc中posix结构 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/dlib/SConscript | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 75a5812fab..3eee0e0184 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_USING_DFS'): + if GetDepend('RT_LIBC_USING_FILEIO'): from distutils.version import LooseVersion from iar import IARVersion @@ -20,7 +20,6 @@ if rtconfig.PLATFORM == 'iar': 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'], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) Return('group') -- cgit v1.3.1 From 4b9fb8f39caae9057a494611e8dae70d2809512d Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Wed, 27 Oct 2021 14:42:25 -0400 Subject: [libc] 消除代码中依赖于RT_LIBC_USING_FILEIO的判断 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/libc/compilers/armlibc/syscalls.c | 42 ++++++++++++------------ components/libc/compilers/dlib/SConscript | 2 +- components/libc/compilers/dlib/syscall_close.c | 4 +-- components/libc/compilers/dlib/syscall_lseek.c | 4 +-- components/libc/compilers/dlib/syscall_open.c | 4 +-- components/libc/compilers/dlib/syscall_read.c | 4 +-- components/libc/compilers/dlib/syscall_write.c | 12 +++---- components/libc/compilers/gcc/newlib/libc.h | 2 ++ components/libc/compilers/gcc/newlib/stdio.c | 43 ++++--------------------- components/libc/compilers/gcc/newlib/syscalls.c | 34 +++++++++---------- 10 files changed, 61 insertions(+), 90 deletions(-) (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index ecb1a9da5a..3b40a5b7b5 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -54,7 +54,7 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int fd; int mode = O_RDONLY; #endif @@ -67,7 +67,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_LIBC_USING_FILEIO +#ifndef RT_USING_POSIX return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -101,19 +101,19 @@ FILEHANDLE _sys_open(const char *name, int openmode) return 0; /* error */ else return fd; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _sys_close(FILEHANDLE fh) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (fh <= STDERR) return 0; /* error */ return close(fh); #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -143,7 +143,7 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; if (fh == STDIN) @@ -168,7 +168,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -178,13 +178,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ if ((fh == STDOUT) || (fh == STDERR)) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard input before initializing libc"); @@ -199,14 +199,14 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } else if (fh == STDIN) { return 0; /* error */ } -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX size = write(fh, buf, len); if (size >= 0) return len - size; @@ -214,7 +214,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /* @@ -223,7 +223,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (fh < STDERR) return 0; /* error */ @@ -231,7 +231,7 @@ int _sys_seek(FILEHANDLE fh, long pos) return lseek(fh, pos, 0); #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } /** @@ -276,7 +276,7 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX struct stat stat; if (fh < STDERR) @@ -286,7 +286,7 @@ long _sys_flen(FILEHANDLE fh) return stat.st_size; #else return 0; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _sys_istty(FILEHANDLE fh) @@ -299,11 +299,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return unlink(filename); #else return 0; /* error */ -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } #ifdef __MICROLIB @@ -324,7 +324,7 @@ int fputc(int c, FILE *f) int fgetc(FILE *f) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX char ch; if (libc_stdio_get_console() < 0) @@ -335,7 +335,7 @@ int fgetc(FILE *f) if(read(STDIN_FILENO, &ch, 1) == 1) return ch; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ return 0; /* error */ } diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 3eee0e0184..348cbf311f 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -11,7 +11,7 @@ CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_LIBC_USING_FILEIO'): + if GetDepend('RT_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index bafe21aa4b..2897c2418a 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -18,9 +18,9 @@ int __close(int handle) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return close(handle); #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 4a3a5c6a46..4ea55ef1c3 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -18,9 +18,9 @@ long __lseek(int handle, long offset, int whence) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_LIBC_USING_FILEIO +#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 891b9afe58..8fb3c3a11f 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -16,7 +16,7 @@ int __open(const char *filename, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int handle; int open_mode = O_RDONLY; @@ -68,5 +68,5 @@ int __open(const char *filename, int mode) return handle; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index f65b502966..447ca03112 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -20,7 +20,7 @@ #pragma module_name = "?__read" size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; if (handle == _LLIO_STDIN) @@ -41,5 +41,5 @@ size_t __read(int handle, unsigned char *buf, size_t len) return size; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index af47d64a3e..ae2d4a1559 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -21,13 +21,13 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int size; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX if (libc_stdio_get_console() < 0) { LOG_W("Do not invoke standard output before initializing libc"); @@ -46,17 +46,17 @@ size_t __write(int handle, const unsigned char *buf, size_t len) return len; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } else if (handle == _LLIO_STDIN) { return _LLIO_ERROR; } -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX size = write(handle, buf, len); return size; #else return _LLIO_ERROR; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } diff --git a/components/libc/compilers/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h index 0ae1057730..2ea27b09f9 100644 --- a/components/libc/compilers/gcc/newlib/libc.h +++ b/components/libc/compilers/gcc/newlib/libc.h @@ -15,11 +15,13 @@ extern "C" { #endif int libc_system_init(void); + #ifdef RT_USING_POSIX int libc_stdio_get_console(void); int libc_stdio_set_console(const char* device_name, int mode); #endif /* RT_USING_POSIX */ + #ifdef __cplusplus } #endif diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c index c0da1b1cec..e6ebc8c303 100644 --- a/components/libc/compilers/gcc/newlib/stdio.c +++ b/components/libc/compilers/gcc/newlib/stdio.c @@ -7,16 +7,14 @@ * Date Author Notes * 2017/10/15 bernard the first version */ -#include +#include +#ifdef RT_USING_POSIX #include +#include #include #include "libc.h" #define STDIO_DEVICE_NAME_MAX 32 - -#ifdef RT_LIBC_USING_FILEIO -#include - static FILE* std_console = NULL; int libc_stdio_set_console(const char* device_name, int mode) @@ -76,7 +74,8 @@ int libc_stdio_set_console(const char* device_name, int mode) _GLOBAL_REENT->__sdidinit = 1; } - if (std_console) return fileno(std_console); + if (std_console) + return fileno(std_console); return -1; } @@ -89,34 +88,4 @@ int libc_stdio_get_console(void) return -1; } -#elif defined(RT_USING_POSIX) -#include -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; -} - -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 6cb60e1776..9e9df3f625 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -175,7 +176,7 @@ int flock(int fd, int operation) _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _off_t rc; rc = lseek(fd, pos, whence); @@ -183,12 +184,12 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = mkdir(name, mode); @@ -196,25 +197,24 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; - rc = open(file, flags, mode); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDIN_FILENO) { @@ -226,12 +226,12 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _rename_r(struct _reent *ptr, const char *old, const char *new) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = rename(old, new); @@ -239,12 +239,12 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX int rc; rc = stat(file, pstat); @@ -252,22 +252,22 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } int _unlink_r(struct _reent *ptr, const char *file) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX return unlink(file); #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ } _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { -#ifdef RT_LIBC_USING_FILEIO +#ifdef RT_USING_POSIX _ssize_t rc; if (libc_stdio_get_console() < 0 && fd == STDOUT_FILENO) { @@ -285,7 +285,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) if (console) return rt_device_write(console, -1, buf, nbytes); } -#endif /* RT_LIBC_USING_FILEIO */ +#endif /* RT_USING_POSIX */ ptr->_errno = ENOTSUP; return -1; } -- cgit v1.3.1 From 7b43cf9793025b0bbb9b2c3bbeedb788edb04f7c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Thu, 28 Oct 2021 02:48:51 -0400 Subject: [libc][posix] move libc.c/.h to posix folder --- components/libc/compilers/armlibc/SConscript | 10 +- components/libc/compilers/armlibc/libc.c | 35 ------ components/libc/compilers/armlibc/libc.h | 29 ----- components/libc/compilers/armlibc/stdio.c | 52 --------- components/libc/compilers/armlibc/syscalls.c | 9 +- components/libc/compilers/common/SConscript | 6 +- components/libc/compilers/dlib/SConscript | 7 +- components/libc/compilers/dlib/libc.c | 35 ------ components/libc/compilers/dlib/libc.h | 28 ----- components/libc/compilers/dlib/stdio.c | 49 -------- components/libc/compilers/dlib/syscall_read.c | 2 + components/libc/compilers/dlib/syscall_write.c | 2 + components/libc/compilers/gcc/newlib/SConscript | 11 +- components/libc/compilers/gcc/newlib/libc.c | 39 ------- components/libc/compilers/gcc/newlib/libc.h | 29 ----- components/libc/compilers/gcc/newlib/stdio.c | 91 --------------- components/libc/compilers/gcc/newlib/syscalls.c | 2 + components/libc/posix/src/SConscript | 5 +- components/libc/posix/src/libc.c | 148 ++++++++++++++++++++++++ components/libc/posix/src/libc.h | 29 +++++ 20 files changed, 199 insertions(+), 419 deletions(-) delete mode 100644 components/libc/compilers/armlibc/libc.c delete mode 100644 components/libc/compilers/armlibc/libc.h delete mode 100644 components/libc/compilers/armlibc/stdio.c delete mode 100644 components/libc/compilers/dlib/libc.c delete mode 100644 components/libc/compilers/dlib/libc.h delete mode 100644 components/libc/compilers/dlib/stdio.c delete mode 100644 components/libc/compilers/gcc/newlib/libc.c delete mode 100644 components/libc/compilers/gcc/newlib/libc.h delete mode 100644 components/libc/compilers/gcc/newlib/stdio.c create mode 100644 components/libc/posix/src/libc.c create mode 100644 components/libc/posix/src/libc.h (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index d77a7c69d5..bf1a299304 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -1,18 +1,12 @@ from building import * Import('rtconfig') -src = Glob('*.c') + Glob('*.cpp') -cwd = GetCurrentDir() +src = Glob('*.c') group = [] -CPPPATH = [cwd] CPPDEFINES = ['RT_USING_ARM_LIBC'] -if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['libc_syms.c']) - if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': - 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/armlibc/libc.c b/components/libc/compilers/armlibc/libc.c deleted file mode 100644 index bc09759fef..0000000000 --- a/components/libc/compilers/armlibc/libc.c +++ /dev/null @@ -1,35 +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 -#include -#include "libc.h" -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#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/armlibc/libc.h b/components/libc/compilers/armlibc/libc.h deleted file mode 100644 index f81380bf78..0000000000 --- a/components/libc/compilers/armlibc/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 - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/armlibc/stdio.c b/components/libc/compilers/armlibc/stdio.c deleted file mode 100644 index e5db167ea4..0000000000 --- a/components/libc/compilers/armlibc/stdio.c +++ /dev/null @@ -1,52 +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 armcc. - */ -#include - -#ifdef RT_USING_POSIX -#include -#include -#include - -#include "libc.h" - -#include -#include - -#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; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 3b40a5b7b5..755ffef1a6 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -14,15 +14,16 @@ * 2020-02-13 Meco Man re-implement exit() and abort() * 2020-02-14 Meco Man implement _sys_tmpnam() */ -#include -#include +#include #include -#include "libc.h" - +#include #include #include #include +#ifdef RT_USING_POSIX +#include "libc.h" +#endif #define DBG_TAG "armlibc.syscalls" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 1c1d645564..bd66b70c7e 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -8,14 +8,14 @@ group = [] CPPPATH = [cwd] CPPDEFINES = [] +if rtconfig.CROSS_TOOL == 'keil': + CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] + if GetDepend('RT_USING_LIBC'): src += Glob('*.c') elif GetDepend('RT_LIBC_USING_TIME'): src += ['time.c'] -if rtconfig.CROSS_TOOL == 'keil': - CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) list = os.listdir(cwd) diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 348cbf311f..39707abc61 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -1,25 +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_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 f6e504bdae..0000000000 --- a/components/libc/compilers/dlib/libc.c +++ /dev/null @@ -1,35 +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 -#include -#include "libc.h" -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#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 292dbde973..0000000000 --- a/components/libc/compilers/dlib/libc.h +++ /dev/null @@ -1,28 +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__ - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - -#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 fea98aedd5..0000000000 --- a/components/libc/compilers/dlib/stdio.c +++ /dev/null @@ -1,49 +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 - -#ifdef RT_USING_POSIX - -#include -#include -#include -#include -#include -#include "libc.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; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 447ca03112..74cedb966a 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -11,7 +11,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #define DBG_TAG "dlib.syscall_read" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index ae2d4a1559..ab011c1096 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -11,7 +11,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #define DBG_TAG "dlib.syscall_write" #define DBG_LVL DBG_INFO diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript index e0ee482747..ae50098dec 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -4,21 +4,14 @@ Import('rtconfig') src = [] cwd = GetCurrentDir() group = [] -LIBS = ['m'] +LIBS = ['m'] # link libm CPPDEFINES = ['RT_USING_NEWLIB'] CPPPATH = [cwd] if rtconfig.PLATFORM == 'gcc': if GetDepend('RT_USING_LIBC'): - # link with libc and libm: - # libm is a frequently used lib. Newlib is compiled with -ffunction-sections in - # recent GCC tool chains. The linker would just link in the functions that have - # been referenced. So setting this won't result in bigger text size. - LIBS += ['c'] - + LIBS += ['c'] # link libc src += Glob('*.c') - if GetDepend('RT_USING_MODULE') == False: - SrcRemove(src, ['libc_syms.c']) else: src += ['syscalls.c'] diff --git a/components/libc/compilers/gcc/newlib/libc.c b/components/libc/compilers/gcc/newlib/libc.c deleted file mode 100644 index 86af026429..0000000000 --- a/components/libc/compilers/gcc/newlib/libc.c +++ /dev/null @@ -1,39 +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 -#include -#include -#include -#include -#include "libc.h" - -#ifdef RT_USING_PTHREADS -#include -#endif - -int libc_system_init(void) -{ -#ifdef RT_USING_POSIX - rt_device_t dev_console; - - dev_console = rt_console_get_device(); - if (dev_console) - { - libc_stdio_set_console(dev_console->parent.name, O_RDWR); - } -#endif /* RT_USING_POSIX */ - -#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/gcc/newlib/libc.h b/components/libc/compilers/gcc/newlib/libc.h deleted file mode 100644 index 2ea27b09f9..0000000000 --- a/components/libc/compilers/gcc/newlib/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__ - -#ifdef __cplusplus -extern "C" { -#endif - -int libc_system_init(void); - -#ifdef RT_USING_POSIX -int libc_stdio_get_console(void); -int libc_stdio_set_console(const char* device_name, int mode); -#endif /* RT_USING_POSIX */ - - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/components/libc/compilers/gcc/newlib/stdio.c b/components/libc/compilers/gcc/newlib/stdio.c deleted file mode 100644 index e6ebc8c303..0000000000 --- a/components/libc/compilers/gcc/newlib/stdio.c +++ /dev/null @@ -1,91 +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 -#ifdef RT_USING_POSIX -#include -#include -#include -#include "libc.h" - -#define STDIO_DEVICE_NAME_MAX 32 -static FILE* std_console = NULL; - -int libc_stdio_set_console(const char* device_name, int mode) -{ - FILE *fp; - char name[STDIO_DEVICE_NAME_MAX]; - char *file_mode; - - snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); - name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; - - if (mode == O_RDWR) - { - file_mode = "r+"; - } - else if (mode == O_WRONLY) - { - file_mode = "wb"; - } - else - { - file_mode = "rb"; - } - - fp = fopen(name, file_mode); - if (fp) - { - setvbuf(fp, NULL, _IONBF, 0); - - if (std_console) - { - fclose(std_console); - std_console = NULL; - } - std_console = fp; - - if (mode == O_RDWR) - { - _GLOBAL_REENT->_stdin = std_console; - } - else - { - _GLOBAL_REENT->_stdin = NULL; - } - - if (mode == O_RDONLY) - { - _GLOBAL_REENT->_stdout = NULL; - _GLOBAL_REENT->_stderr = NULL; - } - else - { - _GLOBAL_REENT->_stdout = std_console; - _GLOBAL_REENT->_stderr = std_console; - } - - _GLOBAL_REENT->__sdidinit = 1; - } - - if (std_console) - return fileno(std_console); - - return -1; -} - -int libc_stdio_get_console(void) -{ - if (std_console) - return fileno(std_console); - else - return -1; -} - -#endif /* RT_USING_POSIX */ diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 9e9df3f625..f95e695a85 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -20,7 +20,9 @@ #include #include #include +#ifdef RT_USING_POSIX #include "libc.h" +#endif #ifdef RT_USING_MODULE #include #endif diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index 5640181ac5..8712d671c0 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -2,9 +2,10 @@ from building import * -cwd = GetCurrentDir() src = Glob('*.c') +cwd = GetCurrentDir() +CPPPATH = [cwd] -group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX']) +group = DefineGroup('POSIX', src, depend = ['RT_USING_POSIX'], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/src/libc.c b/components/libc/posix/src/libc.c new file mode 100644 index 0000000000..84c5a601bc --- /dev/null +++ b/components/libc/posix/src/libc.c @@ -0,0 +1,148 @@ +/* + * 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 +#include +#include +#include +#include +#include +#include +#include "libc.h" +#include +#include +#ifdef RT_USING_PTHREADS +#include +#endif + +int libc_system_init(void) +{ +#ifdef RT_USING_POSIX + rt_device_t dev_console; + + dev_console = rt_console_get_device(); + if (dev_console) + { + libc_stdio_set_console(dev_console->parent.name, O_RDWR); + } +#endif /* RT_USING_POSIX */ + +#if defined RT_USING_PTHREADS && !defined RT_USING_COMPONENTS_INIT + pthread_system_init(); +#endif + + return 0; +} +INIT_COMPONENT_EXPORT(libc_system_init); + +#ifdef RT_USING_POSIX + +#if defined(RT_USING_LIBC) && defined(RT_USING_NEWLIB) +#define STDIO_DEVICE_NAME_MAX 32 +static FILE* std_console = NULL; +int libc_stdio_set_console(const char* device_name, int mode) +{ + FILE *fp; + char name[STDIO_DEVICE_NAME_MAX]; + char *file_mode; + + snprintf(name, sizeof(name) - 1, "/dev/%s", device_name); + name[STDIO_DEVICE_NAME_MAX - 1] = '\0'; + + if (mode == O_RDWR) + { + file_mode = "r+"; + } + else if (mode == O_WRONLY) + { + file_mode = "wb"; + } + else + { + file_mode = "rb"; + } + + fp = fopen(name, file_mode); + if (fp) + { + setvbuf(fp, NULL, _IONBF, 0); + + if (std_console) + { + fclose(std_console); + std_console = NULL; + } + std_console = fp; + + if (mode == O_RDWR) + { + _GLOBAL_REENT->_stdin = std_console; + } + else + { + _GLOBAL_REENT->_stdin = NULL; + } + + if (mode == O_RDONLY) + { + _GLOBAL_REENT->_stdout = NULL; + _GLOBAL_REENT->_stderr = NULL; + } + else + { + _GLOBAL_REENT->_stdout = std_console; + _GLOBAL_REENT->_stderr = std_console; + } + + _GLOBAL_REENT->__sdidinit = 1; + } + + if (std_console) + return fileno(std_console); + + return -1; +} + +int libc_stdio_get_console(void) +{ + if (std_console) + return fileno(std_console); + else + return -1; +} + +#else +#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; +} +#endif /* defined(RT_USING_LIBC) && (defined(__GNUC__) && !defined(__ARMCC_VERSION)) */ +#endif /* RT_USING_POSIX */ diff --git a/components/libc/posix/src/libc.h b/components/libc/posix/src/libc.h new file mode 100644 index 0000000000..f81380bf78 --- /dev/null +++ b/components/libc/posix/src/libc.h @@ -0,0 +1,29 @@ +/* + * 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 + +#ifdef __cplusplus +extern "C" { +#endif + +int libc_system_init(void); +#ifdef RT_USING_POSIX +int libc_stdio_get_console(void); +int libc_stdio_set_console(const char* device_name, int mode); +#endif /* RT_USING_POSIX */ + +#ifdef __cplusplus +} +#endif + +#endif -- cgit v1.3.1 From 973f25901c641f01b19b065a1e263533fc4d8755 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 15 Nov 2021 11:22:49 -0500 Subject: [dfs] move dfs back --- bsp/mini2440/.config | 108 +-- bsp/mini2440/rtconfig.h | 68 +- bsp/qemu-vexpress-a9/.config | 3 + bsp/qemu-vexpress-a9/rtconfig.h | 1 + components/dfs/Kconfig | 4 + components/dfs/SConscript | 3 + components/dfs/include/dfs.h | 8 +- components/dfs/src/dfs.c | 4 +- components/dfs/src/dfs_file.c | 4 +- components/dfs/src/dfs_posix.c | 937 ++++++++++++++++++++++++ components/finsh/SConscript | 2 +- components/finsh/msh.c | 36 +- components/finsh/msh_file.c | 5 +- components/finsh/shell.c | 6 +- components/libc/compilers/armlibc/syscalls.c | 38 +- components/libc/compilers/dlib/SConscript | 2 +- components/libc/compilers/dlib/syscall_close.c | 4 +- components/libc/compilers/dlib/syscall_lseek.c | 4 +- components/libc/compilers/dlib/syscall_open.c | 4 +- components/libc/compilers/dlib/syscall_read.c | 4 +- components/libc/compilers/dlib/syscall_remove.c | 4 +- components/libc/compilers/dlib/syscall_write.c | 8 +- components/libc/compilers/gcc/newlib/syscalls.c | 40 +- components/libc/posix/src/unistd.c | 927 +---------------------- 24 files changed, 1090 insertions(+), 1134 deletions(-) create mode 100644 components/dfs/src/dfs_posix.c (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/bsp/mini2440/.config b/bsp/mini2440/.config index 499dba34f4..afeb2d35a9 100644 --- a/bsp/mini2440/.config +++ b/bsp/mini2440/.config @@ -1,10 +1,14 @@ -# Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) +# +# Automatically generated file; DO NOT EDIT. +# RT-Thread Project Configuration +# CONFIG_BOARD_MINI2440=y # # RT-Thread Kernel # CONFIG_RT_NAME_MAX=8 +# CONFIG_RT_USING_BIG_ENDIAN is not set # CONFIG_RT_USING_ARCH_DATA_TYPE is not set # CONFIG_RT_USING_SMP is not set CONFIG_RT_ALIGN_SIZE=4 @@ -27,8 +31,8 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=512 # # CONFIG_RT_KSERVICE_USING_STDLIB is not set # CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set -# end of kservice optimization - +# CONFIG_RT_USING_ASM_MEMCPY is not set +# CONFIG_RT_USING_TINY_FFS is not set CONFIG_RT_DEBUG=y # CONFIG_RT_DEBUG_COLOR is not set # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -51,7 +55,6 @@ CONFIG_RT_USING_EVENT=y CONFIG_RT_USING_MAILBOX=y CONFIG_RT_USING_MESSAGEQUEUE=y # CONFIG_RT_USING_SIGNALS is not set -# end of Inter-Thread communication # # Memory Management @@ -65,7 +68,6 @@ CONFIG_RT_USING_SMALL_MEM=y # CONFIG_RT_USING_USERHEAP is not set # CONFIG_RT_USING_MEMTRACE is not set CONFIG_RT_USING_HEAP=y -# end of Memory Management # # Kernel Device Object @@ -77,13 +79,11 @@ CONFIG_RT_USING_CONSOLE=y CONFIG_RT_CONSOLEBUF_SIZE=128 CONFIG_RT_CONSOLE_DEVICE_NAME="uart" # CONFIG_RT_PRINTF_LONGLONG is not set -# end of Kernel Device Object - CONFIG_RT_VER_NUM=0x40004 -# end of RT-Thread Kernel - CONFIG_ARCH_ARM=y +# CONFIG_RT_USING_CPU_FFS is not set CONFIG_ARCH_ARM_ARM9=y +# CONFIG_ARCH_CPU_STACK_GROWS_UPWARD is not set # # RT-Thread Components @@ -98,7 +98,6 @@ CONFIG_RT_MAIN_THREAD_PRIORITY=10 # CONFIG_RT_USING_CPLUSPLUS=y # CONFIG_RT_USING_CPLUSPLUS11 is not set -# end of C++ features # # Command shell @@ -118,12 +117,12 @@ CONFIG_FINSH_USING_DESCRIPTION=y # CONFIG_FINSH_ECHO_DISABLE_DEFAULT is not set # CONFIG_FINSH_USING_AUTH is not set CONFIG_FINSH_ARG_MAX=10 -# end of Command shell # # Device virtual file system # CONFIG_RT_USING_DFS=y +CONFIG_DFS_USING_POSIX=y CONFIG_DFS_USING_WORKDIR=y CONFIG_DFS_FILESYSTEMS_MAX=5 CONFIG_DFS_FILESYSTEM_TYPES_MAX=5 @@ -152,13 +151,10 @@ CONFIG_RT_DFS_ELM_MAX_SECTOR_SIZE=512 # CONFIG_RT_DFS_ELM_USE_ERASE is not set CONFIG_RT_DFS_ELM_REENTRANT=y CONFIG_RT_DFS_ELM_MUTEX_TIMEOUT=3000 -# end of elm-chan's FatFs, Generic FAT Filesystem Module - CONFIG_RT_USING_DFS_DEVFS=y # CONFIG_RT_USING_DFS_ROMFS is not set CONFIG_RT_USING_DFS_RAMFS=y # CONFIG_RT_USING_DFS_NFS is not set -# end of Device virtual file system # # Device Drivers @@ -206,27 +202,30 @@ CONFIG_RT_MMCSD_MAX_PARTITION=16 # # Using USB # +# CONFIG_RT_USING_USB is not set # CONFIG_RT_USING_USB_HOST is not set # CONFIG_RT_USING_USB_DEVICE is not set -# end of Using USB -# end of Device Drivers # # POSIX layer and C standard library # CONFIG_RT_USING_LIBC=y -CONFIG_RT_USING_PTHREADS=y -CONFIG_PTHREAD_NUM_MAX=8 -CONFIG_RT_USING_POSIX=y -CONFIG_RT_USING_POSIX_MMAP=y -CONFIG_RT_USING_POSIX_TERMIOS=y -# CONFIG_RT_USING_POSIX_GETLINE is not set -CONFIG_RT_USING_POSIX_AIO=y CONFIG_RT_LIBC_USING_TIME=y +# CONFIG_RT_LIBC_USING_FILEIO is not set CONFIG_RT_USING_MODULE=y CONFIG_RT_USING_CUSTOM_DLMODULE=y CONFIG_RT_LIBC_DEFAULT_TIMEZONE=8 -# end of POSIX layer and C standard library +CONFIG_RT_USING_POSIX=y +# CONFIG_RT_USING_POSIX_STDIO is not set +CONFIG_RT_USING_POSIX_POLL=y +CONFIG_RT_USING_POSIX_SELECT=y +# CONFIG_RT_USING_POSIX_DELAY is not set +# CONFIG_RT_USING_POSIX_GETLINE is not set +CONFIG_RT_USING_POSIX_MMAP=y +CONFIG_RT_USING_POSIX_TERMIOS=y +CONFIG_RT_USING_POSIX_AIO=y +CONFIG_RT_USING_PTHREADS=y +CONFIG_PTHREAD_NUM_MAX=8 # # Network @@ -242,10 +241,7 @@ CONFIG_SAL_INTERNET_CHECK=y # protocol stack implement # CONFIG_SAL_USING_LWIP=y -# end of protocol stack implement - CONFIG_SAL_USING_POSIX=y -# end of Socket abstraction layer # # Network interface device @@ -258,7 +254,7 @@ CONFIG_NETDEV_USING_AUTO_DEFAULT=y # CONFIG_NETDEV_USING_IPV6 is not set CONFIG_NETDEV_IPV4=1 CONFIG_NETDEV_IPV6=0 -# end of Network interface device +# CONFIG_NETDEV_IPV6_SCOPES is not set # # light weight TCP/IP stack @@ -284,8 +280,6 @@ CONFIG_IP_SOF_BROADCAST_RECV=1 CONFIG_RT_LWIP_IPADDR="192.168.0.30" CONFIG_RT_LWIP_GWADDR="192.168.0.1" CONFIG_RT_LWIP_MSKADDR="255.255.255.0" -# end of Static IPv4 Address - CONFIG_RT_LWIP_UDP=y CONFIG_RT_LWIP_TCP=y CONFIG_RT_LWIP_RAW=y @@ -320,22 +314,17 @@ CONFIG_RT_LWIP_STATS=y # CONFIG_RT_LWIP_USING_HW_CHECKSUM is not set CONFIG_RT_LWIP_USING_PING=y # CONFIG_RT_LWIP_DEBUG is not set -# end of light weight TCP/IP stack # # AT commands # # CONFIG_RT_USING_AT is not set -# end of AT commands - # CONFIG_LWIP_USING_DHCPD is not set -# end of Network # # VBUS(Virtual Software BUS) # # CONFIG_RT_USING_VBUS is not set -# end of VBUS(Virtual Software BUS) # # Utilities @@ -347,16 +336,12 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_RT_USING_UTEST is not set # CONFIG_RT_USING_VAR_EXPORT is not set # CONFIG_RT_USING_RT_LINK is not set -# end of Utilities - # CONFIG_RT_USING_LWP is not set -# end of RT-Thread Components # # RT-Thread Utestcases # # CONFIG_RT_USING_UTESTCASES is not set -# end of RT-Thread Utestcases # # RT-Thread online packages @@ -391,17 +376,12 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # Marvell WiFi # # CONFIG_PKG_USING_WLANMARVELL is not set -# end of Marvell WiFi # # Wiced WiFi # # CONFIG_PKG_USING_WLAN_WICED is not set -# end of Wiced WiFi - # CONFIG_PKG_USING_RW007 is not set -# end of Wi-Fi - # CONFIG_PKG_USING_COAP is not set # CONFIG_PKG_USING_NOPOLL is not set # CONFIG_PKG_USING_NETUTILS is not set @@ -423,8 +403,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_JIOT-C-SDK is not set # CONFIG_PKG_USING_UCLOUD_IOT_SDK is not set # CONFIG_PKG_USING_JOYLINK is not set -# end of IoT Cloud - # CONFIG_PKG_USING_NIMBLE is not set # CONFIG_PKG_USING_OTA_DOWNLOADER is not set # CONFIG_PKG_USING_IPMSG is not set @@ -458,7 +436,7 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_LORA_GW_DRIVER_LIB is not set # CONFIG_PKG_USING_LORA_PKT_SNIFFER is not set # CONFIG_PKG_USING_HM is not set -# end of IoT - internet of things +# CONFIG_PKG_USING_SMALL_MODBUS is not set # # security packages @@ -468,7 +446,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_TINYCRYPT is not set # CONFIG_PKG_USING_TFM is not set # CONFIG_PKG_USING_YD_CRYPTO is not set -# end of security packages # # language packages @@ -477,22 +454,19 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_JERRYSCRIPT is not set # CONFIG_PKG_USING_MICROPYTHON is not set # CONFIG_PKG_USING_PIKASCRIPT is not set -# end of language packages # # multimedia packages # -# CONFIG_PKG_USING_OPENMV is not set -# CONFIG_PKG_USING_MUPDF is not set -# CONFIG_PKG_USING_STEMWIN is not set # -# lvgl: powerful and easy-to-use embedded GUI library +# LVGL: powerful and easy-to-use embedded GUI library # # CONFIG_PKG_USING_LITTLEVGL2RTT is not set # CONFIG_PKG_USING_LVGL is not set -# end of lvgl: powerful and easy-to-use embedded GUI library - +# CONFIG_PKG_USING_OPENMV is not set +# CONFIG_PKG_USING_MUPDF is not set +# CONFIG_PKG_USING_STEMWIN is not set # CONFIG_PKG_USING_WAVPLAYER is not set # CONFIG_PKG_USING_TJPGD is not set # CONFIG_PKG_USING_PDFGEN is not set @@ -509,8 +483,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # # CONFIG_PKG_USING_U8G2_OFFICIAL is not set # CONFIG_PKG_USING_U8G2 is not set -# end of u8g2: a monochrome graphic library -# end of multimedia packages # # tools packages @@ -553,7 +525,7 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_MEM_SANDBOX is not set # CONFIG_PKG_USING_SOLAR_TERMS is not set # CONFIG_PKG_USING_GAN_ZHI is not set -# end of tools packages +# CONFIG_PKG_USING_FDT is not set # # system packages @@ -566,7 +538,13 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_QFPLIB_M0_FULL is not set # CONFIG_PKG_USING_QFPLIB_M0_TINY is not set # CONFIG_PKG_USING_QFPLIB_M3 is not set -# end of acceleration: Assembly language or algorithmic acceleration packages + +# +# CMSIS: ARM Cortex-M Microcontroller Software Interface Standard +# +# CONFIG_PKG_USING_CMSIS_5 is not set +# CONFIG_PKG_USING_CMSIS_5_AUX is not set +# CONFIG_PKG_USING_CMSIS_RTOS2 is not set # # Micrium: Micrium software products porting for RT-Thread @@ -577,8 +555,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_UC_CLK is not set # CONFIG_PKG_USING_UC_COMMON is not set # CONFIG_PKG_USING_UC_MODBUS is not set -# end of Micrium: Micrium software products porting for RT-Thread - # CONFIG_PKG_USING_GUIENGINE is not set # CONFIG_PKG_USING_PERSIMMON is not set # CONFIG_PKG_USING_CAIRO is not set @@ -588,7 +564,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_FLASHDB is not set # CONFIG_PKG_USING_SQLITE is not set # CONFIG_PKG_USING_RTI is not set -# CONFIG_PKG_USING_CMSIS is not set # CONFIG_PKG_USING_DFS_YAFFS is not set # CONFIG_PKG_USING_LITTLEFS is not set # CONFIG_PKG_USING_DFS_JFFS2 is not set @@ -613,7 +588,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_WCWIDTH is not set # CONFIG_PKG_USING_MCUBOOT is not set # CONFIG_PKG_USING_TINYUSB is not set -# end of system packages # # peripheral libraries and drivers @@ -689,7 +663,7 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_MISAKA_RGB_BLING is not set # CONFIG_PKG_USING_BL_MCU_SDK is not set # CONFIG_PKG_USING_SOFT_SERIAL is not set -# end of peripheral libraries and drivers +# CONFIG_PKG_USING_MB85RS16 is not set # # AI packages @@ -703,7 +677,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_ULAPACK is not set # CONFIG_PKG_USING_QUEST is not set # CONFIG_PKG_USING_NAXOS is not set -# end of AI packages # # miscellaneous packages @@ -716,7 +689,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_FILESYSTEM_SAMPLES is not set # CONFIG_PKG_USING_NETWORK_SAMPLES is not set # CONFIG_PKG_USING_PERIPHERAL_SAMPLES is not set -# end of samples: kernel and components samples # # entertainment: terminal games and other interesting software packages @@ -730,8 +702,6 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_SNAKE is not set # CONFIG_PKG_USING_TETRIS is not set # CONFIG_PKG_USING_DONUT is not set -# end of entertainment: terminal games and other interesting software packages - # CONFIG_PKG_USING_LIBCSV is not set # CONFIG_PKG_USING_OPTPARSE is not set # CONFIG_PKG_USING_FASTLZ is not set @@ -761,5 +731,3 @@ CONFIG_YMODEM_USING_FILE_TRANSFER=y # CONFIG_PKG_USING_MCURSES is not set # CONFIG_PKG_USING_COWSAY is not set # CONFIG_PKG_USING_TERMBOX is not set -# end of miscellaneous packages -# end of RT-Thread online packages diff --git a/bsp/mini2440/rtconfig.h b/bsp/mini2440/rtconfig.h index 04c746542c..bbdbb5ef67 100644 --- a/bsp/mini2440/rtconfig.h +++ b/bsp/mini2440/rtconfig.h @@ -1,7 +1,9 @@ #ifndef RT_CONFIG_H__ #define RT_CONFIG_H__ -/* Generated by Kconfiglib (https://github.com/ulfalizer/Kconfiglib) */ +/* Automatically generated file; DO NOT EDIT. */ +/* RT-Thread Project Configuration */ + #define BOARD_MINI2440 /* RT-Thread Kernel */ @@ -22,7 +24,6 @@ /* kservice optimization */ -/* end of kservice optimization */ #define RT_DEBUG /* Inter-Thread communication */ @@ -32,7 +33,6 @@ #define RT_USING_EVENT #define RT_USING_MAILBOX #define RT_USING_MESSAGEQUEUE -/* end of Inter-Thread communication */ /* Memory Management */ @@ -40,7 +40,6 @@ #define RT_USING_MEMHEAP #define RT_USING_SMALL_MEM #define RT_USING_HEAP -/* end of Memory Management */ /* Kernel Device Object */ @@ -48,9 +47,7 @@ #define RT_USING_CONSOLE #define RT_CONSOLEBUF_SIZE 128 #define RT_CONSOLE_DEVICE_NAME "uart" -/* end of Kernel Device Object */ #define RT_VER_NUM 0x40004 -/* end of RT-Thread Kernel */ #define ARCH_ARM #define ARCH_ARM_ARM9 @@ -64,7 +61,6 @@ /* C++ features */ #define RT_USING_CPLUSPLUS -/* end of C++ features */ /* Command shell */ @@ -81,11 +77,11 @@ #define MSH_USING_BUILT_IN_COMMANDS #define FINSH_USING_DESCRIPTION #define FINSH_ARG_MAX 10 -/* end of Command shell */ /* Device virtual file system */ #define RT_USING_DFS +#define DFS_USING_POSIX #define DFS_USING_WORKDIR #define DFS_FILESYSTEMS_MAX 5 #define DFS_FILESYSTEM_TYPES_MAX 5 @@ -105,10 +101,8 @@ #define RT_DFS_ELM_MAX_SECTOR_SIZE 512 #define RT_DFS_ELM_REENTRANT #define RT_DFS_ELM_MUTEX_TIMEOUT 3000 -/* end of elm-chan's FatFs, Generic FAT Filesystem Module */ #define RT_USING_DFS_DEVFS #define RT_USING_DFS_RAMFS -/* end of Device virtual file system */ /* Device Drivers */ @@ -131,23 +125,22 @@ /* Using USB */ -/* end of Using USB */ -/* end of Device Drivers */ /* POSIX layer and C standard library */ #define RT_USING_LIBC -#define RT_USING_PTHREADS -#define PTHREAD_NUM_MAX 8 -#define RT_USING_POSIX -#define RT_USING_POSIX_MMAP -#define RT_USING_POSIX_TERMIOS -#define RT_USING_POSIX_AIO #define RT_LIBC_USING_TIME #define RT_USING_MODULE #define RT_USING_CUSTOM_DLMODULE #define RT_LIBC_DEFAULT_TIMEZONE 8 -/* end of POSIX layer and C standard library */ +#define RT_USING_POSIX +#define RT_USING_POSIX_POLL +#define RT_USING_POSIX_SELECT +#define RT_USING_POSIX_MMAP +#define RT_USING_POSIX_TERMIOS +#define RT_USING_POSIX_AIO +#define RT_USING_PTHREADS +#define PTHREAD_NUM_MAX 8 /* Network */ @@ -159,9 +152,7 @@ /* protocol stack implement */ #define SAL_USING_LWIP -/* end of protocol stack implement */ #define SAL_USING_POSIX -/* end of Socket abstraction layer */ /* Network interface device */ @@ -172,7 +163,6 @@ #define NETDEV_USING_AUTO_DEFAULT #define NETDEV_IPV4 1 #define NETDEV_IPV6 0 -/* end of Network interface device */ /* light weight TCP/IP stack */ @@ -191,7 +181,6 @@ #define RT_LWIP_IPADDR "192.168.0.30" #define RT_LWIP_GWADDR "192.168.0.1" #define RT_LWIP_MSKADDR "255.255.255.0" -/* end of Static IPv4 Address */ #define RT_LWIP_UDP #define RT_LWIP_TCP #define RT_LWIP_RAW @@ -220,28 +209,21 @@ #define LWIP_NETIF_LOOPBACK 1 #define RT_LWIP_STATS #define RT_LWIP_USING_PING -/* end of light weight TCP/IP stack */ /* AT commands */ -/* end of AT commands */ -/* end of Network */ /* VBUS(Virtual Software BUS) */ -/* end of VBUS(Virtual Software BUS) */ /* Utilities */ #define RT_USING_RYM #define YMODEM_USING_CRC_TABLE #define YMODEM_USING_FILE_TRANSFER -/* end of Utilities */ -/* end of RT-Thread Components */ /* RT-Thread Utestcases */ -/* end of RT-Thread Utestcases */ /* RT-Thread online packages */ @@ -252,71 +234,53 @@ /* Marvell WiFi */ -/* end of Marvell WiFi */ /* Wiced WiFi */ -/* end of Wiced WiFi */ -/* end of Wi-Fi */ /* IoT Cloud */ -/* end of IoT Cloud */ -/* end of IoT - internet of things */ /* security packages */ -/* end of security packages */ /* language packages */ -/* end of language packages */ /* multimedia packages */ +/* LVGL: powerful and easy-to-use embedded GUI library */ -/* lvgl: powerful and easy-to-use embedded GUI library */ - -/* end of lvgl: powerful and easy-to-use embedded GUI library */ /* u8g2: a monochrome graphic library */ -/* end of u8g2: a monochrome graphic library */ -/* end of multimedia packages */ /* tools packages */ -/* end of tools packages */ /* system packages */ /* acceleration: Assembly language or algorithmic acceleration packages */ -/* end of acceleration: Assembly language or algorithmic acceleration packages */ + +/* CMSIS: ARM Cortex-M Microcontroller Software Interface Standard */ + /* Micrium: Micrium software products porting for RT-Thread */ -/* end of Micrium: Micrium software products porting for RT-Thread */ -/* end of system packages */ /* peripheral libraries and drivers */ -/* end of peripheral libraries and drivers */ /* AI packages */ -/* end of AI packages */ /* miscellaneous packages */ /* samples: kernel and components samples */ -/* end of samples: kernel and components samples */ /* entertainment: terminal games and other interesting software packages */ -/* end of entertainment: terminal games and other interesting software packages */ -/* end of miscellaneous packages */ -/* end of RT-Thread online packages */ #endif diff --git a/bsp/qemu-vexpress-a9/.config b/bsp/qemu-vexpress-a9/.config index 37ff3cbd45..4b777fd9ed 100644 --- a/bsp/qemu-vexpress-a9/.config +++ b/bsp/qemu-vexpress-a9/.config @@ -33,6 +33,7 @@ CONFIG_RT_TIMER_THREAD_STACK_SIZE=1024 # CONFIG_RT_KSERVICE_USING_STDLIB is not set # CONFIG_RT_KSERVICE_USING_TINY_SIZE is not set # CONFIG_RT_USING_ASM_MEMCPY is not set +# CONFIG_RT_USING_TINY_FFS is not set CONFIG_RT_DEBUG=y CONFIG_RT_DEBUG_COLOR=y # CONFIG_RT_DEBUG_INIT_CONFIG is not set @@ -126,6 +127,7 @@ CONFIG_FINSH_ARG_MAX=10 # Device virtual file system # CONFIG_RT_USING_DFS=y +CONFIG_DFS_USING_POSIX=y CONFIG_DFS_USING_WORKDIR=y CONFIG_DFS_FILESYSTEMS_MAX=4 CONFIG_DFS_FILESYSTEM_TYPES_MAX=8 @@ -541,6 +543,7 @@ CONFIG_RT_USING_LWP=y # CONFIG_PKG_USING_MEM_SANDBOX is not set # CONFIG_PKG_USING_SOLAR_TERMS is not set # CONFIG_PKG_USING_GAN_ZHI is not set +# CONFIG_PKG_USING_FDT is not set # # system packages diff --git a/bsp/qemu-vexpress-a9/rtconfig.h b/bsp/qemu-vexpress-a9/rtconfig.h index b0a94bfe08..b03ac43c81 100644 --- a/bsp/qemu-vexpress-a9/rtconfig.h +++ b/bsp/qemu-vexpress-a9/rtconfig.h @@ -90,6 +90,7 @@ /* Device virtual file system */ #define RT_USING_DFS +#define DFS_USING_POSIX #define DFS_USING_WORKDIR #define DFS_FILESYSTEMS_MAX 4 #define DFS_FILESYSTEM_TYPES_MAX 8 diff --git a/components/dfs/Kconfig b/components/dfs/Kconfig index 1ec36784d7..b93c65512b 100644 --- a/components/dfs/Kconfig +++ b/components/dfs/Kconfig @@ -8,6 +8,10 @@ config RT_USING_DFS The device file system is a light weight virtual file system. if RT_USING_DFS + config DFS_USING_POSIX + bool "Using posix-like functions, open/read/write/close" + default y + config DFS_USING_WORKDIR bool "Using working directory" default y diff --git a/components/dfs/SConscript b/components/dfs/SConscript index 5a0b394ce2..790fbd3efe 100644 --- a/components/dfs/SConscript +++ b/components/dfs/SConscript @@ -9,6 +9,9 @@ src/dfs_fs.c cwd = GetCurrentDir() CPPPATH = [cwd + "/include"] +if GetDepend('DFS_USING_POSIX'): + src += ['src/dfs_posix.c'] + group = DefineGroup('Filesystem', src, depend = ['RT_USING_DFS'], CPPPATH = CPPPATH) if GetDepend('RT_USING_DFS'): diff --git a/components/dfs/include/dfs.h b/components/dfs/include/dfs.h index 38f19aa7e7..678ff0e377 100644 --- a/components/dfs/include/dfs.h +++ b/components/dfs/include/dfs.h @@ -81,16 +81,18 @@ int dfs_init(void); char *dfs_normalize_path(const char *directory, const char *filename); const char *dfs_subdir(const char *directory, const char *filename); +int fd_is_open(const char *pathname); +struct dfs_fdtable *dfs_fdtable_get(void); + void dfs_lock(void); void dfs_unlock(void); +#ifdef DFS_USING_POSIX /* FD APIs */ int fd_new(void); struct dfs_fd *fd_get(int fd); void fd_put(struct dfs_fd *fd); -int fd_is_open(const char *pathname); - -struct dfs_fdtable *dfs_fdtable_get(void); +#endif /* DFS_USING_POSIX */ #ifdef __cplusplus } diff --git a/components/dfs/src/dfs.c b/components/dfs/src/dfs.c index 29b2068a6c..47ea0b0a23 100644 --- a/components/dfs/src/dfs.c +++ b/components/dfs/src/dfs.c @@ -34,7 +34,6 @@ char working_directory[DFS_PATH_MAX] = {"/"}; #endif static struct dfs_fdtable _fdtab; -static int fd_alloc(struct dfs_fdtable *fdt, int startfd); /** * @addtogroup DFS @@ -118,6 +117,7 @@ void dfs_unlock(void) rt_mutex_release(&fslock); } +#ifdef DFS_USING_POSIX static int fd_alloc(struct dfs_fdtable *fdt, int startfd) { int idx; @@ -276,6 +276,8 @@ void fd_put(struct dfs_fd *fd) dfs_unlock(); } +#endif /* DFS_USING_POSIX */ + /** * @ingroup Fd * diff --git a/components/dfs/src/dfs_file.c b/components/dfs/src/dfs_file.c index 978c1056c2..711a461e20 100644 --- a/components/dfs/src/dfs_file.c +++ b/components/dfs/src/dfs_file.c @@ -621,7 +621,7 @@ void cat(const char *filename) } FINSH_FUNCTION_EXPORT(cat, print file); -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX #define BUF_SZ 4096 static void copyfile(const char *src, const char *dst) { @@ -843,7 +843,7 @@ void copy(const char *src, const char *dst) } } FINSH_FUNCTION_EXPORT(copy, copy file or dir) -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ #endif /* RT_USING_FINSH */ /* @} */ diff --git a/components/dfs/src/dfs_posix.c b/components/dfs/src/dfs_posix.c new file mode 100644 index 0000000000..e6336c2544 --- /dev/null +++ b/components/dfs/src/dfs_posix.c @@ -0,0 +1,937 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2009-05-27 Yi.qiu The first version + * 2018-02-07 Bernard Change the 3rd parameter of open/fcntl/ioctl to '...' + */ + +#include +#include +#include + +/** + * this function is a POSIX compliant version, which will open a file and + * return a file descriptor according specified flags. + * + * @param file the path name of file. + * @param flags the file open flags. + * + * @return the non-negative integer on successful open, others for failed. + */ +int open(const char *file, int flags, ...) +{ + int fd, result; + struct dfs_fd *d; + + /* allocate a fd */ + fd = fd_new(); + if (fd < 0) + { + rt_set_errno(-ENOMEM); + + return -1; + } + d = fd_get(fd); + + result = dfs_file_open(d, file, flags); + if (result < 0) + { + /* release the ref-count of fd */ + fd_put(d); + fd_put(d); + + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return fd; +} +RTM_EXPORT(open); + +/** + * this function is a POSIX compliant version, which will close the open + * file descriptor. + * + * @param fd the file descriptor. + * + * @return 0 on successful, -1 on failed. + */ +int close(int fd) +{ + int result; + struct dfs_fd *d; + + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + result = dfs_file_close(d); + fd_put(d); + + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + fd_put(d); + + return 0; +} +RTM_EXPORT(close); + +/** + * this function is a POSIX compliant version, which will read specified data + * buffer length for an open file descriptor. + * + * @param fd the file descriptor. + * @param buf the buffer to save the read data. + * @param len the maximal length of data buffer + * + * @return the actual read data buffer length. If the returned value is 0, it + * may be reach the end of file, please check errno. + */ +#ifdef _READ_WRITE_RETURN_TYPE +_READ_WRITE_RETURN_TYPE read(int fd, void *buf, size_t len) /* some gcc tool chains will use different data structure */ +#else +ssize_t read(int fd, void *buf, size_t len) +#endif +{ + int result; + struct dfs_fd *d; + + /* get the fd */ + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + result = dfs_file_read(d, buf, len); + if (result < 0) + { + fd_put(d); + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return result; +} +RTM_EXPORT(read); + +/** + * this function is a POSIX compliant version, which will write specified data + * buffer length for an open file descriptor. + * + * @param fd the file descriptor + * @param buf the data buffer to be written. + * @param len the data buffer length. + * + * @return the actual written data buffer length. + */ +#ifdef _READ_WRITE_RETURN_TYPE +_READ_WRITE_RETURN_TYPE write(int fd, const void *buf, size_t len) /* some gcc tool chains will use different data structure */ +#else +ssize_t write(int fd, const void *buf, size_t len) +#endif +{ + int result; + struct dfs_fd *d; + + /* get the fd */ + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + result = dfs_file_write(d, buf, len); + if (result < 0) + { + fd_put(d); + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return result; +} +RTM_EXPORT(write); + +/** + * this function is a POSIX compliant version, which will seek the offset for + * an open file descriptor. + * + * @param fd the file descriptor. + * @param offset the offset to be seeked. + * @param whence the directory of seek. + * + * @return the current read/write position in the file, or -1 on failed. + */ +off_t lseek(int fd, off_t offset, int whence) +{ + int result; + struct dfs_fd *d; + + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + switch (whence) + { + case SEEK_SET: + break; + + case SEEK_CUR: + offset += d->pos; + break; + + case SEEK_END: + offset += d->size; + break; + + default: + fd_put(d); + rt_set_errno(-EINVAL); + + return -1; + } + + if (offset < 0) + { + fd_put(d); + rt_set_errno(-EINVAL); + + return -1; + } + result = dfs_file_lseek(d, offset); + if (result < 0) + { + fd_put(d); + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return offset; +} +RTM_EXPORT(lseek); + +#ifndef _WIN32 +/** + * this function is a POSIX compliant version, which will rename old file name + * to new file name. + * + * @param old the old file name. + * @param new the new file name. + * + * @return 0 on successful, -1 on failed. + * + * note: the old and new file name must be belong to a same file system. + */ +int rename(const char *old_file, const char *new_file) +{ + int result; + + result = dfs_file_rename(old_file, new_file); + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + return 0; +} +RTM_EXPORT(rename); +#endif + +/** + * this function is a POSIX compliant version, which will unlink (remove) a + * specified path file from file system. + * + * @param pathname the specified path name to be unlinked. + * + * @return 0 on successful, -1 on failed. + */ +int unlink(const char *pathname) +{ + int result; + + result = dfs_file_unlink(pathname); + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + return 0; +} +RTM_EXPORT(unlink); + +/** + * this function is a POSIX compliant version, which will get file information. + * + * @param file the file name + * @param buf the data buffer to save stat description. + * + * @return 0 on successful, -1 on failed. + */ +int stat(const char *file, struct stat *buf) +{ + int result; + + result = dfs_file_stat(file, buf); + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + return result; +} +RTM_EXPORT(stat); + +/** + * this function is a POSIX compliant version, which will get file status. + * + * @param fildes the file description + * @param buf the data buffer to save stat description. + * + * @return 0 on successful, -1 on failed. + */ +int fstat(int fildes, struct stat *buf) +{ + struct dfs_fd *d; + + /* get the fd */ + d = fd_get(fildes); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + /* it's the root directory */ + buf->st_dev = 0; + + buf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | + S_IWUSR | S_IWGRP | S_IWOTH; + if (d->type == FT_DIRECTORY) + { + buf->st_mode &= ~S_IFREG; + buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; + } + + buf->st_size = d->size; + buf->st_mtime = 0; + + fd_put(d); + + return RT_EOK; +} +RTM_EXPORT(fstat); + +/** + * this function is a POSIX compliant version, which shall request that all data + * for the open file descriptor named by fildes is to be transferred to the storage + * device associated with the file described by fildes. + * + * @param fildes the file description + * + * @return 0 on successful completion. Otherwise, -1 shall be returned and errno + * set to indicate the error. + */ +int fsync(int fildes) +{ + int ret; + struct dfs_fd *d; + + /* get the fd */ + d = fd_get(fildes); + if (d == NULL) + { + rt_set_errno(-EBADF); + return -1; + } + + ret = dfs_file_flush(d); + + fd_put(d); + return ret; +} +RTM_EXPORT(fsync); + +/** + * this function is a POSIX compliant version, which shall perform a variety of + * control functions on devices. + * + * @param fildes the file description + * @param cmd the specified command + * @param data represents the additional information that is needed by this + * specific device to perform the requested function. + * + * @return 0 on successful completion. Otherwise, -1 shall be returned and errno + * set to indicate the error. + */ +int fcntl(int fildes, int cmd, ...) +{ + int ret = -1; + struct dfs_fd *d; + + /* get the fd */ + d = fd_get(fildes); + if (d) + { + void *arg; + va_list ap; + + va_start(ap, cmd); + arg = va_arg(ap, void *); + va_end(ap); + + ret = dfs_file_ioctl(d, cmd, arg); + fd_put(d); + } + else ret = -EBADF; + + if (ret < 0) + { + rt_set_errno(ret); + ret = -1; + } + + return ret; +} +RTM_EXPORT(fcntl); + +/** + * this function is a POSIX compliant version, which shall perform a variety of + * control functions on devices. + * + * @param fildes the file description + * @param cmd the specified command + * @param data represents the additional information that is needed by this + * specific device to perform the requested function. + * + * @return 0 on successful completion. Otherwise, -1 shall be returned and errno + * set to indicate the error. + */ +int ioctl(int fildes, int cmd, ...) +{ + void *arg; + va_list ap; + + va_start(ap, cmd); + arg = va_arg(ap, void *); + va_end(ap); + + /* we use fcntl for this API. */ + return fcntl(fildes, cmd, arg); +} +RTM_EXPORT(ioctl); + +/** + * + * this function is a POSIX compliant version, which cause the regular file + * referenced by fd to be truncated to a size of precisely length bytes. + * @param fd the file descriptor. + * @param length the length to be truncated. + * + * @return Upon successful completion, ftruncate() shall return 0; + * otherwise, -1 shall be returned and errno set to indicate the error. + */ +int ftruncate(int fd, off_t length) +{ + int result; + struct dfs_fd *d; + + d = fd_get(fd); + if (d == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + if (length < 0) + { + fd_put(d); + rt_set_errno(-EINVAL); + + return -1; + } + result = dfs_file_ftruncate(d, length); + if (result < 0) + { + fd_put(d); + rt_set_errno(result); + + return -1; + } + + /* release the ref-count of fd */ + fd_put(d); + + return 0; +} +RTM_EXPORT(ftruncate); + +/** + * this function is a POSIX compliant version, which will return the + * information about a mounted file system. + * + * @param path the path which mounted file system. + * @param buf the buffer to save the returned information. + * + * @return 0 on successful, others on failed. + */ +int statfs(const char *path, struct statfs *buf) +{ + int result; + + result = dfs_statfs(path, buf); + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + return result; +} +RTM_EXPORT(statfs); + +/** + * this function is a POSIX compliant version, which will make a directory + * + * @param path the directory path to be made. + * @param mode + * + * @return 0 on successful, others on failed. + */ +int mkdir(const char *path, mode_t mode) +{ + int fd; + struct dfs_fd *d; + int result; + + fd = fd_new(); + if (fd == -1) + { + rt_set_errno(-ENOMEM); + + return -1; + } + + d = fd_get(fd); + + result = dfs_file_open(d, path, O_DIRECTORY | O_CREAT); + + if (result < 0) + { + fd_put(d); + fd_put(d); + rt_set_errno(result); + + return -1; + } + + dfs_file_close(d); + fd_put(d); + fd_put(d); + + return 0; +} +RTM_EXPORT(mkdir); + +/** + * this function is a POSIX compliant version, which will remove a directory. + * + * @param pathname the path name to be removed. + * + * @return 0 on successful, others on failed. + */ +int rmdir(const char *pathname) +{ + int result; + + result = dfs_file_unlink(pathname); + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + + return 0; +} +RTM_EXPORT(rmdir); + +/** + * this function is a POSIX compliant version, which will open a directory. + * + * @param name the path name to be open. + * + * @return the DIR pointer of directory, NULL on open directory failed. + */ +DIR *opendir(const char *name) +{ + struct dfs_fd *d; + int fd, result; + DIR *t; + + t = NULL; + + /* allocate a fd */ + fd = fd_new(); + if (fd == -1) + { + rt_set_errno(-ENOMEM); + + return NULL; + } + d = fd_get(fd); + + result = dfs_file_open(d, name, O_RDONLY | O_DIRECTORY); + if (result >= 0) + { + /* open successfully */ + t = (DIR *) rt_malloc(sizeof(DIR)); + if (t == NULL) + { + dfs_file_close(d); + fd_put(d); + } + else + { + memset(t, 0, sizeof(DIR)); + + t->fd = fd; + } + fd_put(d); + + return t; + } + + /* open failed */ + fd_put(d); + fd_put(d); + rt_set_errno(result); + + return NULL; +} +RTM_EXPORT(opendir); + +/** + * this function is a POSIX compliant version, which will return a pointer + * to a dirent structure representing the next directory entry in the + * directory stream. + * + * @param d the directory stream pointer. + * + * @return the next directory entry, NULL on the end of directory or failed. + */ +struct dirent *readdir(DIR *d) +{ + int result; + struct dfs_fd *fd; + + fd = fd_get(d->fd); + if (fd == NULL) + { + rt_set_errno(-EBADF); + return NULL; + } + + if (d->num) + { + struct dirent *dirent_ptr; + dirent_ptr = (struct dirent *)&d->buf[d->cur]; + d->cur += dirent_ptr->d_reclen; + } + + if (!d->num || d->cur >= d->num) + { + /* get a new entry */ + result = dfs_file_getdents(fd, + (struct dirent *)d->buf, + sizeof(d->buf) - 1); + if (result <= 0) + { + fd_put(fd); + rt_set_errno(result); + + return NULL; + } + + d->num = result; + d->cur = 0; /* current entry index */ + } + + fd_put(fd); + + return (struct dirent *)(d->buf + d->cur); +} +RTM_EXPORT(readdir); + +/** + * this function is a POSIX compliant version, which will return current + * location in directory stream. + * + * @param d the directory stream pointer. + * + * @return the current location in directory stream. + */ +long telldir(DIR *d) +{ + struct dfs_fd *fd; + long result; + + fd = fd_get(d->fd); + if (fd == NULL) + { + rt_set_errno(-EBADF); + + return 0; + } + + result = fd->pos - d->num + d->cur; + fd_put(fd); + + return result; +} +RTM_EXPORT(telldir); + +/** + * this function is a POSIX compliant version, which will set position of + * next directory structure in the directory stream. + * + * @param d the directory stream. + * @param offset the offset in directory stream. + */ +void seekdir(DIR *d, off_t offset) +{ + struct dfs_fd *fd; + + fd = fd_get(d->fd); + if (fd == NULL) + { + rt_set_errno(-EBADF); + + return ; + } + + /* seek to the offset position of directory */ + if (dfs_file_lseek(fd, offset) >= 0) + d->num = d->cur = 0; + fd_put(fd); +} +RTM_EXPORT(seekdir); + +/** + * this function is a POSIX compliant version, which will reset directory + * stream. + * + * @param d the directory stream. + */ +void rewinddir(DIR *d) +{ + struct dfs_fd *fd; + + fd = fd_get(d->fd); + if (fd == NULL) + { + rt_set_errno(-EBADF); + + return ; + } + + /* seek to the beginning of directory */ + if (dfs_file_lseek(fd, 0) >= 0) + d->num = d->cur = 0; + fd_put(fd); +} +RTM_EXPORT(rewinddir); + +/** + * this function is a POSIX compliant version, which will close a directory + * stream. + * + * @param d the directory stream. + * + * @return 0 on successful, -1 on failed. + */ +int closedir(DIR *d) +{ + int result; + struct dfs_fd *fd; + + fd = fd_get(d->fd); + if (fd == NULL) + { + rt_set_errno(-EBADF); + + return -1; + } + + result = dfs_file_close(fd); + fd_put(fd); + + fd_put(fd); + rt_free(d); + + if (result < 0) + { + rt_set_errno(result); + + return -1; + } + else + return 0; +} +RTM_EXPORT(closedir); + +#ifdef DFS_USING_WORKDIR +/** + * this function is a POSIX compliant version, which will change working + * directory. + * + * @param path the path name to be changed to. + * + * @return 0 on successful, -1 on failed. + */ +int chdir(const char *path) +{ + char *fullpath; + DIR *d; + + if (path == NULL) + { + dfs_lock(); + rt_kprintf("%s\n", working_directory); + dfs_unlock(); + + return 0; + } + + if (strlen(path) > DFS_PATH_MAX) + { + rt_set_errno(-ENOTDIR); + + return -1; + } + + fullpath = dfs_normalize_path(NULL, path); + if (fullpath == NULL) + { + rt_set_errno(-ENOTDIR); + + return -1; /* build path failed */ + } + + dfs_lock(); + d = opendir(fullpath); + if (d == NULL) + { + rt_free(fullpath); + /* this is a not exist directory */ + dfs_unlock(); + + return -1; + } + + /* close directory stream */ + closedir(d); + + /* copy full path to working directory */ + strncpy(working_directory, fullpath, DFS_PATH_MAX); + /* release normalize directory path name */ + rt_free(fullpath); + + dfs_unlock(); + + return 0; +} +RTM_EXPORT(chdir); + +#ifdef RT_USING_FINSH +FINSH_FUNCTION_EXPORT_ALIAS(chdir, cd, change current working directory); +#endif +#endif + +/** + * this function is a POSIX compliant version, which shall check the file named + * by the pathname pointed to by the path argument for accessibility according + * to the bit pattern contained in amode. + * + * @param path the specified file/dir path. + * @param amode the value is either the bitwise-inclusive OR of the access + * permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK). + */ +int access(const char *path, int amode) +{ + struct stat sb; + if (stat(path, &sb) < 0) + return -1; /* already sets errno */ + + /* ignore R_OK,W_OK,X_OK condition */ + return 0; +} + +/** + * this function is a POSIX compliant version, which will return current + * working directory. + * + * @param buf the returned current directory. + * @param size the buffer size. + * + * @return the returned current directory. + */ +char *getcwd(char *buf, size_t size) +{ +#ifdef DFS_USING_WORKDIR + dfs_lock(); + strncpy(buf, working_directory, size); + dfs_unlock(); +#else + rt_kprintf(NO_WORKING_DIR); +#endif + + return buf; +} +RTM_EXPORT(getcwd); diff --git a/components/finsh/SConscript b/components/finsh/SConscript index 5eabe47c0e..9b2faa2283 100644 --- a/components/finsh/SConscript +++ b/components/finsh/SConscript @@ -9,7 +9,7 @@ msh.c if GetDepend('MSH_USING_BUILT_IN_COMMANDS'): src += ['cmd.c'] -if GetDepend('RT_USING_POSIX'): +if GetDepend('DFS_USING_POSIX'): src += ['msh_file.c'] CPPPATH = [cwd] diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 5cb54c26e7..727f343a68 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -15,19 +15,17 @@ #ifdef RT_USING_FINSH #ifndef FINSH_ARG_MAX - #define FINSH_ARG_MAX 8 -#endif +#define FINSH_ARG_MAX 8 +#endif /* FINSH_ARG_MAX */ #include "msh.h" #include "shell.h" - -#ifdef RT_USING_POSIX - #include -#endif - +#ifdef DFS_USING_POSIX +#include +#endif /* DFS_USING_POSIX */ #ifdef RT_USING_MODULE - #include -#endif +#include +#endif /* RT_USING_MODULE */ typedef int (*cmd_function_t)(int argc, char **argv); @@ -186,7 +184,7 @@ static cmd_function_t msh_get_cmd(char *cmd, int size) return cmd_func; } -#if defined(RT_USING_MODULE) && defined(RT_USING_POSIX) +#if defined(RT_USING_MODULE) && defined(DFS_USING_POSIX) /* Return 0 on module executed. Other value indicate error. */ int msh_exec_module(const char *cmd_line, int size) @@ -257,7 +255,7 @@ int msh_exec_module(const char *cmd_line, int size) rt_free(pg_name); return ret; } -#endif /* defined(RT_USING_MODULE) && defined(RT_USING_POSIX) */ +#endif /* defined(RT_USING_MODULE) && defined(DFS_USING_POSIX) */ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) { @@ -290,7 +288,7 @@ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) return 0; } -#if defined(RT_USING_LWP) && defined(RT_USING_POSIX) +#if defined(RT_USING_LWP) && defined(DFS_USING_POSIX) static int _msh_exec_lwp(char *cmd, rt_size_t length) { int argc; @@ -326,7 +324,7 @@ static int _msh_exec_lwp(char *cmd, rt_size_t length) return 0; } -#endif /* defined(RT_USING_LWP) && defined(RT_USING_DFS) */ +#endif /* defined(RT_USING_LWP) && defined(DFS_USING_POSIX) */ int msh_exec(char *cmd, rt_size_t length) { @@ -350,7 +348,7 @@ int msh_exec(char *cmd, rt_size_t length) { return cmd_ret; } -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX #ifdef DFS_USING_WORKDIR if (msh_exec_script(cmd, length) == 0) { @@ -371,7 +369,7 @@ int msh_exec(char *cmd, rt_size_t length) return 0; } #endif /* RT_USING_LWP */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ /* truncate the cmd at the first space. */ { @@ -400,7 +398,7 @@ static int str_common(const char *str1, const char *str2) return (str - str1); } -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX void msh_auto_complete_path(char *path) { DIR *dir = RT_NULL; @@ -521,7 +519,7 @@ void msh_auto_complete_path(char *path) closedir(dir); rt_free(full_path); } -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ void msh_auto_complete(char *prefix) { @@ -538,7 +536,7 @@ void msh_auto_complete(char *prefix) return; } -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX /* check whether a spare in the command */ { char *ptr; @@ -564,7 +562,7 @@ void msh_auto_complete(char *prefix) } #endif /* RT_USING_MODULE */ } -#endif /* RT_USING_DFS */ +#endif /* DFS_USING_POSIX */ /* checks in internal command */ { diff --git a/components/finsh/msh_file.c b/components/finsh/msh_file.c index 4e9ed53b31..9dcb820c44 100644 --- a/components/finsh/msh_file.c +++ b/components/finsh/msh_file.c @@ -11,7 +11,7 @@ #include -#if defined(RT_USING_FINSH) && defined(RT_USING_POSIX) +#if defined(RT_USING_FINSH) && defined(DFS_USING_POSIX) #include #include "msh.h" @@ -702,5 +702,4 @@ static int cmd_tail(int argc, char **argv) } MSH_CMD_EXPORT_ALIAS(cmd_tail, tail, print the last N - lines data of the given file); -#endif /* defined(RT_USING_FINSH) && defined(RT_USING_POSIX) */ - +#endif /* defined(RT_USING_FINSH) && defined(DFS_USING_POSIX) */ diff --git a/components/finsh/shell.c b/components/finsh/shell.c index c2f6e2a550..5b96d0daf9 100644 --- a/components/finsh/shell.c +++ b/components/finsh/shell.c @@ -27,9 +27,9 @@ #include "shell.h" #include "msh.h" -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX #include -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ /* finsh thread */ #ifndef RT_USING_HEAP @@ -104,7 +104,7 @@ const char *finsh_get_prompt(void) } strcpy(finsh_prompt, _MSH_PROMPT); -#if defined(RT_USING_POSIX) && defined(DFS_USING_WORKDIR) +#if defined(DFS_USING_POSIX) && defined(DFS_USING_WORKDIR) /* get current working directory */ getcwd(&finsh_prompt[rt_strlen(finsh_prompt)], RT_CONSOLEBUF_SIZE - rt_strlen(finsh_prompt)); #endif diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index b6448f2165..71eacb1c41 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -33,7 +33,7 @@ __asm(".global __use_no_semihosting\n\t"); #else #pragma import(__use_no_semihosting_swi) -#endif +#endif /* __CLANG_ARM */ /* Standard IO device handles. */ #define STDIN 0 @@ -55,10 +55,10 @@ const char __stderr_name[] = "STDERR"; */ FILEHANDLE _sys_open(const char *name, int openmode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int fd; int mode = O_RDONLY; -#endif +#endif /* DFS_USING_POSIX */ /* Register standard Input Output devices. */ if (strcmp(name, __stdin_name) == 0) @@ -68,7 +68,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) if (strcmp(name, __stderr_name) == 0) return (STDERR); -#ifndef RT_USING_POSIX +#ifndef DFS_USING_POSIX return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -102,19 +102,19 @@ FILEHANDLE _sys_open(const char *name, int openmode) return 0; /* error */ else return fd; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _sys_close(FILEHANDLE fh) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX if (fh <= STDERR) return 0; /* error */ return close(fh); #else return 0; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /* @@ -144,7 +144,7 @@ int _sys_close(FILEHANDLE fh) */ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; if (fh == STDIN) @@ -175,7 +175,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) } #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /* @@ -189,9 +189,9 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) */ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ if (fh == STDOUT || fh == STDERR) { @@ -213,7 +213,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) } else { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX size = write(fh, buf, len); if (size >= 0) return 0; /* success */ @@ -221,7 +221,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; /* error */ #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } } @@ -231,7 +231,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) */ int _sys_seek(FILEHANDLE fh, long pos) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX if (fh < STDERR) return 0; /* error */ @@ -239,7 +239,7 @@ int _sys_seek(FILEHANDLE fh, long pos) return lseek(fh, pos, 0); #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /** @@ -284,7 +284,7 @@ RT_WEAK void _sys_exit(int return_code) */ long _sys_flen(FILEHANDLE fh) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX struct stat stat; if (fh < STDERR) @@ -294,7 +294,7 @@ long _sys_flen(FILEHANDLE fh) return stat.st_size; #else return 0; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _sys_istty(FILEHANDLE fh) @@ -307,11 +307,11 @@ int _sys_istty(FILEHANDLE fh) int remove(const char *filename) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return unlink(filename); #else return 0; /* error */ -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } #ifdef __MICROLIB diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 39707abc61..f685873e16 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -7,7 +7,7 @@ group = [] CPPDEFINES = ['RT_USING_DLIBC'] if rtconfig.PLATFORM == 'iar': - if GetDepend('RT_USING_POSIX'): + if GetDepend('DFS_USING_POSIX'): from distutils.version import LooseVersion from iar import IARVersion diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index aef9673153..30ee6f2388 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -24,9 +24,9 @@ int __close(int handle) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return close(handle); #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index b1547f699e..622f613c51 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -33,9 +33,9 @@ long __lseek(int handle, long offset, int whence) handle == _LLIO_STDERR || handle == _LLIO_STDIN) return _LLIO_ERROR; -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return lseek(handle, offset, whence); #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 3336bc8885..66cddc83c1 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -21,7 +21,7 @@ int __open(const char *filename, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int handle; int open_mode = O_RDONLY; @@ -73,5 +73,5 @@ int __open(const char *filename, int mode) return handle; #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index e88f88ead4..469ea7c1dd 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -34,7 +34,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; if (handle == _LLIO_STDIN) @@ -59,5 +59,5 @@ size_t __read(int handle, unsigned char *buf, size_t len) return size; /* return the length of the data read */ #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index cf6541132a..870f91b8c1 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -20,9 +20,9 @@ int remove(const char *filename) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return unlink(filename); #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index 9a7707e9d3..d5ede3e59e 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -37,9 +37,9 @@ size_t __write(int handle, const unsigned char *buf, size_t len) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int size; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ if ((handle == _LLIO_STDOUT) || (handle == _LLIO_STDERR)) { @@ -63,11 +63,11 @@ size_t __write(int handle, const unsigned char *buf, size_t len) } else { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX size = write(handle, buf, len); return size; /* return the length of the data written */ #else return _LLIO_ERROR; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } } diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index f3a2f5bfcf..8bb9af940d 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -109,12 +109,12 @@ int _getpid_r(struct _reent *ptr) int _close_r(struct _reent *ptr, int fd) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return close(fd); #else ptr->_errno = ENOTSUP; return -1; -#endif +#endif /* DFS_USING_POSIX */ } int _execve_r(struct _reent *ptr, const char * name, char *const *argv, char *const *env) @@ -183,7 +183,7 @@ int flock(int fd, int operation) _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX _off_t rc; rc = lseek(fd, pos, whence); @@ -191,12 +191,12 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _mkdir_r(struct _reent *ptr, const char *name, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = mkdir(name, mode); @@ -204,24 +204,24 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _open_r(struct _reent *ptr, const char *file, int flags, int mode) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = open(file, flags, mode); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX _ssize_t rc; if (fd == STDIN_FILENO) { @@ -247,12 +247,12 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _rename_r(struct _reent *ptr, const char *old, const char *new) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = rename(old, new); @@ -260,12 +260,12 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX int rc; rc = stat(file, pstat); @@ -273,24 +273,24 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } int _unlink_r(struct _reent *ptr, const char *file) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX return unlink(file); #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) { -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX _ssize_t rc; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ if (fd == STDOUT_FILENO || fd == STDERR_FILENO) { @@ -311,13 +311,13 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) return -1; } -#ifdef RT_USING_POSIX +#ifdef DFS_USING_POSIX rc = write(fd, buf, nbytes); return rc; #else ptr->_errno = ENOTSUP; return -1; -#endif /* RT_USING_POSIX */ +#endif /* DFS_USING_POSIX */ } /* for exit() and abort() */ diff --git a/components/libc/posix/src/unistd.c b/components/libc/posix/src/unistd.c index 85235965ea..cb18dd3499 100644 --- a/components/libc/posix/src/unistd.c +++ b/components/libc/posix/src/unistd.c @@ -8,935 +8,10 @@ * 2020-09-01 Meco Man first Version * 2021-02-12 Meco Man move all functions located in to this file */ + #include -#include -#include -#include #include -/** - * this function is a POSIX compliant version, which will open a file and - * return a file descriptor according specified flags. - * - * @param file the path name of file. - * @param flags the file open flags. - * - * @return the non-negative integer on successful open, others for failed. - */ -int open(const char *file, int flags, ...) -{ - int fd, result; - struct dfs_fd *d; - - /* allocate a fd */ - fd = fd_new(); - if (fd < 0) - { - rt_set_errno(-ENOMEM); - - return -1; - } - d = fd_get(fd); - - result = dfs_file_open(d, file, flags); - if (result < 0) - { - /* release the ref-count of fd */ - fd_put(d); - fd_put(d); - - rt_set_errno(result); - - return -1; - } - - /* release the ref-count of fd */ - fd_put(d); - - return fd; -} -RTM_EXPORT(open); - -/** - * this function is a POSIX compliant version, which will close the open - * file descriptor. - * - * @param fd the file descriptor. - * - * @return 0 on successful, -1 on failed. - */ -int close(int fd) -{ - int result; - struct dfs_fd *d; - - d = fd_get(fd); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - result = dfs_file_close(d); - fd_put(d); - - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - fd_put(d); - - return 0; -} -RTM_EXPORT(close); - -/** - * this function is a POSIX compliant version, which will read specified data - * buffer length for an open file descriptor. - * - * @param fd the file descriptor. - * @param buf the buffer to save the read data. - * @param len the maximal length of data buffer - * - * @return the actual read data buffer length. If the returned value is 0, it - * may be reach the end of file, please check errno. - */ -#ifdef _READ_WRITE_RETURN_TYPE -_READ_WRITE_RETURN_TYPE read(int fd, void *buf, size_t len) /* some gcc tool chains will use different data structure */ -#else -ssize_t read(int fd, void *buf, size_t len) -#endif -{ - int result; - struct dfs_fd *d; - - /* get the fd */ - d = fd_get(fd); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - result = dfs_file_read(d, buf, len); - if (result < 0) - { - fd_put(d); - rt_set_errno(result); - - return -1; - } - - /* release the ref-count of fd */ - fd_put(d); - - return result; -} -RTM_EXPORT(read); - -/** - * this function is a POSIX compliant version, which will write specified data - * buffer length for an open file descriptor. - * - * @param fd the file descriptor - * @param buf the data buffer to be written. - * @param len the data buffer length. - * - * @return the actual written data buffer length. - */ -#ifdef _READ_WRITE_RETURN_TYPE -_READ_WRITE_RETURN_TYPE write(int fd, const void *buf, size_t len) /* some gcc tool chains will use different data structure */ -#else -ssize_t write(int fd, const void *buf, size_t len) -#endif -{ - int result; - struct dfs_fd *d; - - /* get the fd */ - d = fd_get(fd); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - result = dfs_file_write(d, buf, len); - if (result < 0) - { - fd_put(d); - rt_set_errno(result); - - return -1; - } - - /* release the ref-count of fd */ - fd_put(d); - - return result; -} -RTM_EXPORT(write); - -/** - * this function is a POSIX compliant version, which will seek the offset for - * an open file descriptor. - * - * @param fd the file descriptor. - * @param offset the offset to be seeked. - * @param whence the directory of seek. - * - * @return the current read/write position in the file, or -1 on failed. - */ -off_t lseek(int fd, off_t offset, int whence) -{ - int result; - struct dfs_fd *d; - - d = fd_get(fd); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - switch (whence) - { - case SEEK_SET: - break; - - case SEEK_CUR: - offset += d->pos; - break; - - case SEEK_END: - offset += d->size; - break; - - default: - fd_put(d); - rt_set_errno(-EINVAL); - - return -1; - } - - if (offset < 0) - { - fd_put(d); - rt_set_errno(-EINVAL); - - return -1; - } - result = dfs_file_lseek(d, offset); - if (result < 0) - { - fd_put(d); - rt_set_errno(result); - - return -1; - } - - /* release the ref-count of fd */ - fd_put(d); - - return offset; -} -RTM_EXPORT(lseek); - -#ifndef _WIN32 /* we can not implement these functions */ -/** - * this function is a POSIX compliant version, which will rename old file name - * to new file name. - * - * @param old the old file name. - * @param new the new file name. - * - * @return 0 on successful, -1 on failed. - * - * note: the old and new file name must be belong to a same file system. - */ -int rename(const char *old_file, const char *new_file) -{ - int result; - - result = dfs_file_rename(old_file, new_file); - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - return 0; -} -RTM_EXPORT(rename); -#endif - -/** - * this function is a POSIX compliant version, which will unlink (remove) a - * specified path file from file system. - * - * @param pathname the specified path name to be unlinked. - * - * @return 0 on successful, -1 on failed. - */ -int unlink(const char *pathname) -{ - int result; - - result = dfs_file_unlink(pathname); - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - return 0; -} -RTM_EXPORT(unlink); - -/** - * this function is a POSIX compliant version, which will get file information. - * - * @param file the file name - * @param buf the data buffer to save stat description. - * - * @return 0 on successful, -1 on failed. - */ -int stat(const char *file, struct stat *buf) -{ - int result; - - result = dfs_file_stat(file, buf); - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - return result; -} -RTM_EXPORT(stat); - -/** - * this function is a POSIX compliant version, which will get file status. - * - * @param fildes the file description - * @param buf the data buffer to save stat description. - * - * @return 0 on successful, -1 on failed. - */ -int fstat(int fildes, struct stat *buf) -{ - struct dfs_fd *d; - - /* get the fd */ - d = fd_get(fildes); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - /* it's the root directory */ - buf->st_dev = 0; - - buf->st_mode = S_IFREG | S_IRUSR | S_IRGRP | S_IROTH | - S_IWUSR | S_IWGRP | S_IWOTH; - if (d->type == FT_DIRECTORY) - { - buf->st_mode &= ~S_IFREG; - buf->st_mode |= S_IFDIR | S_IXUSR | S_IXGRP | S_IXOTH; - } - - buf->st_size = d->size; - buf->st_mtime = 0; - - fd_put(d); - - return RT_EOK; -} -RTM_EXPORT(fstat); - -/** - * this function is a POSIX compliant version, which shall request that all data - * for the open file descriptor named by fildes is to be transferred to the storage - * device associated with the file described by fildes. - * - * @param fildes the file description - * - * @return 0 on successful completion. Otherwise, -1 shall be returned and errno - * set to indicate the error. - */ -int fsync(int fildes) -{ - int ret; - struct dfs_fd *d; - - /* get the fd */ - d = fd_get(fildes); - if (d == NULL) - { - rt_set_errno(-EBADF); - return -1; - } - - ret = dfs_file_flush(d); - - fd_put(d); - return ret; -} -RTM_EXPORT(fsync); - -/** - * this function is a POSIX compliant version, which shall perform a variety of - * control functions on devices. - * - * @param fildes the file description - * @param cmd the specified command - * @param data represents the additional information that is needed by this - * specific device to perform the requested function. - * - * @return 0 on successful completion. Otherwise, -1 shall be returned and errno - * set to indicate the error. - */ -int fcntl(int fildes, int cmd, ...) -{ - int ret = -1; - struct dfs_fd *d; - - /* get the fd */ - d = fd_get(fildes); - if (d) - { - void *arg; - va_list ap; - - va_start(ap, cmd); - arg = va_arg(ap, void *); - va_end(ap); - - ret = dfs_file_ioctl(d, cmd, arg); - fd_put(d); - } - else ret = -EBADF; - - if (ret < 0) - { - rt_set_errno(ret); - ret = -1; - } - - return ret; -} -RTM_EXPORT(fcntl); - -/** - * this function is a POSIX compliant version, which shall perform a variety of - * control functions on devices. - * - * @param fildes the file description - * @param cmd the specified command - * @param data represents the additional information that is needed by this - * specific device to perform the requested function. - * - * @return 0 on successful completion. Otherwise, -1 shall be returned and errno - * set to indicate the error. - */ -int ioctl(int fildes, int cmd, ...) -{ - void *arg; - va_list ap; - - va_start(ap, cmd); - arg = va_arg(ap, void *); - va_end(ap); - - /* we use fcntl for this API. */ - return fcntl(fildes, cmd, arg); -} -RTM_EXPORT(ioctl); - -/** - * - * this function is a POSIX compliant version, which cause the regular file - * referenced by fd to be truncated to a size of precisely length bytes. - * @param fd the file descriptor. - * @param length the length to be truncated. - * - * @return Upon successful completion, ftruncate() shall return 0; - * otherwise, -1 shall be returned and errno set to indicate the error. - */ -int ftruncate(int fd, off_t length) -{ - int result; - struct dfs_fd *d; - - d = fd_get(fd); - if (d == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - if (length < 0) - { - fd_put(d); - rt_set_errno(-EINVAL); - - return -1; - } - result = dfs_file_ftruncate(d, length); - if (result < 0) - { - fd_put(d); - rt_set_errno(result); - - return -1; - } - - /* release the ref-count of fd */ - fd_put(d); - - return 0; -} -RTM_EXPORT(ftruncate); - -/** - * this function is a POSIX compliant version, which will return the - * information about a mounted file system. - * - * @param path the path which mounted file system. - * @param buf the buffer to save the returned information. - * - * @return 0 on successful, others on failed. - */ -int statfs(const char *path, struct statfs *buf) -{ - int result; - - result = dfs_statfs(path, buf); - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - return result; -} -RTM_EXPORT(statfs); - -/** - * this function is a POSIX compliant version, which will make a directory - * - * @param path the directory path to be made. - * @param mode - * - * @return 0 on successful, others on failed. - */ -int mkdir(const char *path, mode_t mode) -{ - int fd; - struct dfs_fd *d; - int result; - - fd = fd_new(); - if (fd == -1) - { - rt_set_errno(-ENOMEM); - - return -1; - } - - d = fd_get(fd); - - result = dfs_file_open(d, path, O_DIRECTORY | O_CREAT); - - if (result < 0) - { - fd_put(d); - fd_put(d); - rt_set_errno(result); - - return -1; - } - - dfs_file_close(d); - fd_put(d); - fd_put(d); - - return 0; -} -RTM_EXPORT(mkdir); - -/** - * this function is a POSIX compliant version, which will remove a directory. - * - * @param pathname the path name to be removed. - * - * @return 0 on successful, others on failed. - */ -int rmdir(const char *pathname) -{ - int result; - - result = dfs_file_unlink(pathname); - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - - return 0; -} -RTM_EXPORT(rmdir); - -/** - * this function is a POSIX compliant version, which will open a directory. - * - * @param name the path name to be open. - * - * @return the DIR pointer of directory, NULL on open directory failed. - */ -DIR *opendir(const char *name) -{ - struct dfs_fd *d; - int fd, result; - DIR *t; - - t = NULL; - - /* allocate a fd */ - fd = fd_new(); - if (fd == -1) - { - rt_set_errno(-ENOMEM); - - return NULL; - } - d = fd_get(fd); - - result = dfs_file_open(d, name, O_RDONLY | O_DIRECTORY); - if (result >= 0) - { - /* open successfully */ - t = (DIR *) rt_malloc(sizeof(DIR)); - if (t == NULL) - { - dfs_file_close(d); - fd_put(d); - } - else - { - memset(t, 0, sizeof(DIR)); - - t->fd = fd; - } - fd_put(d); - - return t; - } - - /* open failed */ - fd_put(d); - fd_put(d); - rt_set_errno(result); - - return NULL; -} -RTM_EXPORT(opendir); - -/** - * this function is a POSIX compliant version, which will return a pointer - * to a dirent structure representing the next directory entry in the - * directory stream. - * - * @param d the directory stream pointer. - * - * @return the next directory entry, NULL on the end of directory or failed. - */ -struct dirent *readdir(DIR *d) -{ - int result; - struct dfs_fd *fd; - - fd = fd_get(d->fd); - if (fd == NULL) - { - rt_set_errno(-EBADF); - return NULL; - } - - if (d->num) - { - struct dirent *dirent_ptr; - dirent_ptr = (struct dirent *)&d->buf[d->cur]; - d->cur += dirent_ptr->d_reclen; - } - - if (!d->num || d->cur >= d->num) - { - /* get a new entry */ - result = dfs_file_getdents(fd, - (struct dirent *)d->buf, - sizeof(d->buf) - 1); - if (result <= 0) - { - fd_put(fd); - rt_set_errno(result); - - return NULL; - } - - d->num = result; - d->cur = 0; /* current entry index */ - } - - fd_put(fd); - - return (struct dirent *)(d->buf + d->cur); -} -RTM_EXPORT(readdir); - -/** - * this function is a POSIX compliant version, which will return current - * location in directory stream. - * - * @param d the directory stream pointer. - * - * @return the current location in directory stream. - */ -long telldir(DIR *d) -{ - struct dfs_fd *fd; - long result; - - fd = fd_get(d->fd); - if (fd == NULL) - { - rt_set_errno(-EBADF); - - return 0; - } - - result = fd->pos - d->num + d->cur; - fd_put(fd); - - return result; -} -RTM_EXPORT(telldir); - -/** - * this function is a POSIX compliant version, which will set position of - * next directory structure in the directory stream. - * - * @param d the directory stream. - * @param offset the offset in directory stream. - */ -void seekdir(DIR *d, off_t offset) -{ - struct dfs_fd *fd; - - fd = fd_get(d->fd); - if (fd == NULL) - { - rt_set_errno(-EBADF); - - return ; - } - - /* seek to the offset position of directory */ - if (dfs_file_lseek(fd, offset) >= 0) - d->num = d->cur = 0; - fd_put(fd); -} -RTM_EXPORT(seekdir); - -/** - * this function is a POSIX compliant version, which will reset directory - * stream. - * - * @param d the directory stream. - */ -void rewinddir(DIR *d) -{ - struct dfs_fd *fd; - - fd = fd_get(d->fd); - if (fd == NULL) - { - rt_set_errno(-EBADF); - - return ; - } - - /* seek to the beginning of directory */ - if (dfs_file_lseek(fd, 0) >= 0) - d->num = d->cur = 0; - fd_put(fd); -} -RTM_EXPORT(rewinddir); - -/** - * this function is a POSIX compliant version, which will close a directory - * stream. - * - * @param d the directory stream. - * - * @return 0 on successful, -1 on failed. - */ -int closedir(DIR *d) -{ - int result; - struct dfs_fd *fd; - - fd = fd_get(d->fd); - if (fd == NULL) - { - rt_set_errno(-EBADF); - - return -1; - } - - result = dfs_file_close(fd); - fd_put(fd); - - fd_put(fd); - rt_free(d); - - if (result < 0) - { - rt_set_errno(result); - - return -1; - } - else - return 0; -} -RTM_EXPORT(closedir); - -#ifdef DFS_USING_WORKDIR -/** - * this function is a POSIX compliant version, which will change working - * directory. - * - * @param path the path name to be changed to. - * - * @return 0 on successful, -1 on failed. - */ -int chdir(const char *path) -{ - char *fullpath; - DIR *d; - - if (path == NULL) - { - dfs_lock(); - rt_kprintf("%s\n", working_directory); - dfs_unlock(); - - return 0; - } - - if (strlen(path) > DFS_PATH_MAX) - { - rt_set_errno(-ENOTDIR); - - return -1; - } - - fullpath = dfs_normalize_path(NULL, path); - if (fullpath == NULL) - { - rt_set_errno(-ENOTDIR); - - return -1; /* build path failed */ - } - - dfs_lock(); - d = opendir(fullpath); - if (d == NULL) - { - rt_free(fullpath); - /* this is a not exist directory */ - dfs_unlock(); - - return -1; - } - - /* close directory stream */ - closedir(d); - - /* copy full path to working directory */ - strncpy(working_directory, fullpath, DFS_PATH_MAX); - /* release normalize directory path name */ - rt_free(fullpath); - - dfs_unlock(); - - return 0; -} -RTM_EXPORT(chdir); - -#ifdef RT_USING_FINSH -FINSH_FUNCTION_EXPORT_ALIAS(chdir, cd, change current working directory); -#endif -#endif - -/** - * this function is a POSIX compliant version, which shall check the file named - * by the pathname pointed to by the path argument for accessibility according - * to the bit pattern contained in amode. - * - * @param path the specified file/dir path. - * @param amode the value is either the bitwise-inclusive OR of the access - * permissions to be checked (R_OK, W_OK, X_OK) or the existence test (F_OK). - */ -int access(const char *path, int amode) -{ - struct stat sb; - if (stat(path, &sb) < 0) - return -1; /* already sets errno */ - - /* ignore R_OK,W_OK,X_OK condition */ - return 0; -} - -/** - * this function is a POSIX compliant version, which will return current - * working directory. - * - * @param buf the returned current directory. - * @param size the buffer size. - * - * @return the returned current directory. - */ -char *getcwd(char *buf, size_t size) -{ -#ifdef DFS_USING_WORKDIR - dfs_lock(); - strncpy(buf, working_directory, size); - dfs_unlock(); -#else - rt_kprintf(NO_WORKING_DIR); -#endif - - return buf; -} -RTM_EXPORT(getcwd); - #ifdef RT_USING_POSIX_TERMIOS #include "termios.h" int isatty(int fd) -- cgit v1.3.1 From ed09f38012131850cd67c1392554653b56a37341 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Sun, 26 Dec 2021 09:41:24 -0500 Subject: [libc] remove RT_USING_LIBC --- bsp/at32/at32f403a-start/board/Kconfig | 1 - bsp/at32/at32f407-start/board/Kconfig | 1 - bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig | 1 - ...210\266\344\275\234\346\225\231\347\250\213.md" | 1 - bsp/hc32f4a0/board/Kconfig | 1 - bsp/hk32/hk32f030c8-mini/board/Kconfig | 1 - bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig | 1 - bsp/maxim/MAX32660_EVSYS/board/Kconfig | 1 - bsp/nrf5x/nrf52832/board/Kconfig | 1 - bsp/nrf5x/nrf52840/board/Kconfig | 1 - .../docs/How to make a STM32 BSP for RT-Thread.md | 1 - ...210\266\344\275\234\346\225\231\347\250\213.md" | 1 - .../libraries/templates/stm32l1xx/board/Kconfig | 1 - .../libraries/templates/stm32wbxx/board/Kconfig | 1 - .../libraries/templates/stm32xx_board_Kconfig | 1 - bsp/stm32/stm32f407-armfly-v5/board/Kconfig | 1 - bsp/stm32/stm32f746-st-nucleo/board/Kconfig | 1 - bsp/stm32/stm32l475-atk-pandora/board/Kconfig | 1 - bsp/swm320-lq100/drivers/Kconfig | 1 - bsp/swm320/drivers/Kconfig | 1 - bsp/tae32f5300/drivers/Kconfig | 1 - bsp/tm4c123bsp/board/Kconfig | 1 - components/cplusplus/Kconfig | 4 +- components/cplusplus/README.md | 2 - components/cplusplus/cpp11/armclang/thread.cpp | 4 +- components/cplusplus/cpp11/gcc/mutex | 4 +- components/cplusplus/cpp11/gcc/mutex.cpp | 4 +- components/cplusplus/cpp11/gcc/thread | 2 +- components/cplusplus/cpp11/gcc/thread.cpp | 20 +++--- components/dfs/filesystems/elmfat/dfs_elm.c | 2 - components/libc/Kconfig | 32 ++------- components/libc/compilers/armlibc/README.md | 6 -- components/libc/compilers/armlibc/SConscript | 2 +- components/libc/compilers/armlibc/mem_std.c | 71 ------------------ components/libc/compilers/armlibc/syscall_mem.c | 71 ++++++++++++++++++ components/libc/compilers/armlibc/syscalls.c | 14 +++- components/libc/compilers/common/SConscript | 7 +- .../libc/compilers/common/compiler_private.c | 13 ++++ .../libc/compilers/common/compiler_private.h | 18 +++++ components/libc/compilers/common/nogcc/SConscript | 5 +- components/libc/compilers/common/time.c | 18 ++--- components/libc/compilers/dlib/README.md | 6 -- components/libc/compilers/dlib/SConscript | 2 +- components/libc/compilers/dlib/syscall_close.c | 5 ++ components/libc/compilers/dlib/syscall_lseek.c | 5 ++ components/libc/compilers/dlib/syscall_mem.c | 2 +- components/libc/compilers/dlib/syscall_open.c | 84 ++++++++++++---------- components/libc/compilers/dlib/syscall_read.c | 8 ++- components/libc/compilers/dlib/syscall_remove.c | 5 ++ components/libc/compilers/dlib/syscall_write.c | 4 +- components/libc/compilers/gcc/newlib/README.md | 6 -- components/libc/compilers/gcc/newlib/SConscript | 9 +-- components/libc/compilers/gcc/newlib/syscalls.c | 22 +++--- components/libc/libdl/arch/riscv.c | 10 +-- components/libc/posix/Kconfig | 5 +- components/libc/posix/io/libc.c | 6 +- components/libc/posix/signal/SConscript | 2 +- components/lwp/Kconfig | 1 - components/net/lwip-2.1.2/src/lwipopts.h | 4 -- components/utilities/Kconfig | 1 - 60 files changed, 248 insertions(+), 260 deletions(-) delete mode 100644 components/libc/compilers/armlibc/mem_std.c create mode 100644 components/libc/compilers/armlibc/syscall_mem.c create mode 100644 components/libc/compilers/common/compiler_private.c create mode 100644 components/libc/compilers/common/compiler_private.h (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/bsp/at32/at32f403a-start/board/Kconfig b/bsp/at32/at32f403a-start/board/Kconfig index 9816ab4729..f16afc9bfe 100644 --- a/bsp/at32/at32f403a-start/board/Kconfig +++ b/bsp/at32/at32f403a-start/board/Kconfig @@ -31,7 +31,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_RTC choice diff --git a/bsp/at32/at32f407-start/board/Kconfig b/bsp/at32/at32f407-start/board/Kconfig index 5a3b46274c..c0c63ed753 100644 --- a/bsp/at32/at32f407-start/board/Kconfig +++ b/bsp/at32/at32f407-start/board/Kconfig @@ -37,7 +37,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_RTC choice diff --git a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig index 3f52d1798e..8c7d93c61a 100644 --- a/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig +++ b/bsp/bluetrum/ab32vg1-ab-prougen/board/Kconfig @@ -204,7 +204,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC config RTC_USING_INTERNAL_CLK diff --git "a/bsp/gd32/docs/GD32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" "b/bsp/gd32/docs/GD32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" index 8f50f631c9..6a894cc54a 100644 --- "a/bsp/gd32/docs/GD32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" +++ "b/bsp/gd32/docs/GD32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" @@ -918,7 +918,6 @@ GD32 BSP 的制作规范主要分为 3 个方面:工程配置,ENV 配置和 - 系统空闲线程栈大小统一设置为 256(宏:IDLE_THREAD_STACK_SIZE) - 开启组件自动初始化(宏:RT_USING_COMPONENTS_INIT) - 需要开启 user main 选项(宏:RT_USING_USER_MAIN) -- 默认关闭 libc(宏:RT_USING_LIBC) - FinSH 默认只使用 MSH 模式(宏:FINSH_USING_MSH_ONLY) #### 4.1.3 IDE 配置 diff --git a/bsp/hc32f4a0/board/Kconfig b/bsp/hc32f4a0/board/Kconfig index c33c82d89e..77eaf83ea2 100644 --- a/bsp/hc32f4a0/board/Kconfig +++ b/bsp/hc32f4a0/board/Kconfig @@ -219,7 +219,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_RTC diff --git a/bsp/hk32/hk32f030c8-mini/board/Kconfig b/bsp/hk32/hk32f030c8-mini/board/Kconfig index 16b2d23878..34025eda33 100644 --- a/bsp/hk32/hk32f030c8-mini/board/Kconfig +++ b/bsp/hk32/hk32f030c8-mini/board/Kconfig @@ -31,7 +31,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_RTC choice diff --git a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig index 94669d3736..ffd90e53f2 100644 --- a/bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig +++ b/bsp/lpc55sxx/lpc55s69_nxp_evk/board/Kconfig @@ -137,7 +137,6 @@ menu "On-chip Peripheral Drivers" select RT_USING_SDIO select RT_USING_DFS select RT_USING_DFS_ELMFAT - select RT_LIBC_USING_TIME default y config BSP_USING_RTC diff --git a/bsp/maxim/MAX32660_EVSYS/board/Kconfig b/bsp/maxim/MAX32660_EVSYS/board/Kconfig index 5a470ca469..63fd7067b2 100644 --- a/bsp/maxim/MAX32660_EVSYS/board/Kconfig +++ b/bsp/maxim/MAX32660_EVSYS/board/Kconfig @@ -84,7 +84,6 @@ menu "On-chip Peripheral Drivers" config BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n endmenu diff --git a/bsp/nrf5x/nrf52832/board/Kconfig b/bsp/nrf5x/nrf52832/board/Kconfig index bc61640851..61881a78fd 100644 --- a/bsp/nrf5x/nrf52832/board/Kconfig +++ b/bsp/nrf5x/nrf52832/board/Kconfig @@ -390,7 +390,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC config NRFX_CLOCK_ENABLED diff --git a/bsp/nrf5x/nrf52840/board/Kconfig b/bsp/nrf5x/nrf52840/board/Kconfig index 12c921fc7f..f52beb2f31 100644 --- a/bsp/nrf5x/nrf52840/board/Kconfig +++ b/bsp/nrf5x/nrf52840/board/Kconfig @@ -374,7 +374,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n diff --git a/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md b/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md index 2b677e7dfb..b5e84671d0 100644 --- a/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md +++ b/bsp/stm32/docs/How to make a STM32 BSP for RT-Thread.md @@ -221,7 +221,6 @@ The specifications of making STM32 BSP are mainly divided into three aspects: en - The system idle thread stack size is uniformly set to 256 (Macro: IDLE_THREAD_STACK_SIZE) - Turn on automatic component initialization (Macro: RT_USING_COMPONENTS_INIT) - Need to enable the user main option (Macro: RT_USING_USER_MAIN) -- Disable libc by default (Macro: RT_USING_LIBC) - FinSH only uses MSH mode by default (Macro: FINSH_USING_MSH_ONLY) #### 4.1.3 IDE configuration diff --git "a/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" "b/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" index 5d09fddf50..91eca7e3a0 100644 --- "a/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" +++ "b/bsp/stm32/docs/STM32\347\263\273\345\210\227BSP\345\210\266\344\275\234\346\225\231\347\250\213.md" @@ -269,7 +269,6 @@ STM32 BSP 的制作规范主要分为 3 个方面:工程配置,ENV 配置和 - 系统空闲线程栈大小统一设置为 256(宏:IDLE_THREAD_STACK_SIZE) - 开启组件自动初始化(宏:RT_USING_COMPONENTS_INIT) - 需要开启 user main 选项(宏:RT_USING_USER_MAIN) -- 默认关闭 libc(宏:RT_USING_LIBC) - FinSH 默认只使用 MSH 模式(宏:FINSH_USING_MSH_ONLY) #### 4.1.3 IDE 配置 diff --git a/bsp/stm32/libraries/templates/stm32l1xx/board/Kconfig b/bsp/stm32/libraries/templates/stm32l1xx/board/Kconfig index 1bfdf4513b..3ec4eedb99 100644 --- a/bsp/stm32/libraries/templates/stm32l1xx/board/Kconfig +++ b/bsp/stm32/libraries/templates/stm32l1xx/board/Kconfig @@ -187,7 +187,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/bsp/stm32/libraries/templates/stm32wbxx/board/Kconfig b/bsp/stm32/libraries/templates/stm32wbxx/board/Kconfig index 3a5a05b63f..428a7d3592 100644 --- a/bsp/stm32/libraries/templates/stm32wbxx/board/Kconfig +++ b/bsp/stm32/libraries/templates/stm32wbxx/board/Kconfig @@ -143,7 +143,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/bsp/stm32/libraries/templates/stm32xx_board_Kconfig b/bsp/stm32/libraries/templates/stm32xx_board_Kconfig index 42c8528c60..ba8f7bd25b 100644 --- a/bsp/stm32/libraries/templates/stm32xx_board_Kconfig +++ b/bsp/stm32/libraries/templates/stm32xx_board_Kconfig @@ -151,7 +151,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/bsp/stm32/stm32f407-armfly-v5/board/Kconfig b/bsp/stm32/stm32f407-armfly-v5/board/Kconfig index 7c6b8a97f0..5073e6e7a4 100644 --- a/bsp/stm32/stm32f407-armfly-v5/board/Kconfig +++ b/bsp/stm32/stm32f407-armfly-v5/board/Kconfig @@ -162,7 +162,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/bsp/stm32/stm32f746-st-nucleo/board/Kconfig b/bsp/stm32/stm32f746-st-nucleo/board/Kconfig index 8aba5902a6..83868f1a5d 100644 --- a/bsp/stm32/stm32f746-st-nucleo/board/Kconfig +++ b/bsp/stm32/stm32f746-st-nucleo/board/Kconfig @@ -193,7 +193,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig index 627ef48251..767c446a13 100644 --- a/bsp/stm32/stm32l475-atk-pandora/board/Kconfig +++ b/bsp/stm32/stm32l475-atk-pandora/board/Kconfig @@ -148,7 +148,6 @@ menu "Onboard Peripheral Drivers" select RT_USING_WIFI select RT_WLAN_PROT_LWIP_PBUF_FORCE select RT_USING_LWIP - select RT_USING_LIBC select RT_USING_DFS select DFS_USING_POSIX select PKG_USING_FAL diff --git a/bsp/swm320-lq100/drivers/Kconfig b/bsp/swm320-lq100/drivers/Kconfig index 2ad515ae90..6858ab0568 100644 --- a/bsp/swm320-lq100/drivers/Kconfig +++ b/bsp/swm320-lq100/drivers/Kconfig @@ -236,7 +236,6 @@ menu "On-chip Peripheral Drivers" config BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n menuconfig BSP_USING_SPI diff --git a/bsp/swm320/drivers/Kconfig b/bsp/swm320/drivers/Kconfig index 2ad515ae90..6858ab0568 100644 --- a/bsp/swm320/drivers/Kconfig +++ b/bsp/swm320/drivers/Kconfig @@ -236,7 +236,6 @@ menu "On-chip Peripheral Drivers" config BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n menuconfig BSP_USING_SPI diff --git a/bsp/tae32f5300/drivers/Kconfig b/bsp/tae32f5300/drivers/Kconfig index 46e8ed25ec..6e7d491d04 100644 --- a/bsp/tae32f5300/drivers/Kconfig +++ b/bsp/tae32f5300/drivers/Kconfig @@ -167,7 +167,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_RTC diff --git a/bsp/tm4c123bsp/board/Kconfig b/bsp/tm4c123bsp/board/Kconfig index db5b976281..f6136621de 100644 --- a/bsp/tm4c123bsp/board/Kconfig +++ b/bsp/tm4c123bsp/board/Kconfig @@ -283,7 +283,6 @@ menu "On-chip Peripheral Drivers" menuconfig BSP_USING_ONCHIP_RTC bool "Enable RTC" select RT_USING_RTC - select RT_USING_LIBC default n if BSP_USING_ONCHIP_RTC choice diff --git a/components/cplusplus/Kconfig b/components/cplusplus/Kconfig index 42b5cf9556..3d5757fe42 100644 --- a/components/cplusplus/Kconfig +++ b/components/cplusplus/Kconfig @@ -9,8 +9,8 @@ if RT_USING_CPLUSPLUS config RT_USING_CPLUSPLUS11 bool "Enable c++11 threading feature support" default n - select RT_USING_LIBC - select RT_LIBC_USING_FILEIO + select RT_USING_POSIX_FS + select RT_USING_POSIX_DEVIO select RT_USING_PTHREADS select RT_USING_RTC diff --git a/components/cplusplus/README.md b/components/cplusplus/README.md index d02048d1f1..46c8c78a69 100644 --- a/components/cplusplus/README.md +++ b/components/cplusplus/README.md @@ -11,8 +11,6 @@ Because RT-Thread RTOS is used in embedded system mostly, there are some rules f 4. Static class variables are discouraged. The time and place to call their constructor function could not be precisely controlled and make multi-threaded programming a nightmare. 5. Multiple inheritance is strongly discouraged, as it can cause intolerable confusion. -*NOTE*: The libc (RT_USING_LIBC in rtconfig.h) must be enable. - About GNU GCC compiler please add following string in your ld link script: diff --git a/components/cplusplus/cpp11/armclang/thread.cpp b/components/cplusplus/cpp11/armclang/thread.cpp index 6b38d9b3a7..e10ffb9cfe 100644 --- a/components/cplusplus/cpp11/armclang/thread.cpp +++ b/components/cplusplus/cpp11/armclang/thread.cpp @@ -95,8 +95,8 @@ extern "C" unsigned __ARM_TPL_thread_hw_concurrency() extern "C" int __ARM_TPL_tls_create(__ARM_TPL_tls_key *__key, void (*__at_exit)(void *)) { - pthread_key_t key; - + pthread_key_t key; + if (pthread_key_create(&key, __at_exit) == 0) { *__key = key; diff --git a/components/cplusplus/cpp11/gcc/mutex b/components/cplusplus/cpp11/gcc/mutex index cc593cc139..3fdf86632b 100644 --- a/components/cplusplus/cpp11/gcc/mutex +++ b/components/cplusplus/cpp11/gcc/mutex @@ -4,7 +4,7 @@ #error "C++ version lower than C++11" #endif -//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS) +//#if defined(RT_USING_PTHREADS) #include @@ -509,4 +509,4 @@ namespace std } } -//#endif // (RT_USING_LIBC) && (RT_USING_PTHREADS) \ No newline at end of file +//#endif //(RT_USING_PTHREADS) \ No newline at end of file diff --git a/components/cplusplus/cpp11/gcc/mutex.cpp b/components/cplusplus/cpp11/gcc/mutex.cpp index 014460ffde..e11f6d8990 100644 --- a/components/cplusplus/cpp11/gcc/mutex.cpp +++ b/components/cplusplus/cpp11/gcc/mutex.cpp @@ -34,7 +34,7 @@ namespace std get_once_functor_lock_ptr() = m_ptr; } - extern "C" + extern "C" { void once_proxy() { @@ -42,7 +42,7 @@ namespace std function once_call = std::move(once_functor); // no need to hold the lock anymore - unique_lock* lock_ptr = get_once_functor_lock_ptr(); + unique_lock* lock_ptr = get_once_functor_lock_ptr(); get_once_functor_lock_ptr() = nullptr; lock_ptr->unlock(); diff --git a/components/cplusplus/cpp11/gcc/thread b/components/cplusplus/cpp11/gcc/thread index 5b64decd6a..60e3ec964c 100644 --- a/components/cplusplus/cpp11/gcc/thread +++ b/components/cplusplus/cpp11/gcc/thread @@ -4,7 +4,7 @@ #error "C++ version lower than C++11" #endif -//#if defined(RT_USING_LIBC) && defined(RT_USING_PTHREADS) +//#if defined(RT_USING_PTHREADS) #include #include diff --git a/components/cplusplus/cpp11/gcc/thread.cpp b/components/cplusplus/cpp11/gcc/thread.cpp index 947170da25..3979da0dc4 100644 --- a/components/cplusplus/cpp11/gcc/thread.cpp +++ b/components/cplusplus/cpp11/gcc/thread.cpp @@ -35,17 +35,17 @@ namespace std { auto raw_ptr = b.get(); // transfer the ownership of the invoker to the new thread - raw_ptr->this_ptr = std::move(b); + raw_ptr->this_ptr = std::move(b); int err = pthread_create(&_m_thr.__cpp_thread_t, NULL, &execute_native_thread_routine, raw_ptr); - if (err) + if (err) { raw_ptr->this_ptr.reset(); throw_system_error(err, "Failed to create a thread"); } - - } + + } thread::~thread() { @@ -59,12 +59,12 @@ namespace std if (joinable()) err = pthread_join(native_handle(), NULL); - - if (err) + + if (err) { throw_system_error(err, "thread::join failed"); } - + _m_thr = id(); } @@ -78,14 +78,14 @@ namespace std { throw_system_error(err, "thread::detach failed"); } - + _m_thr = id(); } // TODO: not yet actually implemented. // The standard states that the returned value should only be considered a hint. - unsigned thread::hardware_concurrency() noexcept - { + unsigned thread::hardware_concurrency() noexcept + { int __n = _RT_NPROCS; if (__n < 0) __n = 0; diff --git a/components/dfs/filesystems/elmfat/dfs_elm.c b/components/dfs/filesystems/elmfat/dfs_elm.c index 166c9d77da..b7cdaf8522 100644 --- a/components/dfs/filesystems/elmfat/dfs_elm.c +++ b/components/dfs/filesystems/elmfat/dfs_elm.c @@ -945,7 +945,6 @@ DWORD get_fattime(void) { DWORD fat_time = 0; -#if defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC) time_t now; struct tm *p_tm; struct tm tm_now; @@ -968,7 +967,6 @@ DWORD get_fattime(void) (DWORD)tm_now.tm_hour << 11 | (DWORD)tm_now.tm_min << 5 | (DWORD)tm_now.tm_sec / 2 ; -#endif /* defined(RT_LIBC_USING_TIME) || defined(RT_USING_LIBC) */ return fat_time; } diff --git a/components/libc/Kconfig b/components/libc/Kconfig index 69f8e1ae36..0556cf6183 100644 --- a/components/libc/Kconfig +++ b/components/libc/Kconfig @@ -1,38 +1,16 @@ menu "POSIX layer and C standard library" -config RT_USING_LIBC - bool "Enable libc APIs from the toolchain" +config RT_USING_MODULE + bool "Enable dynamic module with dlopen/dlsym/dlclose feature" default n -if RT_USING_LIBC - config RT_LIBC_USING_TIME - default y - - config RT_LIBC_USING_FILEIO - bool "Enable libc with file operation, eg.fopen/fwrite/fread/getchar/STDIO" - select RT_USING_POSIX_FS - select RT_USING_POSIX_DEVIO - default n - - config RT_USING_MODULE - bool "Enable dynamic module with dlopen/dlsym/dlclose feature" +if RT_USING_MODULE + config RT_USING_CUSTOM_DLMODULE + bool "Enable load dynamic module by custom" default n - - if RT_USING_MODULE - config RT_USING_CUSTOM_DLMODULE - bool "Enable load dynamic module by custom" - default n - endif -endif - -if RT_USING_LIBC != y - config RT_LIBC_USING_TIME - bool "Enable time functions without compiler's libc" - default y endif config RT_LIBC_DEFAULT_TIMEZONE - depends on (RT_LIBC_USING_TIME || RT_USING_LIBC) int "Set the default time zone (UTC+)" range -12 12 default 8 diff --git a/components/libc/compilers/armlibc/README.md b/components/libc/compilers/armlibc/README.md index 4d2a73b6be..fc0d750234 100644 --- a/components/libc/compilers/armlibc/README.md +++ b/components/libc/compilers/armlibc/README.md @@ -1,9 +1,3 @@ # ARMLIB (Keil-MDK) porting for RT-Thread -Please define RT_USING_LIBC and compile RT-Thread with Keil-MDK compiler. - - - -## More Information - https://www.keil.com/support/man/docs/armlib/ \ No newline at end of file diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index bf1a299304..7fc94ccaa4 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -7,6 +7,6 @@ group = [] CPPDEFINES = ['RT_USING_ARM_LIBC'] if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES) + group = DefineGroup('compiler-libc', src, depend = [], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/armlibc/mem_std.c b/components/libc/compilers/armlibc/mem_std.c deleted file mode 100644 index f8a81c7873..0000000000 --- a/components/libc/compilers/armlibc/mem_std.c +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright (c) 2006-2021, RT-Thread Development Team - * - * SPDX-License-Identifier: Apache-2.0 - * - * Change Logs: - * Date Author Notes - * 2014-08-03 bernard Add file header - * 2021-11-13 Meco Man implement no-heap warning - */ - -#include -#include - -#ifndef RT_USING_HEAP -#define DBG_TAG "armlibc.mem" -#define DBG_LVL DBG_INFO -#include - -#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ - RT_ASSERT(0);\ - }while(0) -#endif /* RT_USING_HEAP */ - -#ifdef __CC_ARM -/* avoid the heap and heap-using library functions supplied by arm */ -#pragma import(__use_no_heap) -#endif /* __CC_ARM */ - -void *malloc(size_t n) -{ -#ifdef RT_USING_HEAP - return rt_malloc(n); -#else - _NO_HEAP_ERROR(); - return RT_NULL; -#endif -} -RTM_EXPORT(malloc); - -void *realloc(void *rmem, size_t newsize) -{ -#ifdef RT_USING_HEAP - return rt_realloc(rmem, newsize); -#else - _NO_HEAP_ERROR(); - return RT_NULL; -#endif -} -RTM_EXPORT(realloc); - -void *calloc(size_t nelem, size_t elsize) -{ -#ifdef RT_USING_HEAP - return rt_calloc(nelem, elsize); -#else - _NO_HEAP_ERROR(); - return RT_NULL; -#endif -} -RTM_EXPORT(calloc); - -void free(void *rmem) -{ -#ifdef RT_USING_HEAP - rt_free(rmem); -#else - _NO_HEAP_ERROR(); -#endif -} -RTM_EXPORT(free); diff --git a/components/libc/compilers/armlibc/syscall_mem.c b/components/libc/compilers/armlibc/syscall_mem.c new file mode 100644 index 0000000000..b5403dfaf3 --- /dev/null +++ b/components/libc/compilers/armlibc/syscall_mem.c @@ -0,0 +1,71 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2014-08-03 bernard Add file header + * 2021-11-13 Meco Man implement no-heap warning + */ + +#include +#include + +#ifndef RT_USING_HEAP +#define DBG_TAG "armlibc.syscall.mem" +#define DBG_LVL DBG_INFO +#include + +#define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ + RT_ASSERT(0);\ + }while(0) +#endif /* RT_USING_HEAP */ + +#ifdef __CC_ARM +/* avoid the heap and heap-using library functions supplied by arm */ +#pragma import(__use_no_heap) +#endif /* __CC_ARM */ + +void *malloc(size_t n) +{ +#ifdef RT_USING_HEAP + return rt_malloc(n); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif +} +RTM_EXPORT(malloc); + +void *realloc(void *rmem, size_t newsize) +{ +#ifdef RT_USING_HEAP + return rt_realloc(rmem, newsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif +} +RTM_EXPORT(realloc); + +void *calloc(size_t nelem, size_t elsize) +{ +#ifdef RT_USING_HEAP + return rt_calloc(nelem, elsize); +#else + _NO_HEAP_ERROR(); + return RT_NULL; +#endif +} +RTM_EXPORT(calloc); + +void free(void *rmem) +{ +#ifdef RT_USING_HEAP + rt_free(rmem); +#else + _NO_HEAP_ERROR(); +#endif +} +RTM_EXPORT(free); diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 0e965d62af..77bf37dcbc 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -21,6 +21,7 @@ #include #include #include +#include #ifdef RT_USING_POSIX_DEVIO #include "libc.h" #endif /* RT_USING_POSIX_DEVIO */ @@ -69,6 +70,7 @@ FILEHANDLE _sys_open(const char *name, int openmode) return (STDERR); #ifndef DFS_USING_POSIX + LOG_W("%s: %s", __func__, warning_without_fs); return 0; /* error */ #else /* Correct openmode from fopen to open */ @@ -113,6 +115,7 @@ int _sys_close(FILEHANDLE fh) return close(fh); #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; #endif /* DFS_USING_POSIX */ } @@ -152,12 +155,13 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard output before initializing libc"); + LOG_W("Do not invoke standard output before initializing compiler-libc"); return 0; /* error, but keep going */ } size = read(STDIN_FILENO, buf, len); return len - size; /* success */ #else + LOG_W("%s: %s", __func__, warning_without_devio); return 0; /* error */ #endif /* RT_USING_POSIX_DEVIO */ } @@ -178,6 +182,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) } } #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -228,6 +233,7 @@ int _sys_write(FILEHANDLE fh, const unsigned char *buf, unsigned len, int mode) return 0; /* error */ } #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -246,6 +252,7 @@ int _sys_seek(FILEHANDLE fh, long pos) /* position is relative to the start of file fh */ return lseek(fh, pos, 0); #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -301,6 +308,7 @@ long _sys_flen(FILEHANDLE fh) fstat(fh, &stat); return stat.st_size; #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; #endif /* DFS_USING_POSIX */ } @@ -318,6 +326,7 @@ int remove(const char *filename) #ifdef DFS_USING_POSIX return unlink(filename); #else + LOG_W("%s: %s", __func__, warning_without_fs); return 0; /* error */ #endif /* DFS_USING_POSIX */ } @@ -345,13 +354,14 @@ int fgetc(FILE *f) if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard output before initializing libc"); + LOG_W("Do not invoke standard output before initializing compiler-libc"); return 0; } if(read(STDIN_FILENO, &ch, 1) == 1) return ch; #endif /* RT_USING_POSIX_DEVIO */ + LOG_W("%s: %s", __func__, warning_without_devio); return 0; /* error */ } diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 504bf84e56..26cd9ab1d8 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -10,12 +10,9 @@ CPPDEFINES = [] if rtconfig.CROSS_TOOL == 'keil': CPPDEFINES += ['__CLK_TCK=RT_TICK_PER_SECOND'] -if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') -elif GetDepend('RT_LIBC_USING_TIME'): - src += ['time.c'] +src += Glob('*.c') -group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) +group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) list = os.listdir(cwd) for item in list: diff --git a/components/libc/compilers/common/compiler_private.c b/components/libc/compilers/common/compiler_private.c new file mode 100644 index 0000000000..6e9a6001f0 --- /dev/null +++ b/components/libc/compilers/common/compiler_private.c @@ -0,0 +1,13 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-12-26 Meco Man First Version + */ +#include "compiler_private.h" + +const char *warning_without_fs = "Please enable RT_USING_POSIX_FS"; +const char *warning_without_devio = "Please enable RT_USING_POSIX_FS and RT_USING_POSIX_DEVIO"; diff --git a/components/libc/compilers/common/compiler_private.h b/components/libc/compilers/common/compiler_private.h new file mode 100644 index 0000000000..79bac3b787 --- /dev/null +++ b/components/libc/compilers/common/compiler_private.h @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2006-2021, RT-Thread Development Team + * + * SPDX-License-Identifier: Apache-2.0 + * + * Change Logs: + * Date Author Notes + * 2021-12-26 Meco Man First Version + */ +#ifndef __COMPILER_PRIVATE_H__ +#define __COMPILER_PRIVATE_H__ + +#include + +extern const char *warning_without_fs; +extern const char *warning_without_devio; + +#endif /* __COMPILER_PRIVATE_H__ */ diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/nogcc/SConscript index c766c8f82d..091848a6d5 100644 --- a/components/libc/compilers/common/nogcc/SConscript +++ b/components/libc/compilers/common/nogcc/SConscript @@ -7,9 +7,8 @@ cwd = GetCurrentDir() CPPPATH = [cwd] group = [] -if GetDepend('RT_USING_LIBC'): - src += Glob('*.c') +src += Glob('*.c') if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) + group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/common/time.c b/components/libc/compilers/common/time.c index 4d204a0c00..1fe11561f7 100644 --- a/components/libc/compilers/common/time.c +++ b/components/libc/compilers/common/time.c @@ -25,7 +25,7 @@ #include #include #include -#ifdef RT_USING_DEVICE +#ifdef RT_USING_RTC #include #endif @@ -33,6 +33,8 @@ #define DBG_LVL DBG_INFO #include +#define WARNING_NO_RTC "Cannot find a RTC device!" + /* seconds per day */ #define SPD 24*60*60 @@ -108,7 +110,7 @@ static rt_err_t get_timeval(struct timeval *tv) else { /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + rt_kprintf(WARNING_NO_RTC); return -RT_ENOSYS; } @@ -116,7 +118,7 @@ static rt_err_t get_timeval(struct timeval *tv) #else /* LOG_W will cause a recursive printing if ulog timestamp function is enabled */ - rt_kprintf("Cannot find a RTC device to provide time!\r\n"); + rt_kprintf(WARNING_NO_RTC); return -RT_ENOSYS; #endif /* RT_USING_RTC */ } @@ -153,14 +155,14 @@ static int set_timeval(struct timeval *tv) } else { - LOG_W("Cannot find a RTC device to provide time!"); + LOG_W(WARNING_NO_RTC); return -RT_ENOSYS; } return rst; #else - LOG_W("Cannot find a RTC device to provide time!"); + LOG_W(WARNING_NO_RTC); return -RT_ENOSYS; #endif /* RT_USING_RTC */ } @@ -525,7 +527,7 @@ INIT_COMPONENT_EXPORT(_rt_clock_time_system_init); int clock_getres(clockid_t clockid, struct timespec *res) { #ifndef RT_USING_RTC - LOG_W("Cannot find a RTC device to save time!"); + LOG_W(WARNING_NO_RTC); return -1; #else int ret = 0; @@ -564,7 +566,7 @@ RTM_EXPORT(clock_getres); int clock_gettime(clockid_t clockid, struct timespec *tp) { #ifndef RT_USING_RTC - LOG_W("Cannot find a RTC device to save time!"); + LOG_W(WARNING_NO_RTC); return -1; #else int ret = 0; @@ -628,7 +630,7 @@ int clock_nanosleep(clockid_t clockid, int flags, const struct timespec *rqtp, s int clock_settime(clockid_t clockid, const struct timespec *tp) { #ifndef RT_USING_RTC - LOG_W("Cannot find a RTC device to save time!"); + LOG_W(WARNING_NO_RTC); return -1; #else register rt_base_t level; diff --git a/components/libc/compilers/dlib/README.md b/components/libc/compilers/dlib/README.md index acd08f9074..e4d70e8135 100644 --- a/components/libc/compilers/dlib/README.md +++ b/components/libc/compilers/dlib/README.md @@ -1,9 +1,3 @@ # DLIB (IAR) porting for RT-Thread -Please define RT_USING_LIBC and compile RT-Thread with IAR compiler. - - - -## More Information - http://www.iarsys.co.jp/download/LMS2/arm/7502/ewarm7502doc/arm/doc/EWARM_DevelopmentGuide.ENU.pdf P.130 \ No newline at end of file diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index f685873e16..2c5dbc426d 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -15,6 +15,6 @@ if rtconfig.PLATFORM == 'iar': if LooseVersion(IARVersion()) < LooseVersion("8.20.1"): CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT'] - group = DefineGroup('libc', src, depend = ['RT_USING_LIBC'], CPPDEFINES = CPPDEFINES) + group = DefineGroup('compiler-libc', src, depend = [], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/dlib/syscall_close.c b/components/libc/compilers/dlib/syscall_close.c index 30ee6f2388..9ac60076f4 100644 --- a/components/libc/compilers/dlib/syscall_close.c +++ b/components/libc/compilers/dlib/syscall_close.c @@ -10,6 +10,10 @@ #include #include #include +#include +#define DBG_TAG "dlib.syscall.close" +#define DBG_LVL DBG_INFO +#include /* * The "__close" function should close the file corresponding to @@ -27,6 +31,7 @@ int __close(int handle) #ifdef DFS_USING_POSIX return close(handle); #else + LOG_W(warning_without_fs); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_lseek.c b/components/libc/compilers/dlib/syscall_lseek.c index 622f613c51..b7ec0fa7a9 100644 --- a/components/libc/compilers/dlib/syscall_lseek.c +++ b/components/libc/compilers/dlib/syscall_lseek.c @@ -10,6 +10,10 @@ #include #include #include +#include +#define DBG_TAG "dlib.syscall.lseek" +#define DBG_LVL DBG_INFO +#include /* * The "__lseek" function makes the next file operation (__read or @@ -36,6 +40,7 @@ long __lseek(int handle, long offset, int whence) #ifdef DFS_USING_POSIX return lseek(handle, offset, whence); #else + LOG_W(warning_without_fs); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_mem.c b/components/libc/compilers/dlib/syscall_mem.c index 74b960f0b9..57060da842 100644 --- a/components/libc/compilers/dlib/syscall_mem.c +++ b/components/libc/compilers/dlib/syscall_mem.c @@ -12,7 +12,7 @@ #include #ifndef RT_USING_HEAP -#define DBG_TAG "dlib.syscall_mem" +#define DBG_TAG "dlib.syscall.mem" #define DBG_LVL DBG_INFO #include #define _NO_HEAP_ERROR() do{LOG_E("Please enable RT_USING_HEAP");\ diff --git a/components/libc/compilers/dlib/syscall_open.c b/components/libc/compilers/dlib/syscall_open.c index 66cddc83c1..3d31f0cf69 100644 --- a/components/libc/compilers/dlib/syscall_open.c +++ b/components/libc/compilers/dlib/syscall_open.c @@ -11,6 +11,10 @@ #include #include #include +#include +#define DBG_TAG "dlib.syscall.open" +#define DBG_LVL DBG_INFO +#include /* * The "__open" function opens the file named "filename" as specified @@ -22,56 +26,58 @@ int __open(const char *filename, int mode) { #ifdef DFS_USING_POSIX - int handle; - int open_mode = O_RDONLY; + int handle; + int open_mode = O_RDONLY; - if (mode & _LLIO_CREAT) - { - open_mode |= O_CREAT; - - /* Check what we should do with it if it exists. */ - if (mode & _LLIO_APPEND) + if (mode & _LLIO_CREAT) { - /* Append to the existing file. */ - open_mode |= O_APPEND; + open_mode |= O_CREAT; + + /* Check what we should do with it if it exists. */ + if (mode & _LLIO_APPEND) + { + /* Append to the existing file. */ + open_mode |= O_APPEND; + } + + if (mode & _LLIO_TRUNC) + { + /* Truncate the existsing file. */ + open_mode |= O_TRUNC; + } } - if (mode & _LLIO_TRUNC) + if (mode & _LLIO_TEXT) { - /* Truncate the existsing file. */ - open_mode |= O_TRUNC; + /* we didn't support text mode */ } - } - if (mode & _LLIO_TEXT) - { - /* we didn't support text mode */ - } - - switch (mode & _LLIO_RDWRMASK) - { - case _LLIO_RDONLY: - break; - - case _LLIO_WRONLY: - open_mode |= O_WRONLY; - break; + switch (mode & _LLIO_RDWRMASK) + { + case _LLIO_RDONLY: + break; - case _LLIO_RDWR: - /* The file should be opened for both reads and writes. */ - open_mode |= O_RDWR; - break; + case _LLIO_WRONLY: + open_mode |= O_WRONLY; + break; - default: - return _LLIO_ERROR; - } + case _LLIO_RDWR: + /* The file should be opened for both reads and writes. */ + open_mode |= O_RDWR; + break; - handle = open(filename, open_mode, 0); - if (handle < 0) - return _LLIO_ERROR; + default: + return _LLIO_ERROR; + } - return handle; + handle = open(filename, open_mode, 0); + if (handle < 0) + { + return _LLIO_ERROR; + } + return handle; #else - return _LLIO_ERROR; + LOG_W(warning_without_fs); + return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 62bc05d243..29941c23db 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -14,8 +14,8 @@ #ifdef RT_USING_POSIX_DEVIO #include "libc.h" #endif /* RT_USING_POSIX_DEVIO */ - -#define DBG_TAG "dlib.syscall_read" +#include +#define DBG_TAG "dlib.syscall.read" #define DBG_LVL DBG_INFO #include @@ -42,11 +42,12 @@ size_t __read(int handle, unsigned char *buf, size_t len) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard input before initializing libc"); + LOG_W("Do not invoke standard input before initializing compiler-libc"); return 0; /* error, but keep going */ } return read(STDIN_FILENO, buf, len); /* return the length of the data read */ #else + LOG_W(warning_without_devio); return _LLIO_ERROR; #endif /* RT_USING_POSIX_DEVIO */ } @@ -58,6 +59,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) size = read(handle, buf, len); return size; /* return the length of the data read */ #else + LOG_W(warning_without_fs); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_remove.c b/components/libc/compilers/dlib/syscall_remove.c index 870f91b8c1..9b5d596eb5 100644 --- a/components/libc/compilers/dlib/syscall_remove.c +++ b/components/libc/compilers/dlib/syscall_remove.c @@ -10,6 +10,10 @@ #include #include #include +#include +#define DBG_TAG "dlib.syscall.remove" +#define DBG_LVL DBG_INFO +#include /* * The "remove" function should remove the file named "filename". It @@ -23,6 +27,7 @@ int remove(const char *filename) #ifdef DFS_USING_POSIX return unlink(filename); #else + LOG_W(warning_without_fs); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/dlib/syscall_write.c b/components/libc/compilers/dlib/syscall_write.c index 2bc5863d8a..11a6f9cca5 100644 --- a/components/libc/compilers/dlib/syscall_write.c +++ b/components/libc/compilers/dlib/syscall_write.c @@ -11,7 +11,8 @@ #include #include #include -#define DBG_TAG "dlib.syscall_write" +#include +#define DBG_TAG "dlib.syscall.write" #define DBG_LVL DBG_INFO #include @@ -63,6 +64,7 @@ size_t __write(int handle, const unsigned char *buf, size_t len) size = write(handle, buf, len); return size; /* return the length of the data written */ #else + LOG_W(warning_without_fs); return _LLIO_ERROR; #endif /* DFS_USING_POSIX */ } diff --git a/components/libc/compilers/gcc/newlib/README.md b/components/libc/compilers/gcc/newlib/README.md index 62172e6a55..4614375b45 100644 --- a/components/libc/compilers/gcc/newlib/README.md +++ b/components/libc/compilers/gcc/newlib/README.md @@ -1,10 +1,4 @@ # NEWLIB (GCC) porting for RT-Thread -Please define RT_USING_LIBC and compile RT-Thread with GCC compiler. - - - -## More Information - https://sourceware.org/newlib/libc.html#Reentrancy diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript index d51bbdad84..7a2be2e781 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -10,11 +10,8 @@ LIBS = ['m'] # link libm CPPPATH = [cwd] if rtconfig.PLATFORM == 'gcc': - if GetDepend('RT_USING_LIBC'): - LIBS += ['c'] # link libc - src += Glob('*.c') - else: - src += ['syscalls.c'] + LIBS += ['c'] # link libc + src += Glob('*.c') #report newlib version print('Newlib version:' + GetNewLibVersion(rtconfig)) @@ -22,7 +19,7 @@ if rtconfig.PLATFORM == 'gcc': # identify this is Newlib, and only enable POSIX.1-1990 CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1'] - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) list = os.listdir(cwd) diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 8fe8c5be4b..65dece0d02 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -26,7 +26,7 @@ #ifdef RT_USING_MODULE #include #endif /* RT_USING_MODULE */ - +#include #define DBG_TAG "newlib.syscalls" #define DBG_LVL DBG_INFO #include @@ -92,8 +92,6 @@ void __libc_init_array(void) /* __libc_init_array is ARM code, not Thumb; it will cause a hardfault. */ } -#ifdef RT_USING_LIBC - /* Reentrant versions of system calls. */ #ifndef _REENT_ONLY int *__errno () @@ -112,6 +110,7 @@ int _close_r(struct _reent *ptr, int fd) #ifdef DFS_USING_POSIX return close(fd); #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -185,10 +184,10 @@ _off_t _lseek_r(struct _reent *ptr, int fd, _off_t pos, int whence) { #ifdef DFS_USING_POSIX _off_t rc; - rc = lseek(fd, pos, whence); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -198,10 +197,10 @@ int _mkdir_r(struct _reent *ptr, const char *name, int mode) { #ifdef DFS_USING_POSIX int rc; - rc = mkdir(name, mode); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -214,6 +213,7 @@ int _open_r(struct _reent *ptr, const char *file, int flags, int mode) rc = open(file, flags, mode); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -228,10 +228,11 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard input before initializing libc"); + LOG_W("Do not invoke standard input before initializing compiler-libc"); return 0; } #else + LOG_W("%s: %s", __func__, warning_without_devio); ptr->_errno = ENOTSUP; return -1; #endif /* RT_USING_POSIX_DEVIO */ @@ -245,6 +246,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) rc = read(fd, buf, nbytes); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -254,10 +256,10 @@ int _rename_r(struct _reent *ptr, const char *old, const char *new) { #ifdef DFS_USING_POSIX int rc; - rc = rename(old, new); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -267,10 +269,10 @@ int _stat_r(struct _reent *ptr, const char *file, struct stat *pstat) { #ifdef DFS_USING_POSIX int rc; - rc = stat(file, pstat); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -281,6 +283,7 @@ int _unlink_r(struct _reent *ptr, const char *file) #ifdef DFS_USING_POSIX return unlink(file); #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -315,6 +318,7 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) rc = write(fd, buf, nbytes); return rc; #else + LOG_W("%s: %s", __func__, warning_without_fs); ptr->_errno = ENOTSUP; return -1; #endif /* DFS_USING_POSIX */ @@ -333,5 +337,3 @@ These functions are implemented and replaced by the 'common/time.c' file int _gettimeofday_r(struct _reent *ptr, struct timeval *__tp, void *__tzp); _CLOCK_T_ _times_r(struct _reent *ptr, struct tms *ptms); */ - -#endif /* RT_USING_LIBC */ diff --git a/components/libc/libdl/arch/riscv.c b/components/libc/libdl/arch/riscv.c index 33cae28d16..c7c454e168 100644 --- a/components/libc/libdl/arch/riscv.c +++ b/components/libc/libdl/arch/riscv.c @@ -1,12 +1,12 @@ /* - * Copyright (c) 2006-2018, RT-Thread Development Team + * Copyright (c) 2006-2021, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 - * + * * Change Logs: * Date Author Notes * 2021/04/23 chunyexixiaoyu first version - + */ #include "../dlmodule.h" @@ -31,7 +31,7 @@ int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val Elf64_Addr *where, tmp; Elf64_Sword addend, offset; rt_uint64_t upper, lower, sign, j1, j2; - + where = (Elf64_Addr *)((rt_uint8_t *)module->mem_space + rel->r_offset - module->vstart_addr); @@ -50,7 +50,7 @@ int dlmodule_relocate(struct rt_dlmodule *module, Elf_Rel *rel, Elf_Addr sym_val case R_RISCV_JUMP_SLOT: *where = (Elf64_Addr)sym_val; RT_DEBUG_LOG(RT_DEBUG_MODULE, ("R_RISCV_JUMP_SLOT: %x -> %x\n",where, *where)); - break; + break; default: RT_DEBUG_LOG(RT_DEBUG_MODULE, ("__riscv__ELF: invalid relocate TYPE %d\n", ELF64_R_TYPE(rel->r_info))); return -1; diff --git a/components/libc/posix/Kconfig b/components/libc/posix/Kconfig index ef1389f9c3..39411a1be5 100644 --- a/components/libc/posix/Kconfig +++ b/components/libc/posix/Kconfig @@ -41,14 +41,13 @@ config RT_USING_POSIX_DELAY config RT_USING_POSIX_CLOCK bool "Enable clock/time functions, clock_gettime()/clock_settime()/clock_getres() etc" - select RT_LIBC_USING_TIME if !RT_USING_LIBC select RT_USING_POSIX_DELAY default n config RT_USING_POSIX_GETLINE bool "Enable getline()/getdelim()" - select RT_USING_LIBC - select RT_LIBC_USING_FILEIO + select RT_USING_POSIX_FS + select RT_USING_POSIX_DEVIO default n config RT_USING_PTHREADS diff --git a/components/libc/posix/io/libc.c b/components/libc/posix/io/libc.c index 0107f3a58b..4bb647c16b 100644 --- a/components/libc/posix/io/libc.c +++ b/components/libc/posix/io/libc.c @@ -33,8 +33,7 @@ int libc_system_init(void) } INIT_COMPONENT_EXPORT(libc_system_init); -#ifdef RT_USING_POSIX_DEVIO -#if defined(RT_USING_LIBC) && defined(RT_USING_NEWLIB) +#if defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_NEWLIB) #define STDIO_DEVICE_NAME_MAX 32 static FILE* std_console = NULL; int libc_stdio_set_console(const char* device_name, int mode) @@ -135,5 +134,4 @@ int libc_stdio_set_console(const char* device_name, int mode) int libc_stdio_get_console(void) { return std_fd; } -#endif /* defined(RT_USING_LIBC) && defined(RT_USING_NEWLIB) */ -#endif /* RT_USING_POSIX_DEVIO */ +#endif /* defined(RT_USING_POSIX_DEVIO) && defined(RT_USING_NEWLIB) */ diff --git a/components/libc/posix/signal/SConscript b/components/libc/posix/signal/SConscript index 07cd98cbe0..9c712fa694 100644 --- a/components/libc/posix/signal/SConscript +++ b/components/libc/posix/signal/SConscript @@ -7,7 +7,7 @@ src = Glob('*.c') + Glob('*.cpp') CPPPATH = [cwd] group = DefineGroup('POSIX', src, - depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS', 'RT_USING_LIBC'], + depend = ['RT_USING_SIGNALS', 'RT_USING_PTHREADS'], CPPPATH = CPPPATH) Return('group') diff --git a/components/lwp/Kconfig b/components/lwp/Kconfig index 82193e3b00..fde442d235 100644 --- a/components/lwp/Kconfig +++ b/components/lwp/Kconfig @@ -2,7 +2,6 @@ config RT_USING_LWP bool "Using light-weight process" select RT_USING_POSIX_FS select RT_USING_POSIX_SELECT - select RT_USING_LIBC depends on ARCH_ARM_CORTEX_M || ARCH_ARM_ARM9 || ARCH_ARM_CORTEX_A default n help diff --git a/components/net/lwip-2.1.2/src/lwipopts.h b/components/net/lwip-2.1.2/src/lwipopts.h index 95e88961d2..ca70de012a 100644 --- a/components/net/lwip-2.1.2/src/lwipopts.h +++ b/components/net/lwip-2.1.2/src/lwipopts.h @@ -231,11 +231,7 @@ # define SSIZE_MAX LONG_MAX # endif -#ifdef RT_USING_LIBC #define LWIP_NO_UNISTD_H 0 -#else -#define LWIP_NO_UNISTD_H 1 -#endif /* ---------- Memory options ---------- */ #define MEMCPY(dst,src,len) rt_memcpy(dst,src,len) diff --git a/components/utilities/Kconfig b/components/utilities/Kconfig index d5d878e86f..af0fe054ae 100644 --- a/components/utilities/Kconfig +++ b/components/utilities/Kconfig @@ -136,7 +136,6 @@ config RT_USING_ULOG menu "log format" config ULOG_OUTPUT_FLOAT bool "Enable float number support. It will using more thread stack." - select RT_USING_LIBC default n help The default formater is using rt_vsnprint and it not supported float number. -- cgit v1.3.1 From c8dcf7cc6805bcf5380d524d7a5c44e2ff366128 Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Tue, 28 Dec 2021 23:25:16 -0500 Subject: [libc]rename group name --- components/drivers/mtd/SConscript | 2 +- components/libc/compilers/armlibc/SConscript | 2 +- components/libc/compilers/armlibc/syscalls.c | 4 ++-- components/libc/compilers/common/SConscript | 2 +- components/libc/compilers/common/nogcc/SConscript | 2 +- components/libc/compilers/dlib/SConscript | 2 +- components/libc/compilers/dlib/syscall_read.c | 2 +- components/libc/compilers/gcc/newlib/SConscript | 2 +- components/libc/compilers/gcc/newlib/legacy/_select/SConscript | 2 +- components/libc/compilers/gcc/newlib/syscalls.c | 2 +- components/libc/posix/io/SConscript | 2 +- components/libc/posix/io/poll/SConscript | 2 +- components/libc/posix/ipc/SConscript | 2 +- components/libc/posix/src/SConscript | 2 +- examples/utest/testcases/kernel/SConscript | 2 +- libcpu/arc/common/SConscript | 2 +- 16 files changed, 17 insertions(+), 17 deletions(-) (limited to 'components/libc/compilers/dlib/SConscript') diff --git a/components/drivers/mtd/SConscript b/components/drivers/mtd/SConscript index 6f86656187..5fffdc655d 100644 --- a/components/drivers/mtd/SConscript +++ b/components/drivers/mtd/SConscript @@ -2,7 +2,7 @@ from building import * cwd = GetCurrentDir() src = [] -depend = [] +depend = [''] CPPPATH = [cwd + '/../include'] group = [] diff --git a/components/libc/compilers/armlibc/SConscript b/components/libc/compilers/armlibc/SConscript index 7fc94ccaa4..bd3ac8dffc 100644 --- a/components/libc/compilers/armlibc/SConscript +++ b/components/libc/compilers/armlibc/SConscript @@ -7,6 +7,6 @@ group = [] CPPDEFINES = ['RT_USING_ARM_LIBC'] if rtconfig.PLATFORM == 'armcc' or rtconfig.PLATFORM == 'armclang': - group = DefineGroup('compiler-libc', src, depend = [], CPPDEFINES = CPPDEFINES) + group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 77bf37dcbc..e9318c5fc4 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -155,7 +155,7 @@ int _sys_read(FILEHANDLE fh, unsigned char *buf, unsigned len, int mode) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard output before initializing compiler-libc"); + LOG_W("Do not invoke standard output before initializing Compiler"); return 0; /* error, but keep going */ } size = read(STDIN_FILENO, buf, len); @@ -354,7 +354,7 @@ int fgetc(FILE *f) if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard output before initializing compiler-libc"); + LOG_W("Do not invoke standard output before initializing Compiler"); return 0; } diff --git a/components/libc/compilers/common/SConscript b/components/libc/compilers/common/SConscript index 26cd9ab1d8..8db8f2c94a 100644 --- a/components/libc/compilers/common/SConscript +++ b/components/libc/compilers/common/SConscript @@ -12,7 +12,7 @@ if rtconfig.CROSS_TOOL == 'keil': src += Glob('*.c') -group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) +group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES) list = os.listdir(cwd) for item in list: diff --git a/components/libc/compilers/common/nogcc/SConscript b/components/libc/compilers/common/nogcc/SConscript index 091848a6d5..dbc26ac177 100644 --- a/components/libc/compilers/common/nogcc/SConscript +++ b/components/libc/compilers/common/nogcc/SConscript @@ -10,5 +10,5 @@ group = [] src += Glob('*.c') if rtconfig.PLATFORM != 'gcc' or rtconfig.ARCH == 'sim': - group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH) + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/dlib/SConscript b/components/libc/compilers/dlib/SConscript index 2c5dbc426d..e11ea65b97 100644 --- a/components/libc/compilers/dlib/SConscript +++ b/components/libc/compilers/dlib/SConscript @@ -15,6 +15,6 @@ if rtconfig.PLATFORM == 'iar': if LooseVersion(IARVersion()) < LooseVersion("8.20.1"): CPPDEFINES = CPPDEFINES + ['_DLIB_THREAD_SUPPORT'] - group = DefineGroup('compiler-libc', src, depend = [], CPPDEFINES = CPPDEFINES) + group = DefineGroup('Compiler', src, depend = [''], CPPDEFINES = CPPDEFINES) Return('group') diff --git a/components/libc/compilers/dlib/syscall_read.c b/components/libc/compilers/dlib/syscall_read.c index 29941c23db..525db3c98f 100644 --- a/components/libc/compilers/dlib/syscall_read.c +++ b/components/libc/compilers/dlib/syscall_read.c @@ -42,7 +42,7 @@ size_t __read(int handle, unsigned char *buf, size_t len) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard input before initializing compiler-libc"); + LOG_W("Do not invoke standard input before initializing Compiler"); return 0; /* error, but keep going */ } return read(STDIN_FILENO, buf, len); /* return the length of the data read */ diff --git a/components/libc/compilers/gcc/newlib/SConscript b/components/libc/compilers/gcc/newlib/SConscript index 7a2be2e781..8076a73727 100644 --- a/components/libc/compilers/gcc/newlib/SConscript +++ b/components/libc/compilers/gcc/newlib/SConscript @@ -19,7 +19,7 @@ if rtconfig.PLATFORM == 'gcc': # identify this is Newlib, and only enable POSIX.1-1990 CPPDEFINES = ['RT_USING_NEWLIB', '_POSIX_C_SOURCE=1'] - group = DefineGroup('compiler-libc', src, depend = [], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH, CPPDEFINES = CPPDEFINES, LIBS = LIBS) list = os.listdir(cwd) diff --git a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript b/components/libc/compilers/gcc/newlib/legacy/_select/SConscript index 1c6a22b869..b7bd86a36c 100644 --- a/components/libc/compilers/gcc/newlib/legacy/_select/SConscript +++ b/components/libc/compilers/gcc/newlib/legacy/_select/SConscript @@ -15,6 +15,6 @@ if rtconfig.PLATFORM == 'gcc' and (CheckHeader(rtconfig, 'sys/select.h') == Fals except: pass - group = DefineGroup('libc', src, depend = [], CPPPATH = CPPPATH) + group = DefineGroup('Compiler', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 65dece0d02..6a2e99d512 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -228,7 +228,7 @@ _ssize_t _read_r(struct _reent *ptr, int fd, void *buf, size_t nbytes) #ifdef RT_USING_POSIX_DEVIO if (libc_stdio_get_console() < 0) { - LOG_W("Do not invoke standard input before initializing compiler-libc"); + LOG_W("Do not invoke standard input before initializing Compiler"); return 0; } #else diff --git a/components/libc/posix/io/SConscript b/components/libc/posix/io/SConscript index 32654674e8..0771ec67be 100644 --- a/components/libc/posix/io/SConscript +++ b/components/libc/posix/io/SConscript @@ -19,7 +19,7 @@ if GetDepend('RT_USING_POSIX_SELECT'): flag = True if flag == True: - group = DefineGroup('POSIX', src, depend = [], CPPPATH = CPPPATH) + group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) list = os.listdir(cwd) for d in list: diff --git a/components/libc/posix/io/poll/SConscript b/components/libc/posix/io/poll/SConscript index 7d82ade035..39b321b6c5 100644 --- a/components/libc/posix/io/poll/SConscript +++ b/components/libc/posix/io/poll/SConscript @@ -9,6 +9,6 @@ CPPPATH = [cwd] if GetDepend('RT_USING_POSIX_POLL'): src += ['poll.c'] -group = DefineGroup('POSIX', src, depend = [], CPPPATH = CPPPATH) +group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/components/libc/posix/ipc/SConscript b/components/libc/posix/ipc/SConscript index 5a78955f1d..5ea9dea355 100644 --- a/components/libc/posix/ipc/SConscript +++ b/components/libc/posix/ipc/SConscript @@ -15,6 +15,6 @@ if GetDepend('RT_USING_POSIX_MESSAGE_QUEUE'): if GetDepend('RT_USING_POSIX_MESSAGE_SEMAPHORE'): src += ['semaphore.c'] -group = DefineGroup('POSIX', src, depend = [], CPPPATH = inc) +group = DefineGroup('POSIX', src, depend = [''], CPPPATH = inc) Return('group') diff --git a/components/libc/posix/src/SConscript b/components/libc/posix/src/SConscript index 2ff916ff08..93bb93b0ad 100644 --- a/components/libc/posix/src/SConscript +++ b/components/libc/posix/src/SConscript @@ -11,6 +11,6 @@ flag = False src += ['unistd.c'] #TODO if flag == True: - group = DefineGroup('POSIX', src, depend = [], CPPPATH = CPPPATH) + group = DefineGroup('POSIX', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/examples/utest/testcases/kernel/SConscript b/examples/utest/testcases/kernel/SConscript index ab98c6065b..95959f1f9b 100644 --- a/examples/utest/testcases/kernel/SConscript +++ b/examples/utest/testcases/kernel/SConscript @@ -43,6 +43,6 @@ if GetDepend(['UTEST_THREAD_TC']): CPPPATH = [cwd] -group = DefineGroup('utestcases', src, depend = [], CPPPATH = CPPPATH) +group = DefineGroup('utestcases', src, depend = [''], CPPPATH = CPPPATH) Return('group') diff --git a/libcpu/arc/common/SConscript b/libcpu/arc/common/SConscript index 80c21d87eb..84f58e8959 100644 --- a/libcpu/arc/common/SConscript +++ b/libcpu/arc/common/SConscript @@ -5,6 +5,6 @@ src = Glob('*.c') CPPPATH = [cwd] -group = DefineGroup('CPU', src, depend = [], CPPPATH = CPPPATH) +group = DefineGroup('CPU', src, depend = [''], CPPPATH = CPPPATH) Return('group') -- cgit v1.3.1