summaryrefslogtreecommitdiff
path: root/components
diff options
context:
space:
mode:
authorMeco Man <[email protected]>2021-09-27 22:20:21 -0400
committerMeco Man <[email protected]>2021-09-27 22:20:21 -0400
commitc80688126a013c53334464799e28fcf2e4f4fb8c (patch)
tree628c5c404da0fe38fba9c76dc90be434ddfdd7bb /components
parentebdf19bf0fbb960102608ed76e1762230ca910bd (diff)
[libc] 优化system 支持gcc
Diffstat (limited to 'components')
-rw-r--r--components/finsh/msh.c15
-rw-r--r--components/libc/compilers/armlibc/syscalls.c10
-rw-r--r--components/libc/compilers/common/stdlib.c20
-rw-r--r--components/libc/compilers/dlib/syscalls.c7
-rw-r--r--components/libc/compilers/gcc/newlib/syscalls.c6
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 <stdio.h>
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 <rtthread.h>
@@ -17,9 +16,3 @@ void __exit (int status)
__rt_libc_exit(status);
while(1);
}
-
-int system(const char * string)
-{
- extern int __rt_libc_system(const char *string);
- return __rt_libc_system(string);
-}
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)
{