MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / _msh_exec_search_path

Function _msh_exec_search_path

components/finsh/msh.c:374–422  ·  view source on GitHub ↗

* search for the file named "pg_name" or "pg_name.elf" at the given directory, * and return its path. return NULL when not found. */

Source from the content-addressed store, hash-verified

372 * and return its path. return NULL when not found.
373 */
374static char *_msh_exec_search_path(const char *path, const char *pg_name)
375{
376 char *path_buffer = RT_NULL;
377 ssize_t pg_len = strlen(pg_name);
378 ssize_t base_len = 0;
379
380 if (path)
381 {
382 base_len = strlen(path);
383 }
384
385 path_buffer = rt_malloc(base_len + pg_len + 6);
386 if (path_buffer == RT_NULL)
387 {
388 return RT_NULL; /* no mem */
389 }
390
391 if (base_len > 0)
392 {
393 memcpy(path_buffer, path, base_len);
394 path_buffer[base_len] = '/';
395 path_buffer[base_len + 1] = '\0';
396 }
397 else
398 {
399 *path_buffer = '\0';
400 }
401 strcat(path_buffer, pg_name);
402
403 if (_msh_lwp_cmd_exists(path_buffer))
404 {
405 return path_buffer;
406 }
407
408 if (strstr(path_buffer, ".elf") != NULL)
409 {
410 goto not_found;
411 }
412
413 strcat(path_buffer, ".elf");
414 if (_msh_lwp_cmd_exists(path_buffer))
415 {
416 return path_buffer;
417 }
418
419not_found:
420 rt_free(path_buffer);
421 return RT_NULL;
422}
423
424/*
425 * search for the file named "pg_name" or "pg_name.elf" at each env path,

Callers 2

_msh_exec_search_envFunction · 0.85
_msh_exec_lwpFunction · 0.85

Calls 3

rt_mallocFunction · 0.85
_msh_lwp_cmd_existsFunction · 0.85
rt_freeFunction · 0.85

Tested by

no test coverage detected