* This function will do a executable program with main function and parameters. * * @param path the full path of application module * @param cmd_line the command line of program * @param size the size of command line of program * * @return the module object */
| 423 | * @return the module object |
| 424 | */ |
| 425 | rt_module_t rt_module_exec_cmd(const char *path, const char* cmd_line, int line_size) |
| 426 | { |
| 427 | struct dfs_filesystem *fs; |
| 428 | appentry_t fptr; |
| 429 | HINSTANCE hinstlib; |
| 430 | rt_module_t module; |
| 431 | |
| 432 | char * winpath = RT_NULL; |
| 433 | char * name = RT_NULL; |
| 434 | char *full_path = RT_NULL; |
| 435 | |
| 436 | RT_DEBUG_NOT_IN_INTERRUPT; |
| 437 | |
| 438 | /* check parameters */ |
| 439 | RT_ASSERT(path != RT_NULL); |
| 440 | |
| 441 | if (*path != '/') |
| 442 | { |
| 443 | full_path = dfs_normalize_path(RT_NULL, path); |
| 444 | } |
| 445 | else |
| 446 | { |
| 447 | full_path = (const char*)path; |
| 448 | } |
| 449 | |
| 450 | /* app module should only in DFS_WIN32 */ |
| 451 | fs = dfs_filesystem_lookup(full_path); |
| 452 | if ((fs == RT_NULL) || (strcmp(fs->ops->name,"wdir") != 0)) |
| 453 | { |
| 454 | rt_kprintf("invalid path: %s\n", path); |
| 455 | goto __exit; |
| 456 | } |
| 457 | |
| 458 | /* change path */ |
| 459 | // len = strlen(full_path + 1); |
| 460 | if ((winpath = dfs_win32_dirdup((char *)full_path)) == RT_NULL) |
| 461 | { |
| 462 | rt_kprintf("out of memory, exit", path); |
| 463 | goto __exit; |
| 464 | } |
| 465 | |
| 466 | hinstlib = LoadLibrary(winpath); |
| 467 | if (hinstlib == NULL) |
| 468 | { |
| 469 | rt_kprintf("error: unable to open %s\n", winpath); |
| 470 | goto __exit; |
| 471 | } |
| 472 | |
| 473 | fptr = (appentry_t)GetProcAddress(hinstlib, "main"); |
| 474 | if (fptr == NULL) |
| 475 | { |
| 476 | rt_kprintf("error: unable to find function in %s\n", winpath); |
| 477 | FreeLibrary(hinstlib); |
| 478 | goto __exit; |
| 479 | } |
| 480 | |
| 481 | /* release winpath */ |
| 482 | rt_free(winpath); |
nothing calls this directly
no test coverage detected