* search for the file named "pg_name" or "pg_name.elf" at each env path, * and return its path. return NULL when not found. */
| 426 | * and return its path. return NULL when not found. |
| 427 | */ |
| 428 | static char *_msh_exec_search_env(const char *pg_name) |
| 429 | { |
| 430 | char *result = RT_NULL; |
| 431 | char *exec_path = RT_NULL; |
| 432 | char *search_path = RT_NULL; |
| 433 | char *pos = RT_NULL; |
| 434 | char tmp_ch = '\0'; |
| 435 | |
| 436 | if (!(exec_path = getenv("PATH"))) |
| 437 | { |
| 438 | return RT_NULL; |
| 439 | } |
| 440 | |
| 441 | /* exec path may need to be modified */ |
| 442 | if (!(exec_path = strdup(exec_path))) |
| 443 | { |
| 444 | return RT_NULL; |
| 445 | } |
| 446 | |
| 447 | pos = exec_path; |
| 448 | search_path = exec_path; |
| 449 | |
| 450 | /* walk through the entire exec_path until finding the program wanted |
| 451 | or hitting its end */ |
| 452 | while (1) |
| 453 | { |
| 454 | /* env paths are seperated by ':' */ |
| 455 | if (*pos == ':' || *pos == '\0') |
| 456 | { |
| 457 | tmp_ch = *pos; |
| 458 | *pos = '\0'; |
| 459 | |
| 460 | result = _msh_exec_search_path(search_path, pg_name); |
| 461 | if (result || tmp_ch == '\0') |
| 462 | { |
| 463 | goto ret; |
| 464 | } |
| 465 | |
| 466 | pos++; |
| 467 | search_path = pos; |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | pos++; |
| 472 | } |
| 473 | |
| 474 | /* release the duplicated exec_path and return */ |
| 475 | ret: |
| 476 | rt_free(exec_path); |
| 477 | return result; |
| 478 | } |
| 479 | |
| 480 | int _msh_exec_lwp(int debug, char *cmd, rt_size_t length) |
| 481 | { |
no test coverage detected