Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/c/generic/task.c

    r9d58539 r9f5cf68  
    201201 *
    202202 * 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 */
     213int 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
    203239 * loader API. Arguments are passed as a null-terminated list of arguments.
    204240 *
     
    216252        va_list ap;
    217253        const char *arg;
    218         const char **arglist;
    219254        int cnt = 0;
    220255       
     
    226261        va_end(ap);
    227262       
    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;
    235263        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);
    240265        va_end(ap);
    241266       
    242         /* Spawn task. */
    243         int rc = task_spawnv(task_id, path, arglist);
    244        
    245         /* Free argument list. */
    246         free(arglist);
    247267        return rc;
    248268}
Note: See TracChangeset for help on using the changeset viewer.