4
0
mirror of https://github.com/RT-Thread/rt-thread.git synced 2025-02-28 05:37:04 +08:00

[libc] 优化system 支持gcc

This commit is contained in:
Meco Man 2021-09-27 22:20:21 -04:00
parent ebdf19bf0f
commit c80688126a
5 changed files with 15 additions and 43 deletions

View File

@ -257,21 +257,6 @@ int msh_exec_module(const char *cmd_line, int size)
rt_free(pg_name); rt_free(pg_name);
return ret; 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) */ #endif /* defined(RT_USING_MODULE) && defined(RT_USING_DFS) */
static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp) static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)

View File

@ -319,16 +319,6 @@ int remove(const char *filename)
#endif #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 #ifdef __MICROLIB
#include <stdio.h> #include <stdio.h>

View File

@ -25,11 +25,21 @@ void __rt_libc_exit(int status)
} }
} }
int __rt_libc_system(const char *string)
{
#ifdef RT_USING_MSH #ifdef RT_USING_MSH
int system(const char *command)
{
extern int msh_exec(char *cmd, rt_size_t length); extern int msh_exec(char *cmd, rt_size_t length);
msh_exec((char*)string, rt_strlen(string));
#endif int ret = -RT_ENOMEM;
return 0; char *cmd = rt_strdup(command);
if (cmd)
{
ret = msh_exec(cmd, rt_strlen(cmd));
rt_free(cmd);
} }
return ret;
}
RTM_EXPORT(system);
#endif

View File

@ -6,7 +6,6 @@
* Change Logs: * Change Logs:
* Date Author Notes * Date Author Notes
* 2021-02-13 Meco Man implement exit() and abort() * 2021-02-13 Meco Man implement exit() and abort()
* 2021-02-20 Meco Man add system()
*/ */
#include <rtthread.h> #include <rtthread.h>
@ -17,9 +16,3 @@ void __exit (int status)
__rt_libc_exit(status); __rt_libc_exit(status);
while(1); while(1);
} }
int system(const char * string)
{
extern int __rt_libc_system(const char *string);
return __rt_libc_system(string);
}

View File

@ -308,12 +308,6 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
#endif #endif
} }
void _system(const char *s)
{
extern int __rt_libc_system(const char *string);
__rt_libc_system(s);
}
/* for exit() and abort() */ /* for exit() and abort() */
__attribute__ ((noreturn)) void _exit (int status) __attribute__ ((noreturn)) void _exit (int status)
{ {