Changes in uspace/lib/c/generic/task.c [9f5cf68:9d58539] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
r9f5cf68 r9d58539 201 201 * 202 202 * This is really just a convenience wrapper over the more complicated 203 * loader API. Arguments are passed in a va_list.204 *205 * @param id If not NULL, the ID of the task is stored here on success.206 * @param path Pathname of the binary to execute.207 * @param cnt Number of arguments.208 * @param ap Command-line arguments.209 *210 * @return Zero on success or negative error code.211 *212 */213 int task_spawn(task_id_t *task_id, const char *path, int cnt, va_list ap)214 {215 /* Allocate argument list. */216 const char **arglist = malloc(cnt * sizeof(const char *));217 if (arglist == NULL)218 return ENOMEM;219 220 /* Fill in arguments. */221 const char *arg;222 cnt = 0;223 do {224 arg = va_arg(ap, const char *);225 arglist[cnt++] = arg;226 } while (arg != NULL);227 228 /* Spawn task. */229 int rc = task_spawnv(task_id, path, arglist);230 231 /* Free argument list. */232 free(arglist);233 return rc;234 }235 236 /** Create a new task by running an executable from the filesystem.237 *238 * This is really just a convenience wrapper over the more complicated239 203 * loader API. Arguments are passed as a null-terminated list of arguments. 240 204 * … … 252 216 va_list ap; 253 217 const char *arg; 218 const char **arglist; 254 219 int cnt = 0; 255 220 … … 261 226 va_end(ap); 262 227 228 /* Allocate argument list. */ 229 arglist = malloc(cnt * sizeof(const char *)); 230 if (arglist == NULL) 231 return ENOMEM; 232 233 /* Fill in arguments. */ 234 cnt = 0; 263 235 va_start(ap, path); 264 int rc = task_spawn(task_id, path, cnt, ap); 236 do { 237 arg = va_arg(ap, const char *); 238 arglist[cnt++] = arg; 239 } while (arg != NULL); 265 240 va_end(ap); 266 241 242 /* Spawn task. */ 243 int rc = task_spawnv(task_id, path, arglist); 244 245 /* Free argument list. */ 246 free(arglist); 267 247 return rc; 268 248 }
Note:
See TracChangeset
for help on using the changeset viewer.