diff mbox

[v4,1/3] kvm-unit-tests: Add memcpy to lib/string.c

Message ID 1371738969-26658-1-git-send-email-yzt356@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Arthur Chunqi Li June 20, 2013, 2:36 p.m. UTC
Add memcpy(void *dest, const void *src, size_t n) to lib/string.c.
This function acts the same as memcpy in libc.

Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
---
 lib/libcflat.h |    1 +
 lib/string.c   |   12 ++++++++++++
 2 files changed, 13 insertions(+)

Comments

Paolo Bonzini June 21, 2013, 3:01 p.m. UTC | #1
Il 20/06/2013 16:36, Arthur Chunqi Li ha scritto:
> Add memcpy(void *dest, const void *src, size_t n) to lib/string.c.
> This function acts the same as memcpy in libc.
> 
> Signed-off-by: Arthur Chunqi Li <yzt356@gmail.com>
> ---
>  lib/libcflat.h |    1 +
>  lib/string.c   |   12 ++++++++++++
>  2 files changed, 13 insertions(+)
> 
> diff --git a/lib/libcflat.h b/lib/libcflat.h
> index 0875bd9..fadc33d 100644
> --- a/lib/libcflat.h
> +++ b/lib/libcflat.h
> @@ -50,6 +50,7 @@ extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
>  extern void puts(const char *s);
>  
>  extern void *memset(void *s, int c, size_t n);
> +extern void *memcpy(void *dest, const void *src, size_t n);
>  
>  extern long atol(const char *ptr);
>  #define ARRAY_SIZE(_a)  (sizeof(_a)/sizeof((_a)[0]))
> diff --git a/lib/string.c b/lib/string.c
> index 9dc94a1..e798f86 100644
> --- a/lib/string.c
> +++ b/lib/string.c
> @@ -42,6 +42,18 @@ void *memset(void *s, int c, size_t n)
>      return s;
>  }
>  
> +void *memcpy(void *dest, const void *src, size_t n)
> +{
> +    size_t i;
> +    char *a = dest;
> +    char *b = src;

I added a const here and pushed the three patches.

Paolo

> +
> +    for (i = 0; i < n; ++i)
> +        a[i] = b[i];
> +
> +    return dest;
> +}
> +
>  long atol(const char *ptr)
>  {
>      long acc = 0;
> 

--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/lib/libcflat.h b/lib/libcflat.h
index 0875bd9..fadc33d 100644
--- a/lib/libcflat.h
+++ b/lib/libcflat.h
@@ -50,6 +50,7 @@  extern int vsnprintf(char *buf, int size, const char *fmt, va_list va);
 extern void puts(const char *s);
 
 extern void *memset(void *s, int c, size_t n);
+extern void *memcpy(void *dest, const void *src, size_t n);
 
 extern long atol(const char *ptr);
 #define ARRAY_SIZE(_a)  (sizeof(_a)/sizeof((_a)[0]))
diff --git a/lib/string.c b/lib/string.c
index 9dc94a1..e798f86 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -42,6 +42,18 @@  void *memset(void *s, int c, size_t n)
     return s;
 }
 
+void *memcpy(void *dest, const void *src, size_t n)
+{
+    size_t i;
+    char *a = dest;
+    char *b = src;
+
+    for (i = 0; i < n; ++i)
+        a[i] = b[i];
+
+    return dest;
+}
+
 long atol(const char *ptr)
 {
     long acc = 0;