diff options
author | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 14:09:15 -0600 |
---|---|---|
committer | Ariadne Conill <ariadne@dereferenced.org> | 2021-12-14 14:09:15 -0600 |
commit | aff17d7e25c06521e2f9d85c3d8fdfc85eae498c (patch) | |
tree | 2ed63cff051cbdfdca73516576633addcf2f0a57 | |
parent | 0a5db96c5c40409f1b627e34f83efe88d2e6feaa (diff) | |
download | apk-tools-feature/macos.tar.gz apk-tools-feature/macos.tar.bz2 apk-tools-feature/macos.tar.xz apk-tools-feature/macos.zip |
portability: take over strlcpyfeature/macos
-rw-r--r-- | portability/meson.build | 1 | ||||
-rw-r--r-- | portability/strlcpy.c | 13 | ||||
-rw-r--r-- | src/blob.c | 13 |
3 files changed, 14 insertions, 13 deletions
diff --git a/portability/meson.build b/portability/meson.build index 851dfca..90d6cd7 100644 --- a/portability/meson.build +++ b/portability/meson.build @@ -11,6 +11,7 @@ libportability_src = [] check_functions = [ ['memrchr', 'memrchr.c', 'NEED_MEMRCHR', 'string.h'], + ['strlcpy', 'strlcpy.c', 'NEED_STRLCPY', 'string.h'], ] 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; +} @@ -677,16 +677,3 @@ void apk_blob_pull_base64(apk_blob_t *b, apk_blob_t to) err: *b = APK_BLOB_NULL; } - -#if defined(__GLIBC__) && !defined(__UCLIBC__) -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; -} -#endif |