aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndre Przywara <andre.przywara@arm.com>2015-07-17 17:02:16 +0100
committerWill Deacon <will.deacon@arm.com>2015-07-20 18:25:48 +0100
commit8f22adc4230f07980a318ad1662fba5af0c131c1 (patch)
tree5740e0942db90a7fbe0c1aa65480399460edef0a
parent52c22e6e64a94cc701d86587d32cd3822ac5c293 (diff)
downloadkvmtool-8f22adc4230f07980a318ad1662fba5af0c131c1.tar.gz
check for and use C library provided strlcpy and strlcat
The musl-libc library provides implementations of strlcpy and strlcat, so introduce a feature check for it and only use the kvmtool implementation if there is no library support for it. This avoids clashes with the public definition. Signed-off-by: Andre Przywara <andre.przywara@arm.com> Signed-off-by: Will Deacon <will.deacon@arm.com>
-rw-r--r--Makefile5
-rw-r--r--config/feature-tests.mak10
-rw-r--r--include/kvm/strbuf.h2
-rw-r--r--util/strbuf.c2
4 files changed, 19 insertions, 0 deletions
diff --git a/Makefile b/Makefile
index 46e4a9d3..285c482c 100644
--- a/Makefile
+++ b/Makefile
@@ -199,6 +199,11 @@ endif
# On a given system, some libs may link statically, some may not; so, check
# both and only build those that link!
+ifeq ($(call try-build,$(SOURCE_STRLCPY),$(CFLAGS),),y)
+ CFLAGS_DYNOPT += -DHAVE_STRLCPY
+ CFLAGS_STATOPT += -DHAVE_STRLCPY
+endif
+
ifeq ($(call try-build,$(SOURCE_BFD),$(CFLAGS),-lbfd -static),y)
CFLAGS_STATOPT += -DCONFIG_HAS_BFD
OBJS_STATOPT += symbol.o
diff --git a/config/feature-tests.mak b/config/feature-tests.mak
index 6bee6c2e..03cdb423 100644
--- a/config/feature-tests.mak
+++ b/config/feature-tests.mak
@@ -196,3 +196,13 @@ int main(void)
return 0;
}
endef
+
+define SOURCE_STRLCPY
+#include <string.h>
+
+int main(void)
+{
+ strlcpy(NULL, NULL, 0);
+ return 0;
+}
+endef
diff --git a/include/kvm/strbuf.h b/include/kvm/strbuf.h
index 2beefbc3..76573394 100644
--- a/include/kvm/strbuf.h
+++ b/include/kvm/strbuf.h
@@ -6,8 +6,10 @@
int prefixcmp(const char *str, const char *prefix);
+#ifndef HAVE_STRLCPY
extern size_t strlcat(char *dest, const char *src, size_t count);
extern size_t strlcpy(char *dest, const char *src, size_t size);
+#endif
/* some inline functions */
diff --git a/util/strbuf.c b/util/strbuf.c
index 99d6b0c0..2c6e8ad7 100644
--- a/util/strbuf.c
+++ b/util/strbuf.c
@@ -13,6 +13,7 @@ int prefixcmp(const char *str, const char *prefix)
}
}
+#ifndef HAVE_STRLCPY
/**
* strlcat - Append a length-limited, %NUL-terminated string to another
* @dest: The string to be appended to
@@ -60,3 +61,4 @@ size_t strlcpy(char *dest, const char *src, size_t size)
}
return ret;
}
+#endif