Changeset 9f5cf68 in mainline
- Timestamp:
- 2012-08-16T18:51:52Z (12 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b6a088f
- Parents:
- dbf2ca4
- Location:
- uspace/lib/c
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/c/generic/task.c
rdbf2ca4 r9f5cf68 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 complicated 203 239 * loader API. Arguments are passed as a null-terminated list of arguments. 204 240 * … … 216 252 va_list ap; 217 253 const char *arg; 218 const char **arglist;219 254 int cnt = 0; 220 255 … … 226 261 va_end(ap); 227 262 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;235 263 va_start(ap, path); 236 do { 237 arg = va_arg(ap, const char *); 238 arglist[cnt++] = arg; 239 } while (arg != NULL); 264 int rc = task_spawn(task_id, path, cnt, ap); 240 265 va_end(ap); 241 266 242 /* Spawn task. */243 int rc = task_spawnv(task_id, path, arglist);244 245 /* Free argument list. */246 free(arglist);247 267 return rc; 248 268 } -
uspace/lib/c/include/task.h
rdbf2ca4 r9f5cf68 38 38 #include <sys/types.h> 39 39 #include <abi/proc/task.h> 40 #include <stdarg.h> 40 41 41 42 typedef enum { … … 48 49 extern int task_kill(task_id_t); 49 50 50 extern task_id_t task_spawn(const char *, const char *const[], int *);51 51 extern int task_spawnv(task_id_t *, const char *path, const char *const []); 52 52 extern int task_spawnvf(task_id_t *, const char *path, const char *const [], 53 53 int *const []); 54 extern int task_spawn(task_id_t *, const char *path, int, va_list ap); 54 55 extern int task_spawnl(task_id_t *, const char *path, ...); 55 56
Note:
See TracChangeset
for help on using the changeset viewer.