Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
lxc
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chen Yisong
lxc
Commits
61a1d519
Commit
61a1d519
authored
May 21, 2013
by
Christian Seiler
Committed by
Serge Hallyn
Aug 14, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add helper functions to convert va_list of char* to char**.
Signed-off-by:
Christian Seiler
<
christian@iwakd.de
>
Acked-by:
Serge E. Hallyn
<
serge.hallyn@ubuntu.com
>
parent
9c4693b8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
0 deletions
+51
-0
utils.c
src/lxc/utils.c
+46
-0
utils.h
src/lxc/utils.h
+5
-0
No files found.
src/lxc/utils.c
View file @
61a1d519
...
...
@@ -26,6 +26,7 @@
#include <unistd.h>
#include <stdlib.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/mman.h>
...
...
@@ -447,3 +448,48 @@ int sha1sum_file(char *fnam, unsigned char *digest)
return
ret
;
}
#endif
char
**
lxc_va_arg_list_to_argv
(
va_list
ap
,
size_t
skip
,
int
do_strdup
)
{
va_list
ap2
;
size_t
count
=
1
+
skip
;
char
**
result
;
/* first determine size of argument list, we don't want to reallocate
* constantly...
*/
va_copy
(
ap2
,
ap
);
while
(
1
)
{
char
*
arg
=
va_arg
(
ap2
,
char
*
);
if
(
!
arg
)
break
;
count
++
;
}
va_end
(
ap2
);
result
=
calloc
(
count
,
sizeof
(
char
*
));
if
(
!
result
)
return
NULL
;
count
=
skip
;
while
(
1
)
{
char
*
arg
=
va_arg
(
ap
,
char
*
);
if
(
!
arg
)
break
;
arg
=
do_strdup
?
strdup
(
arg
)
:
arg
;
if
(
!
arg
)
goto
oom
;
result
[
count
++
]
=
arg
;
}
/* calloc has already set last element to NULL*/
return
result
;
oom:
free
(
result
);
return
NULL
;
}
const
char
**
lxc_va_arg_list_to_argv_const
(
va_list
ap
,
size_t
skip
)
{
return
(
const
char
**
)
lxc_va_arg_list_to_argv
(
ap
,
skip
,
0
);
}
src/lxc/utils.h
View file @
61a1d519
...
...
@@ -24,6 +24,7 @@
#define _utils_h
#include <errno.h>
#include <stdarg.h>
#include <sys/types.h>
#include <unistd.h>
#include "config.h"
...
...
@@ -182,4 +183,8 @@ extern ssize_t lxc_read_nointr_expect(int fd, void* buf, size_t count, const voi
extern
int
sha1sum_file
(
char
*
fnam
,
unsigned
char
*
md_value
);
#endif
/* convert variadic argument lists to arrays (for execl type argument lists) */
extern
char
**
lxc_va_arg_list_to_argv
(
va_list
ap
,
size_t
skip
,
int
do_strdup
);
extern
const
char
**
lxc_va_arg_list_to_argv_const
(
va_list
ap
,
size_t
skip
);
#endif
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment