147 /* ----------------------------- util_env_str ----------------------------- */ |
147 /* ----------------------------- util_env_str ----------------------------- */ |
148 |
148 |
149 |
149 |
150 NSAPI_PUBLIC char *util_env_str(const char *name, const char *value) { |
150 NSAPI_PUBLIC char *util_env_str(const char *name, const char *value) { |
151 char *t; |
151 char *t; |
152 |
152 |
153 t = (char *) MALLOC(strlen(name)+strlen(value)+2); /* 2: '=' and '\0' */ |
153 size_t len = strlen(name) + strlen(value) + 2; |
154 |
154 t = (char *) MALLOC(len); /* 2: '=' and '\0' */ |
155 sprintf(t, "%s=%s", name, value); |
155 |
|
156 snprintf(t, len, "%s=%s", name, value); |
156 |
157 |
157 return t; |
158 return t; |
158 } |
159 } |
159 |
160 |
160 |
161 |
177 util_sprintf(&env[x][y], "=%s", value); |
178 util_sprintf(&env[x][y], "=%s", value); |
178 return; |
179 return; |
179 } |
180 } |
180 *i = '='; |
181 *i = '='; |
181 } |
182 } |
|
183 } |
|
184 |
|
185 |
|
186 /* ---------------------------- util_sh_escape ---------------------------- */ |
|
187 |
|
188 |
|
189 NSAPI_PUBLIC char *util_sh_escape(char *s) |
|
190 { |
|
191 char *ns = (char *) MALLOC(strlen(s) * 2 + 1); /* worst case */ |
|
192 register char *t, *u; |
|
193 |
|
194 for(t = s, u = ns; *t; ++t, ++u) { |
|
195 if(strchr("&;`'\"|*?~<>^()[]{}$\\ #!", *t)) |
|
196 *u++ = '\\'; |
|
197 *u = *t; |
|
198 } |
|
199 *u = '\0'; |
|
200 return ns; |
182 } |
201 } |
183 |
202 |
184 |
203 |
185 /* ---------------------------- util_env_find ----------------------------- */ |
204 /* ---------------------------- util_env_find ----------------------------- */ |
186 |
205 |