Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 9f5cf68 in mainline


Ignore:
Timestamp:
2012-08-16T18:51:52Z (9 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master
Children:
b6a088f
Parents:
dbf2ca4
Message:

implement va_list variant of task_spawn()

Location:
uspace/lib/c
Files:
2 edited

Legend:

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

    rdbf2ca4 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}
  • uspace/lib/c/include/task.h

    rdbf2ca4 r9f5cf68  
    3838#include <sys/types.h>
    3939#include <abi/proc/task.h>
     40#include <stdarg.h>
    4041
    4142typedef enum {
     
    4849extern int task_kill(task_id_t);
    4950
    50 extern task_id_t task_spawn(const char *, const char *const[], int *);
    5151extern int task_spawnv(task_id_t *, const char *path, const char *const []);
    5252extern int task_spawnvf(task_id_t *, const char *path, const char *const [],
    5353    int *const []);
     54extern int task_spawn(task_id_t *, const char *path, int, va_list ap);
    5455extern int task_spawnl(task_id_t *, const char *path, ...);
    5556
Note: See TracChangeset for help on using the changeset viewer.