summaryrefslogtreecommitdiffstatshomepage
path: root/lib/libc/string0.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-02 18:38:19 +0300
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2016-05-02 18:38:19 +0300
commitbd9de5ec9020384334b63582c7640372a9a2d022 (patch)
treebc6018e2a7f02ffcd284dfcaea3f1e8d5baa054a /lib/libc/string0.c
parent5302c3e8c4c2a3b7def285df1ec95285913c6176 (diff)
downloadmicropython-bd9de5ec9020384334b63582c7640372a9a2d022.tar.gz
micropython-bd9de5ec9020384334b63582c7640372a9a2d022.zip
lib/libc/string0: Add strncpy() implementation.
Diffstat (limited to 'lib/libc/string0.c')
-rw-r--r--lib/libc/string0.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/libc/string0.c b/lib/libc/string0.c
index 1b37169edd..be003a1bc1 100644
--- a/lib/libc/string0.c
+++ b/lib/libc/string0.c
@@ -169,6 +169,15 @@ char *strcpy(char *dest, const char *src) {
return dest;
}
+char *strncpy(char *dest, const char *src, size_t dest_sz) {
+ char *d = dest;
+ while (*src && --dest_sz) {
+ *d++ = *src++;
+ }
+ *d = '\0';
+ return dest;
+}
+
// needed because gcc optimises strcpy + strcat to this
char *stpcpy(char *dest, const char *src) {
while (*src) {