Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
a35e5bd9
Commit
a35e5bd9
authored
8 years ago
by
Deomid Ryabkov
Committed by
Cesanta Bot
8 years ago
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
A function to make a NUL-terminated copy of mg_str
PUBLISHED_FROM=c1310b7d62f3ad6e2f24fea9f5229588c56b0bbe
parent
83fe5a17
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
mongoose.c
mongoose.c
+17
-5
mongoose.h
mongoose.h
+8
-0
No files found.
mongoose.c
View file @
a35e5bd9
...
...
@@ -1389,19 +1389,31 @@ int mg_vcasecmp(const struct mg_str *str1, const char *str2) {
return
r
;
}
st
ruct
mg_str
mg_strdup
(
const
struct
mg_str
s
)
WEAK
;
struct
mg_str
mg_strdup
(
const
struct
mg_str
s
)
{
st
atic
struct
mg_str
mg_strdup_common
(
const
struct
mg_str
s
,
int
nul_terminate
)
{
struct
mg_str
r
=
{
NULL
,
0
};
if
(
s
.
len
>
0
&&
s
.
p
!=
NULL
)
{
r
.
p
=
(
char
*
)
MG_MALLOC
(
s
.
len
);
if
(
r
.
p
!=
NULL
)
{
memcpy
((
char
*
)
r
.
p
,
s
.
p
,
s
.
len
);
char
*
sc
=
(
char
*
)
MG_MALLOC
(
s
.
len
+
(
nul_terminate
?
1
:
0
));
if
(
sc
!=
NULL
)
{
memcpy
(
sc
,
s
.
p
,
s
.
len
);
if
(
nul_terminate
)
sc
[
s
.
len
]
=
'\0'
;
r
.
p
=
sc
;
r
.
len
=
s
.
len
;
}
}
return
r
;
}
struct
mg_str
mg_strdup
(
const
struct
mg_str
s
)
WEAK
;
struct
mg_str
mg_strdup
(
const
struct
mg_str
s
)
{
return
mg_strdup_common
(
s
,
1
/* NUL-terminate */
);
}
struct
mg_str
mg_strdup_nul
(
const
struct
mg_str
s
)
WEAK
;
struct
mg_str
mg_strdup_nul
(
const
struct
mg_str
s
)
{
return
mg_strdup_common
(
s
,
0
/* NUL-terminate */
);
}
int
mg_strcmp
(
const
struct
mg_str
str1
,
const
struct
mg_str
str2
)
WEAK
;
int
mg_strcmp
(
const
struct
mg_str
str1
,
const
struct
mg_str
str2
)
{
size_t
i
=
0
;
...
...
This diff is collapsed.
Click to expand it.
mongoose.h
View file @
a35e5bd9
...
...
@@ -1789,7 +1789,15 @@ int mg_vcmp(const struct mg_str *str2, const char *str1);
*/
int
mg_vcasecmp
(
const
struct
mg_str
*
str2
,
const
char
*
str1
);
/* Creates a copy of s (heap-allocated). */
struct
mg_str
mg_strdup
(
const
struct
mg_str
s
);
/*
* Creates a copy of s (heap-allocated).
* Resulting string is NUL-terminated (but NUL is not included in len).
*/
struct
mg_str
mg_strdup_nul
(
const
struct
mg_str
s
);
int
mg_strcmp
(
const
struct
mg_str
str1
,
const
struct
mg_str
str2
);
int
mg_strncmp
(
const
struct
mg_str
str1
,
const
struct
mg_str
str2
,
size_t
n
);
...
...
This diff is collapsed.
Click to expand it.
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