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
97f35ce6
Unverified
Commit
97f35ce6
authored
Feb 05, 2019
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
string_utils: remove stack allocations
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
643c9ec9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
10 additions
and
18 deletions
+10
-18
string_utils.c
src/lxc/string_utils.c
+10
-18
No files found.
src/lxc/string_utils.c
View file @
97f35ce6
...
@@ -46,6 +46,7 @@
...
@@ -46,6 +46,7 @@
#include "config.h"
#include "config.h"
#include "lxclock.h"
#include "lxclock.h"
#include "macro.h"
#include "macro.h"
#include "memory_utils.h"
#include "namespace.h"
#include "namespace.h"
#include "parse.h"
#include "parse.h"
#include "string_utils.h"
#include "string_utils.h"
...
@@ -321,17 +322,14 @@ char *lxc_append_paths(const char *first, const char *second)
...
@@ -321,17 +322,14 @@ char *lxc_append_paths(const char *first, const char *second)
bool
lxc_string_in_list
(
const
char
*
needle
,
const
char
*
haystack
,
char
_sep
)
bool
lxc_string_in_list
(
const
char
*
needle
,
const
char
*
haystack
,
char
_sep
)
{
{
char
*
token
,
*
str
;
__do_free
char
*
str
=
NULL
;
char
*
token
;
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
sep
[
2
]
=
{
_sep
,
'\0'
};
size_t
len
;
if
(
!
haystack
||
!
needle
)
if
(
!
haystack
||
!
needle
)
return
0
;
return
0
;
len
=
strlen
(
haystack
);
str
=
must_copy_string
(
haystack
);
str
=
alloca
(
len
+
1
);
(
void
)
strlcpy
(
str
,
haystack
,
len
+
1
);
lxc_iterate_parts
(
token
,
str
,
sep
)
lxc_iterate_parts
(
token
,
str
,
sep
)
if
(
strcmp
(
needle
,
token
)
==
0
)
if
(
strcmp
(
needle
,
token
)
==
0
)
return
1
;
return
1
;
...
@@ -341,21 +339,18 @@ bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
...
@@ -341,21 +339,18 @@ bool lxc_string_in_list(const char *needle, const char *haystack, char _sep)
char
**
lxc_string_split
(
const
char
*
string
,
char
_sep
)
char
**
lxc_string_split
(
const
char
*
string
,
char
_sep
)
{
{
char
*
token
,
*
str
;
__do_free
char
*
str
=
NULL
;
char
*
token
;
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
**
tmp
=
NULL
,
**
result
=
NULL
;
char
**
tmp
=
NULL
,
**
result
=
NULL
;
size_t
result_capacity
=
0
;
size_t
result_capacity
=
0
;
size_t
result_count
=
0
;
size_t
result_count
=
0
;
int
r
,
saved_errno
;
int
r
,
saved_errno
;
size_t
len
;
if
(
!
string
)
if
(
!
string
)
return
calloc
(
1
,
sizeof
(
char
*
));
return
calloc
(
1
,
sizeof
(
char
*
));
len
=
strlen
(
string
);
str
=
must_copy_string
(
string
);
str
=
alloca
(
len
+
1
);
(
void
)
strlcpy
(
str
,
string
,
len
+
1
);
lxc_iterate_parts
(
token
,
str
,
sep
)
{
lxc_iterate_parts
(
token
,
str
,
sep
)
{
r
=
lxc_grow_array
((
void
***
)
&
result
,
&
result_capacity
,
result_count
+
1
,
16
);
r
=
lxc_grow_array
((
void
***
)
&
result
,
&
result_capacity
,
result_count
+
1
,
16
);
if
(
r
<
0
)
if
(
r
<
0
)
...
@@ -461,22 +456,19 @@ char **lxc_string_split_quoted(char *string)
...
@@ -461,22 +456,19 @@ char **lxc_string_split_quoted(char *string)
char
**
lxc_string_split_and_trim
(
const
char
*
string
,
char
_sep
)
char
**
lxc_string_split_and_trim
(
const
char
*
string
,
char
_sep
)
{
{
char
*
token
,
*
str
;
__do_free
char
*
str
=
NULL
;
char
*
token
;
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
sep
[
2
]
=
{
_sep
,
'\0'
};
char
**
result
=
NULL
;
char
**
result
=
NULL
;
size_t
result_capacity
=
0
;
size_t
result_capacity
=
0
;
size_t
result_count
=
0
;
size_t
result_count
=
0
;
int
r
,
saved_errno
;
int
r
,
saved_errno
;
size_t
i
=
0
;
size_t
i
=
0
;
size_t
len
;
if
(
!
string
)
if
(
!
string
)
return
calloc
(
1
,
sizeof
(
char
*
));
return
calloc
(
1
,
sizeof
(
char
*
));
len
=
strlen
(
string
);
str
=
must_copy_string
(
string
);
str
=
alloca
(
len
+
1
);
(
void
)
strlcpy
(
str
,
string
,
len
+
1
);
lxc_iterate_parts
(
token
,
str
,
sep
)
{
lxc_iterate_parts
(
token
,
str
,
sep
)
{
while
(
token
[
0
]
==
' '
||
token
[
0
]
==
'\t'
)
while
(
token
[
0
]
==
' '
||
token
[
0
]
==
'\t'
)
token
++
;
token
++
;
...
...
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