Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
L
linux
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
linux
Commits
0297761d
Commit
0297761d
authored
May 24, 2003
by
Linus Torvalds
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add 'strlcpy()' implementation
parent
b9fdbdca
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
include/linux/string.h
include/linux/string.h
+3
-0
lib/string.c
lib/string.c
+27
-0
No files found.
include/linux/string.h
View file @
0297761d
...
...
@@ -28,6 +28,9 @@ extern char * strcpy(char *,const char *);
#ifndef __HAVE_ARCH_STRNCPY
extern
char
*
strncpy
(
char
*
,
const
char
*
,
__kernel_size_t
);
#endif
#ifndef __HAVE_ARCH_STRLCPY
size_t
strlcpy
(
char
*
,
const
char
*
,
size_t
);
#endif
#ifndef __HAVE_ARCH_STRCAT
extern
char
*
strcat
(
char
*
,
const
char
*
);
#endif
...
...
lib/string.c
View file @
0297761d
...
...
@@ -22,6 +22,7 @@
#include <linux/types.h>
#include <linux/string.h>
#include <linux/ctype.h>
#include <linux/module.h>
#ifndef __HAVE_ARCH_STRNICMP
/**
...
...
@@ -94,6 +95,32 @@ char * strncpy(char * dest,const char *src,size_t count)
}
#endif
#ifndef __HAVE_ARCH_STRLCPY
/**
* strlcpy - Copy a %NUL terminated string into a sized buffer
* @dest: Where to copy the string to
* @src: Where to copy the string from
* @size: size of destination buffer
*
* Compatible with *BSD: the result is always a valid
* NUL-terminated string that fits in the buffer (unless,
* of course, the buffer size is zero). It does not pad
* out the result like strncpy() does.
*/
size_t
strlcpy
(
char
*
dest
,
const
char
*
src
,
size_t
size
)
{
size_t
ret
=
strlen
(
src
);
if
(
size
)
{
size_t
len
=
(
ret
>=
size
)
?
size
-
1
:
ret
;
memcpy
(
dest
,
src
,
len
);
dest
[
len
]
=
'\0'
;
}
return
ret
;
}
EXPORT_SYMBOL
(
strlcpy
);
#endif
#ifndef __HAVE_ARCH_STRCAT
/**
* strcat - Append one %NUL-terminated string to another
...
...
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