From: Sascha Hauer <s.hauer@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 1/3] string: Add (x)memdup
Date: Tue, 26 Nov 2013 13:17:18 +0100 [thread overview]
Message-ID: <1385468240-3915-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1385468240-3915-1-git-send-email-s.hauer@pengutronix.de>
It's a common task to duplicate some memory. Add (x)memdup functions.
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
include/string.h | 2 ++
include/xfuncs.h | 1 +
lib/string.c | 14 ++++++++++++++
lib/xfuncs.c | 10 ++++++++++
4 files changed, 27 insertions(+)
diff --git a/include/string.h b/include/string.h
index b906e15..a833da1 100644
--- a/include/string.h
+++ b/include/string.h
@@ -3,4 +3,6 @@
#include <linux/string.h>
+void *memdup(const void *, size_t);
+
#endif /* __STRING_H */
diff --git a/include/xfuncs.h b/include/xfuncs.h
index 261aaa5..8efc99d 100644
--- a/include/xfuncs.h
+++ b/include/xfuncs.h
@@ -8,5 +8,6 @@ void *xrealloc(void *ptr, size_t size);
void *xzalloc(size_t size);
char *xstrdup(const char *s);
void* xmemalign(size_t alignment, size_t bytes);
+void* xmemdup(const void *orig, size_t size);
#endif /* __XFUNCS_H */
diff --git a/lib/string.c b/lib/string.c
index eeec137..ceced7f 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -725,3 +725,17 @@ void *memchr_inv(const void *start, int c, size_t bytes)
return check_bytes8(start, value, bytes % 8);
}
EXPORT_SYMBOL(memchr_inv);
+
+void *memdup(const void *orig, size_t size)
+{
+ void *buf;
+
+ buf = malloc(size);
+ if (!buf)
+ return NULL;
+
+ memcpy(buf, orig, size);
+
+ return buf;
+}
+EXPORT_SYMBOL(memdup);
diff --git a/lib/xfuncs.c b/lib/xfuncs.c
index db85720..86d0013 100644
--- a/lib/xfuncs.c
+++ b/lib/xfuncs.c
@@ -75,3 +75,13 @@ void* xmemalign(size_t alignment, size_t bytes)
return p;
}
EXPORT_SYMBOL(xmemalign);
+
+void *xmemdup(const void *orig, size_t size)
+{
+ void *buf = xmalloc(size);
+
+ memcpy(buf, orig, size);
+
+ return buf;
+}
+EXPORT_SYMBOL(xmemdup);
--
1.8.4.2
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2013-11-26 12:17 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-26 12:17 [PATCH v2] OMAP gpmc bus driver support Sascha Hauer
2013-11-26 12:17 ` Sascha Hauer [this message]
2013-11-26 12:17 ` [PATCH 2/3] device: Add functions to add resources Sascha Hauer
2013-11-26 12:17 ` [PATCH 3/3] bus: Add omap gpmc driver Sascha Hauer
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=1385468240-3915-2-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.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