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

Function lwp_get_command_line_args

components/lwp/lwp_args.c:812–864  ·  view source on GitHub ↗

* @brief Get command line arguments from light-weight process * * @param[in] lwp Pointer to the light-weight process structure * * @return char** Returns a NULL-terminated array of argument strings on success: * - The array and each string are allocated in kernel space * - The caller is responsible for freeing using lwp_free_command_line_args() * RT_NULL Returns NULL

Source from the content-addressed store, hash-verified

810 * proper NULL termination of the argument vector.
811 */
812char **lwp_get_command_line_args(struct rt_lwp *lwp)
813{
814 size_t argc = 0;
815 char **argv = NULL;
816 int ret;
817 size_t i;
818 size_t len;
819
820 if (lwp)
821 {
822 ret = lwp_data_get(lwp, &argc, lwp->args, sizeof(argc));
823 if (ret == 0)
824 {
825 return RT_NULL;
826 }
827 argv = (char**)rt_calloc((argc + 1), sizeof(char*));
828
829 if (argv)
830 {
831 for (i = 0; i < argc; i++)
832 {
833 char *argvp = NULL;
834 ret = lwp_data_get(lwp, &argvp, &((char **)lwp->args)[1 + i], sizeof(argvp));
835 if (ret == 0)
836 {
837 goto error_exit;
838 }
839
840 len = lwp_user_strlen_ext(lwp, argvp);
841 if (len >= 0)
842 {
843 argv[i] = (char*)rt_malloc(len + 1);
844 ret = lwp_data_get(lwp, argv[i], argvp, len);
845 if (ret != len)
846 {
847 goto error_exit;
848 }
849 argv[i][len] = '\0';
850 }
851 else
852 {
853 goto error_exit;
854 }
855 }
856 argv[argc] = NULL;
857 }
858 }
859
860 return argv;
861error_exit:
862 lwp_free_command_line_args(argv);
863 return RT_NULL;
864}
865
866/**
867 * @brief Print environment variables of light-weight process

Callers 3

lwp_backtrace_frameFunction · 0.85
stat_single_showFunction · 0.85
cmdline_single_showFunction · 0.85

Calls 5

lwp_data_getFunction · 0.85
rt_callocFunction · 0.85
lwp_user_strlen_extFunction · 0.85
rt_mallocFunction · 0.85

Tested by

no test coverage detected