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

Function args_append

components/lwp/lwp_args.c:82–132  ·  view source on GitHub ↗

* @brief Appends an argument or environment variable to the LWP arguments info structure * * @param[in,out] ai Pointer to the arguments info structure * @param[in] str_addr Address of the string to append (user or kernel space) * @param[in] str_len Length of the string to append * @param[in] atype Type of argument being appended (LWP_ARGS_TYPE_*) * * @return rt_err_t RT_EOK on success, -RT_

Source from the content-addressed store, hash-verified

80 * growing the string buffer into 2 times its current size if buffer is full.
81 */
82static rt_err_t args_append(struct lwp_args_info *ai, const char *str_addr,
83 size_t str_len, enum lwp_args_type atype)
84{
85 rt_err_t error;
86 char *str_bufaddr;
87
88 if (ai->strings_length + str_len + 1 > ai->str_buf_size)
89 {
90 /* reallocate buffer for this */
91 void *newptr;
92 newptr = rt_realloc(ai->str_buf, ai->str_buf_size * 2);
93 if (!newptr)
94 return -RT_ENOMEM;
95 ai->str_buf = newptr;
96 ai->str_buf_size *= 2;
97 }
98
99 /* append new string to string buffer and update strings_length */
100 str_bufaddr = &ai->str_buf[ai->strings_length];
101 if (atype == LWP_ARGS_TYPE_KARG || atype == LWP_ARGS_TYPE_KENVP)
102 {
103 strcpy(str_bufaddr, str_addr);
104 ai->strings_length += str_len + 1;
105 }
106 else
107 {
108 lwp_get_from_user(str_bufaddr, (void *)str_addr, str_len);
109 ai->strings_length += str_len;
110 ai->str_buf[ai->strings_length++] = '\0';
111 }
112
113 /* append new argument or environment */
114 switch (atype)
115 {
116 case LWP_ARGS_TYPE_ARG:
117 case LWP_ARGS_TYPE_KARG:
118 error = _strvec_append(&ai->argv, str_bufaddr);
119 if (!error && ai->argv.string_count == 1)
120 {
121 ai->argv0_strlen = str_len;
122 }
123 break;
124 case LWP_ARGS_TYPE_ENVP:
125 case LWP_ARGS_TYPE_KENVP:
126 error = _strvec_append(&ai->envp, str_bufaddr);
127 break;
128 default:
129 break;
130 }
131 return error;
132}
133
134
135/**

Callers 2

lwp_args_putFunction · 0.85
lwp_args_load_scriptFunction · 0.85

Calls 3

rt_reallocFunction · 0.85
lwp_get_from_userFunction · 0.85
_strvec_appendFunction · 0.85

Tested by

no test coverage detected