Skip to content

Commit c806881

Browse files
committed
[libc] 优化system 支持gcc
1 parent ebdf19b commit c806881

File tree

5 files changed

+15
-43
lines changed

5 files changed

+15
-43
lines changed

components/finsh/msh.c

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -257,21 +257,6 @@ int msh_exec_module(const char *cmd_line, int size)
257257
rt_free(pg_name);
258258
return ret;
259259
}
260-
261-
int system(const char *command)
262-
{
263-
int ret = -RT_ENOMEM;
264-
char *cmd = rt_strdup(command);
265-
266-
if (cmd)
267-
{
268-
ret = msh_exec(cmd, rt_strlen(cmd));
269-
rt_free(cmd);
270-
}
271-
272-
return ret;
273-
}
274-
RTM_EXPORT(system);
275260
#endif /* defined(RT_USING_MODULE) && defined(RT_USING_DFS) */
276261

277262
static int _msh_exec_cmd(char *cmd, rt_size_t length, int *retp)

components/libc/compilers/armlibc/syscalls.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -319,16 +319,6 @@ int remove(const char *filename)
319319
#endif
320320
}
321321

322-
#if defined(RT_USING_FINSH) && defined(RT_USING_MODULE) && defined(RT_USING_DFS)
323-
/* use system(const char *string) implementation in the msh */
324-
#else
325-
int system(const char *string)
326-
{
327-
extern int __rt_libc_system(const char *string);
328-
return __rt_libc_system(string);
329-
}
330-
#endif
331-
332322
#ifdef __MICROLIB
333323
#include <stdio.h>
334324

components/libc/compilers/common/stdlib.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,21 @@ void __rt_libc_exit(int status)
2525
}
2626
}
2727

28-
int __rt_libc_system(const char *string)
29-
{
3028
#ifdef RT_USING_MSH
29+
int system(const char *command)
30+
{
3131
extern int msh_exec(char *cmd, rt_size_t length);
32-
msh_exec((char*)string, rt_strlen(string));
33-
#endif
34-
return 0;
32+
33+
int ret = -RT_ENOMEM;
34+
char *cmd = rt_strdup(command);
35+
36+
if (cmd)
37+
{
38+
ret = msh_exec(cmd, rt_strlen(cmd));
39+
rt_free(cmd);
40+
}
41+
42+
return ret;
3543
}
44+
RTM_EXPORT(system);
45+
#endif

components/libc/compilers/dlib/syscalls.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2021-02-13 Meco Man implement exit() and abort()
9-
* 2021-02-20 Meco Man add system()
109
*/
1110
#include <rtthread.h>
1211

@@ -17,9 +16,3 @@ void __exit (int status)
1716
__rt_libc_exit(status);
1817
while(1);
1918
}
20-
21-
int system(const char * string)
22-
{
23-
extern int __rt_libc_system(const char *string);
24-
return __rt_libc_system(string);
25-
}

components/libc/compilers/gcc/newlib/syscalls.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -308,12 +308,6 @@ _ssize_t _write_r(struct _reent *ptr, int fd, const void *buf, size_t nbytes)
308308
#endif
309309
}
310310

311-
void _system(const char *s)
312-
{
313-
extern int __rt_libc_system(const char *string);
314-
__rt_libc_system(s);
315-
}
316-
317311
/* for exit() and abort() */
318312
__attribute__ ((noreturn)) void _exit (int status)
319313
{

0 commit comments

Comments
 (0)