summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAriadne Conill <ariadne@dereferenced.org>2021-12-14 14:09:15 -0600
committerTimo Teräs <timo.teras@iki.fi>2021-12-29 20:14:41 +0200
commit2c3cef8787198455f70fb530157ba413b77a2b1e (patch)
tree82f797c6ee5f634d5f20046968fa08e22f9e4573
parent03a5e6d9b9978c4e2fc6b904da379407ab9452bf (diff)
downloadapk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.gz
apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.bz2
apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.tar.xz
apk-tools-2c3cef8787198455f70fb530157ba413b77a2b1e.zip
portability: take over strlcpy
-rw-r--r--portability/meson.build1
-rw-r--r--portability/string.h4
-rw-r--r--portability/strlcpy.c13
-rw-r--r--src/apk_blob.h4
-rw-r--r--src/blob.c13
5 files changed, 18 insertions, 17 deletions
diff --git a/portability/meson.build b/portability/meson.build
index 51e4aee..3a680fe 100644
--- a/portability/meson.build
+++ b/portability/meson.build
@@ -6,6 +6,7 @@ libportability_src = []
check_functions = [
['memrchr', 'memrchr.c', 'NEED_MEMRCHR', 'string.h'],
+ ['strlcpy', 'strlcpy.c', 'NEED_STRLCPY', 'string.h'],
]
diff --git a/portability/string.h b/portability/string.h
index 0b8bb71..688d75b 100644
--- a/portability/string.h
+++ b/portability/string.h
@@ -3,3 +3,7 @@
#ifdef NEED_MEMRCHR
extern void *memrchr(const void *m, int c, size_t n);
#endif
+
+#ifdef NEED_STRLCPY
+size_t strlcpy(char *dst, const char *src, size_t size);
+#endif
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;
+}
diff --git a/src/apk_blob.h b/src/apk_blob.h
index 4286fbe..b2ab01f 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -127,8 +127,4 @@ void apk_blob_pull_base64(apk_blob_t *b, apk_blob_t to);
void apk_blob_pull_hexdump(apk_blob_t *b, apk_blob_t to);
int apk_blob_pull_blob_match(apk_blob_t *b, apk_blob_t match);
-#if defined(__GLIBC__) && !defined(__UCLIBC__)
-extern size_t strlcpy(char *dest, const char *src, size_t size);
-#endif
-
#endif
diff --git a/src/blob.c b/src/blob.c
index 8413a3b..27de70d 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -676,16 +676,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