diff mbox

[RFC,7/8] cutil: add strocat(), to concat a string to an offset in another

Message ID 1316443309-23843-8-git-send-email-mdroth@linux.vnet.ibm.com
State New
Headers show

Commit Message

Michael Roth Sept. 19, 2011, 2:41 p.m. UTC
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
---
 cutils.c      |    8 ++++++++
 qemu-common.h |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)

Comments

Paolo Bonzini Sept. 20, 2011, 10:43 a.m. UTC | #1
On 09/19/2011 04:41 PM, Michael Roth wrote:
> +/* concat first 'offset' chars in 'dest' with 'src' */
> +char *strocat(char *buf, const char *src, int offset)
> +{
> +    memcpy(&buf[offset], src, strlen(src));
> +    buf[offset+strlen(src)] = '\0';

This is just strcpy(&buf[offset], src);

> +    return buf;
> +}

Paolo
diff mbox

Patch

diff --git a/cutils.c b/cutils.c
index c91f887..0835834 100644
--- a/cutils.c
+++ b/cutils.c
@@ -84,6 +84,14 @@  int stristart(const char *str, const char *val, const char **ptr)
     return 1;
 }
 
+/* concat first 'offset' chars in 'dest' with 'src' */
+char *strocat(char *buf, const char *src, int offset)
+{
+    memcpy(&buf[offset], src, strlen(src));
+    buf[offset+strlen(src)] = '\0';
+    return buf;
+}
+
 /* XXX: use host strnlen if available ? */
 int qemu_strnlen(const char *s, int max_len)
 {
diff --git a/qemu-common.h b/qemu-common.h
index 404c421..0a9b919 100644
--- a/qemu-common.h
+++ b/qemu-common.h
@@ -138,6 +138,7 @@  void pstrcpy(char *buf, int buf_size, const char *str);
 char *pstrcat(char *buf, int buf_size, const char *s);
 int strstart(const char *str, const char *val, const char **ptr);
 int stristart(const char *str, const char *val, const char **ptr);
+char *strocat(char *dest, const char *src, int offset);
 int qemu_strnlen(const char *s, int max_len);
 time_t mktimegm(struct tm *tm);
 int qemu_fls(int i);