diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 14:09:15 -0600 |
---|---|---|
committer | Timo Teräs <timo.teras@iki.fi> | 2021-12-29 20:14:41 +0200 |
commit | 2c3cef8787198455f70fb530157ba413b77a2b1e (patch) | |
tree | 82f797c6ee5f634d5f20046968fa08e22f9e4573 /portability/strlcpy.c | |
parent | 03a5e6d9b9978c4e2fc6b904da379407ab9452bf (diff) | |
download | apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.gz apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.bz2 apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.xz apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.zip |
portability: take over strlcpy
Diffstat (limited to 'portability/strlcpy.c')
-rw-r--r-- | portability/strlcpy.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/portability/strlcpy.c b/portability/strlcpy.c new file mode 100644 index 0000000..6ce46e3 --- /dev/null +++ b/portability/strlcpy.c @@ -0,0 +1,13 @@ +#include <stddef.h> +#include <string.h> + +size_t strlcpy(char *dst, const char *src, size_t size) +{ + size_t ret = strlen(src), len; + if (!size) return ret; + len = ret; + if (len >= size) len = size - 1; + memcpy(dst, src, len); + dst[len] = 0; + return ret; +} |