[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);
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)

View File

@ -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>

View File

@ -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

View File

@ -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);
}

View File

@ -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)
{