From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Pekka Enberg <penberg@kernel.org>, Ingo Molnar <mingo@elte.hu>
Cc: linux-kernel@vger.kernel.org, Lai Jiangshan <laijs@cn.fujitsu.com>
Subject: [PATCH 08/11] kvm tools: move strlcat() to util/strbuf.c
Date: Mon, 12 Dec 2011 15:15:52 +0800 [thread overview]
Message-ID: <1323674155-17570-9-git-send-email-laijs@cn.fujitsu.com> (raw)
In-Reply-To: <1323674155-17570-1-git-send-email-laijs@cn.fujitsu.com>
strlcat() is a string related function.
Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
tools/kvm/builtin-run.c | 1 +
tools/kvm/include/kvm/strbuf.h | 13 +++++++++++++
tools/kvm/include/kvm/util.h | 10 ----------
tools/kvm/util/strbuf.c | 26 ++++++++++++++++++++++++++
tools/kvm/util/util.c | 25 -------------------------
5 files changed, 40 insertions(+), 35 deletions(-)
diff --git a/tools/kvm/builtin-run.c b/tools/kvm/builtin-run.c
index 76ce657..5afc8c0 100644
--- a/tools/kvm/builtin-run.c
+++ b/tools/kvm/builtin-run.c
@@ -21,6 +21,7 @@
#include "kvm/mutex.h"
#include "kvm/term.h"
#include "kvm/util.h"
+#include "kvm/strbuf.h"
#include "kvm/vesa.h"
#include "kvm/irq.h"
#include "kvm/kvm.h"
diff --git a/tools/kvm/include/kvm/strbuf.h b/tools/kvm/include/kvm/strbuf.h
index e67ca20..8fdef7e 100644
--- a/tools/kvm/include/kvm/strbuf.h
+++ b/tools/kvm/include/kvm/strbuf.h
@@ -1,6 +1,19 @@
#ifndef __STRBUF_H__
#define __STRBUF_H__
+#include <sys/types.h>
+#include <string.h>
+
int prefixcmp(const char *str, const char *prefix);
+extern size_t strlcat(char *dest, const char *src, size_t count);
+
+/* some inline functions */
+
+static inline const char *skip_prefix(const char *str, const char *prefix)
+{
+ size_t len = strlen(prefix);
+ return strncmp(str, prefix, len) ? NULL : str + len;
+}
+
#endif
diff --git a/tools/kvm/include/kvm/util.h b/tools/kvm/include/kvm/util.h
index dc2e0b9..3e382fc 100644
--- a/tools/kvm/include/kvm/util.h
+++ b/tools/kvm/include/kvm/util.h
@@ -58,16 +58,6 @@ do { \
__stringify(cnd) "\n"); \
} while (0)
-extern size_t strlcat(char *dest, const char *src, size_t count);
-
-/* some inline functions */
-
-static inline const char *skip_prefix(const char *str, const char *prefix)
-{
- size_t len = strlen(prefix);
- return strncmp(str, prefix, len) ? NULL : str + len;
-}
-
#define MSECS_TO_USECS(s) ((s) * 1000)
/* Millisecond sleep */
diff --git a/tools/kvm/util/strbuf.c b/tools/kvm/util/strbuf.c
index ec77ab1..6632a14 100644
--- a/tools/kvm/util/strbuf.c
+++ b/tools/kvm/util/strbuf.c
@@ -1,5 +1,6 @@
/* user defined headers */
+#include <kvm/util.h>
#include <kvm/strbuf.h>
int prefixcmp(const char *str, const char *prefix)
@@ -11,3 +12,28 @@ int prefixcmp(const char *str, const char *prefix)
return (unsigned char)*prefix - (unsigned char)*str;
}
}
+
+/**
+ * strlcat - Append a length-limited, %NUL-terminated string to another
+ * @dest: The string to be appended to
+ * @src: The string to append to it
+ * @count: The size of the destination buffer.
+ */
+size_t strlcat(char *dest, const char *src, size_t count)
+{
+ size_t dsize = strlen(dest);
+ size_t len = strlen(src);
+ size_t res = dsize + len;
+
+ DIE_IF(dsize >= count);
+
+ dest += dsize;
+ count -= dsize;
+ if (len >= count)
+ len = count - 1;
+
+ memcpy(dest, src, len);
+ dest[len] = 0;
+
+ return res;
+}
diff --git a/tools/kvm/util/util.c b/tools/kvm/util/util.c
index 4efbce9..682ed6c 100644
--- a/tools/kvm/util/util.c
+++ b/tools/kvm/util/util.c
@@ -74,28 +74,3 @@ void die_perror(const char *s)
perror(s);
exit(1);
}
-
-/**
- * strlcat - Append a length-limited, %NUL-terminated string to another
- * @dest: The string to be appended to
- * @src: The string to append to it
- * @count: The size of the destination buffer.
- */
-size_t strlcat(char *dest, const char *src, size_t count)
-{
- size_t dsize = strlen(dest);
- size_t len = strlen(src);
- size_t res = dsize + len;
-
- DIE_IF(dsize >= count);
-
- dest += dsize;
- count -= dsize;
- if (len >= count)
- len = count - 1;
-
- memcpy(dest, src, len);
- dest[len] = 0;
-
- return res;
-}
--
1.7.4.4
next prev parent reply other threads:[~2011-12-12 7:16 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-12-12 7:15 [PATCH 00/11] kvm tools: cleanups Lai Jiangshan
2011-12-12 7:15 ` [PATCH 01/11] kvm tools: check condition before wait Lai Jiangshan
2011-12-12 7:15 ` [PATCH 02/11] kvm tools: fix function name Lai Jiangshan
2011-12-12 7:15 ` [PATCH 03/11] kvm tools: move threadpool.c to util/ Lai Jiangshan
2011-12-12 7:15 ` [PATCH 04/11] kvm tools: move rbtree.o " Lai Jiangshan
2011-12-12 7:15 ` [PATCH 05/11] kvm tools: add missing build output Lai Jiangshan
2011-12-12 7:15 ` [PATCH 06/11] kvm tools: move read-write.c to util/ Lai Jiangshan
2011-12-12 7:15 ` [PATCH 07/11] kvm tools: move util.c " Lai Jiangshan
2011-12-12 7:15 ` Lai Jiangshan [this message]
2011-12-12 7:15 ` [PATCH 09/11] kvm tools: narrow the C.S. of compat_mtx Lai Jiangshan
2011-12-12 7:15 ` [PATCH 10/11] kvm tools: protect shared global id in compat_mtx C.S Lai Jiangshan
2011-12-12 7:15 ` [PATCH 11/11] kvm tools: remove duplicated code Lai Jiangshan
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=1323674155-17570-9-git-send-email-laijs@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@elte.hu \
--cc=penberg@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®