From c80688126a013c53334464799e28fcf2e4f4fb8c Mon Sep 17 00:00:00 2001 From: Meco Man <920369182@qq.com> Date: Mon, 27 Sep 2021 22:20:21 -0400 Subject: [PATCH] =?UTF-8?q?[libc]=20=E4=BC=98=E5=8C=96system=20=E6=94=AF?= =?UTF-8?q?=E6=8C=81gcc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/finsh/msh.c | 15 -------------- components/libc/compilers/armlibc/syscalls.c | 10 ---------- components/libc/compilers/common/stdlib.c | 20 ++++++++++++++----- components/libc/compilers/dlib/syscalls.c | 7 ------- .../libc/compilers/gcc/newlib/syscalls.c | 6 ------ 5 files changed, 15 insertions(+), 43 deletions(-) diff --git a/components/finsh/msh.c b/components/finsh/msh.c index 86985c561c..18182ca264 100644 --- a/components/finsh/msh.c +++ b/components/finsh/msh.c @@ -257,21 +257,6 @@ int msh_exec_module(const char *cmd_line, int size) rt_free(pg_name); return ret; } - -int system(const char *command) -{ - int ret = -RT_ENOMEM; - char *cmd = rt_strdup(command); - - if (cmd) - { - ret = msh_exec(cmd, rt_strlen(cmd)); - rt_free(cmd); - } - - return ret; -} -RTM_EXPORT(system); #endif /* defined(RT_USING_MODULE) && defined(RT_USING_DFS) */ static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) diff --git a/components/libc/compilers/armlibc/syscalls.c b/components/libc/compilers/armlibc/syscalls.c index 7d8ec2e8b4..3b1627d82a 100644 --- a/components/libc/compilers/armlibc/syscalls.c +++ b/components/libc/compilers/armlibc/syscalls.c @@ -319,16 +319,6 @@ int remove(const char *filename) #endif } -#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS) -/* use system(const char *string) implementation in the msh */ -#else -int system(const char *string) -{ - extern int __rt_libc_system(const char *string); - return __rt_libc_system(string); -} -#endif - #ifdef __MICROLIB #include diff --git a/components/libc/compilers/common/stdlib.c b/components/libc/compilers/common/stdlib.c index 16a13afb83..6cc0b9fdac 100644 --- a/components/libc/compilers/common/stdlib.c +++ b/components/libc/compilers/common/stdlib.c @@ -25,11 +25,21 @@ void __rt_libc_exit(int status) } } -int __rt_libc_system(const char *string) -{ #ifdef RT_USING_MSH +int system(const char *command) +{ extern int msh_exec(char *cmd, rt_size_t length); - msh_exec((char*)string, rt_strlen(string)); -#endif - return 0; + + int ret = -RT_ENOMEM; + char *cmd = rt_strdup(command); + + if (cmd) + { + ret = msh_exec(cmd, rt_strlen(cmd)); + rt_free(cmd); + } + + return ret; } +RTM_EXPORT(system); +#endif diff --git a/components/libc/compilers/dlib/syscalls.c b/components/libc/compilers/dlib/syscalls.c index e1c9562b3a..1ee6a3bc12 100644 --- a/components/libc/compilers/dlib/syscalls.c +++ b/components/libc/compilers/dlib/syscalls.c @@ -6,7 +6,6 @@ * Change Logs: * Date Author Notes * 2021-02-13 Meco Man implement exit() and abort() - * 2021-02-20 Meco Man add system() */ #include @@ -17,9 +16,3 @@ void __exit (int status) __rt_libc_exit(status); while(1); } - -int system(const char * string) -{ - extern int __rt_libc_system(const char *string); - return __rt_libc_system(string); -} diff --git a/components/libc/compilers/gcc/newlib/syscalls.c b/components/libc/compilers/gcc/newlib/syscalls.c index 8b7ff9efdb..f5a2c16ecc 100644 --- a/components/libc/compilers/gcc/newlib/syscalls.c +++ b/components/libc/compilers/gcc/newlib/syscalls.c @@ -308,12 +308,6 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes) #endif } -void _system(const char *s) -{ - extern int __rt_libc_system(const char *string); - __rt_libc_system(s); -} - /* for exit() and abort() */ __attribute__ ((noreturn)) void _exit (int status) { -- GitLab