summaryrefslogtreecommitdiff
path: root/mm/util.c
diff options
context:
space:
mode:
authorMatt Mackall <mpm@selenic.com>2006-01-08 01:01:43 -0800
committerLinus Torvalds <torvalds@g5.osdl.org>2006-01-08 20:13:41 -0800
commit30992c97ae9d01b17374fbfab76a869fb4bba500 (patch)
treeb1ea66bec56fabd80571696d0b081423dcab2340 /mm/util.c
parent50dd26ba0947aa653f0e42897aad7a4adce4e620 (diff)
downloadlinux-3.10-30992c97ae9d01b17374fbfab76a869fb4bba500.tar.gz
linux-3.10-30992c97ae9d01b17374fbfab76a869fb4bba500.tar.bz2
linux-3.10-30992c97ae9d01b17374fbfab76a869fb4bba500.zip
[PATCH] slob: introduce mm/util.c for shared functions
Add mm/util.c for functions common between SLAB and SLOB. Signed-off-by: Matt Mackall <mpm@selenic.com> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Diffstat (limited to 'mm/util.c')
-rw-r--r--mm/util.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/mm/util.c b/mm/util.c
new file mode 100644
index 00000000000..5f4bb59da63
--- /dev/null
+++ b/mm/util.c
@@ -0,0 +1,39 @@
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/module.h>
+
+/**
+ * kzalloc - allocate memory. The memory is set to zero.
+ * @size: how many bytes of memory are required.
+ * @flags: the type of memory to allocate.
+ */
+void *kzalloc(size_t size, gfp_t flags)
+{
+ void *ret = kmalloc(size, flags);
+ if (ret)
+ memset(ret, 0, size);
+ return ret;
+}
+EXPORT_SYMBOL(kzalloc);
+
+/*
+ * kstrdup - allocate space for and copy an existing string
+ *
+ * @s: the string to duplicate
+ * @gfp: the GFP mask used in the kmalloc() call when allocating memory
+ */
+char *kstrdup(const char *s, gfp_t gfp)
+{
+ size_t len;
+ char *buf;
+
+ if (!s)
+ return NULL;
+
+ len = strlen(s) + 1;
+ buf = kmalloc(len, gfp);
+ if (buf)
+ memcpy(buf, s, len);
+ return buf;
+}
+EXPORT_SYMBOL(kstrdup);