All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: will.deacon@arm.com, kvm@vger.kernel.org
Cc: Szabolcs.Nagy@arm.com, marc.zyngier@arm.com,
	kvmarm@lists.cs.columbia.edu
Subject: [PATCH 10/12] check for and use C library provided strlcpy and strlcat
Date: Fri, 17 Jul 2015 17:02:16 +0100	[thread overview]
Message-ID: <1437148938-5394-11-git-send-email-andre.przywara@arm.com> (raw)
In-Reply-To: <1437148938-5394-1-git-send-email-andre.przywara@arm.com>

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>
---
 Makefile                 |  5 +++++
 config/feature-tests.mak | 10 ++++++++++
 include/kvm/strbuf.h     |  2 ++
 util/strbuf.c            |  2 ++
 4 files changed, 19 insertions(+)

diff --git a/Makefile b/Makefile
index 46e4a9d..285c482 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 6bee6c2..03cdb42 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 2beefbc..7657339 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 99d6b0c..2c6e8ad 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
-- 
2.3.5

  parent reply	other threads:[~2015-07-17 16:02 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-07-17 16:02 [PATCH 00/12] kvmtool: Improve portability Andre Przywara
2015-07-17 16:02 ` [PATCH 01/12] avoid casts when initializing structures Andre Przywara
2015-07-17 16:02 ` [PATCH 02/12] qcow: fix signedness bugs Andre Przywara
2015-07-17 16:02 ` [PATCH 03/12] kvm-ipc: use proper type for file descriptor Andre Przywara
2015-07-17 16:02 ` [PATCH 04/12] Makefile: remove unneeded -s switch on compiling BIOS files Andre Przywara
2015-07-17 16:02 ` [PATCH 05/12] ui: remove pointless double const in keymap declarations Andre Przywara
2015-07-17 16:02 ` [PATCH 06/12] kvm__set_dir(): avoid variable arguments call Andre Przywara
2015-07-17 16:49   ` Will Deacon
2015-07-17 16:02 ` [PATCH 07/12] util/util.c: avoid clang error on vsnprintf Andre Przywara
2015-07-17 16:50   ` Will Deacon
2015-07-20 14:28     ` Claudio Fontana
2015-07-20 14:46       ` Andre Przywara
2015-07-17 16:02 ` [PATCH 08/12] Fix call to connect() Andre Przywara
2015-07-17 16:02 ` [PATCH 09/12] use <poll.h> instead of <sys/poll.h> Andre Przywara
2015-07-17 16:02 ` Andre Przywara [this message]
2015-07-17 16:02 ` [PATCH 11/12] avoid using predefined PAGE_SIZE Andre Przywara
2015-07-17 16:47   ` Szabolcs Nagy
2015-07-17 16:02 ` [PATCH 12/12] remove KVM_CAP_MAX_VCPUS hack Andre Przywara
2015-07-17 16:52 ` [PATCH 00/12] kvmtool: Improve portability Will Deacon

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1437148938-5394-11-git-send-email-andre.przywara@arm.com \
    --to=andre.przywara@arm.com \
    --cc=Szabolcs.Nagy@arm.com \
    --cc=kvm@vger.kernel.org \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=marc.zyngier@arm.com \
    --cc=will.deacon@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.