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
27bd7792
Unverified
Commit
27bd7792
authored
Oct 18, 2018
by
Christian Brauner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
include: simplify strlcpy()
Signed-off-by:
Christian Brauner
<
christian.brauner@ubuntu.com
>
parent
a542f5a7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
7 additions
and
33 deletions
+7
-33
strlcpy.c
src/include/strlcpy.c
+7
-33
No files found.
src/include/strlcpy.c
View file @
27bd7792
...
...
@@ -19,43 +19,17 @@
* This function has been copied from musl.
*/
#include <limits.h>
#include <stdint.h>
#include <string.h>
#define ALIGN (sizeof(size_t) - 1)
#define ONES ((size_t)-1 / UCHAR_MAX)
#define HIGHS (ONES * (UCHAR_MAX / 2 + 1))
#define HASZERO(x) (((x)-ONES) & ~(x)&HIGHS)
size_t
strlcpy
(
char
*
d
,
const
char
*
s
,
size_t
n
)
size_t
strlcpy
(
char
*
dest
,
const
char
*
src
,
size_t
size
)
{
char
*
d0
=
d
;
size_t
*
wd
;
const
size_t
*
ws
;
if
(
!
n
--
)
goto
finish
;
size_t
ret
=
strlen
(
src
);
if
(((
uintptr_t
)
s
&
ALIGN
)
==
((
uintptr_t
)
d
&
ALIGN
))
{
for
(;
((
uintptr_t
)
s
&
ALIGN
)
&&
n
&&
(
*
d
=
*
s
);
n
--
,
s
++
,
d
++
)
;
if
(
n
&&
*
s
)
{
wd
=
(
void
*
)
d
;
ws
=
(
const
void
*
)
s
;
for
(;
n
>=
sizeof
(
size_t
)
&&
!
HASZERO
(
*
ws
);
n
-=
sizeof
(
size_t
),
ws
++
,
wd
++
)
*
wd
=
*
ws
;
d
=
(
void
*
)
wd
;
s
=
(
const
void
*
)
ws
;
}
if
(
size
)
{
size_t
len
=
(
ret
>=
size
)
?
size
-
1
:
ret
;
memcpy
(
dest
,
src
,
len
);
dest
[
len
]
=
'\0'
;
}
for
(;
n
&&
(
*
d
=
*
s
);
n
--
,
s
++
,
d
++
)
;
*
d
=
0
;
finish:
return
d
-
d0
+
strlen
(
s
);
return
ret
;
}
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