MCPcopy Index your code
hub / github.com/RT-Thread/rt-thread / msh_exec_module

Function msh_exec_module

components/finsh/msh.c:254–321  ·  view source on GitHub ↗

Return 0 on module executed. Other value indicate error. */

Source from the content-addressed store, hash-verified

252/* Return 0 on module executed. Other value indicate error.
253 */
254int msh_exec_module(const char *cmd_line, int size)
255{
256 int ret;
257 int fd = -1;
258 char *pg_name;
259 int length, cmd_length = 0;
260
261 if (size == 0)
262 return -RT_ERROR;
263 /* get the length of command0 */
264 while ((cmd_line[cmd_length] != ' ' && cmd_line[cmd_length] != '\t') && cmd_length < size)
265 cmd_length ++;
266
267 /* get name length */
268 length = cmd_length + 32;
269
270 /* allocate program name memory */
271 pg_name = (char *) rt_malloc(length + 3);
272 if (pg_name == RT_NULL)
273 return -RT_ENOMEM;
274
275 /* copy command0 */
276 rt_memcpy(pg_name, cmd_line, cmd_length);
277 pg_name[cmd_length] = '\0';
278
279 if (strstr(pg_name, ".mo") != RT_NULL || strstr(pg_name, ".MO") != RT_NULL)
280 {
281 /* try to open program */
282 fd = open(pg_name, O_RDONLY, 0);
283
284 /* search in /bin path */
285 if (fd < 0)
286 {
287 rt_snprintf(pg_name, length - 1, "/bin/%.*s", cmd_length, cmd_line);
288 fd = open(pg_name, O_RDONLY, 0);
289 }
290 }
291 else
292 {
293 /* add .mo and open program */
294
295 /* try to open program */
296 strcat(pg_name, ".mo");
297 fd = open(pg_name, O_RDONLY, 0);
298
299 /* search in /bin path */
300 if (fd < 0)
301 {
302 rt_snprintf(pg_name, length - 1, "/bin/%.*s.mo", cmd_length, cmd_line);
303 fd = open(pg_name, O_RDONLY, 0);
304 }
305 }
306
307 if (fd >= 0)
308 {
309 /* found program */
310 close(fd);
311 dlmodule_exec(pg_name, cmd_line, size);

Callers 1

msh_execFunction · 0.85

Calls 7

rt_mallocFunction · 0.85
rt_memcpyFunction · 0.85
rt_snprintfFunction · 0.85
dlmodule_execFunction · 0.85
rt_freeFunction · 0.85
openFunction · 0.50
closeFunction · 0.50

Tested by

no test coverage detected