diff options
author | Matt Mackall <mpm@selenic.com> | 2006-01-08 04:01:43 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@g5.osdl.org> | 2006-01-08 23:13:41 -0500 |
commit | 30992c97ae9d01b17374fbfab76a869fb4bba500 (patch) | |
tree | b1ea66bec56fabd80571696d0b081423dcab2340 /mm/util.c | |
parent | 50dd26ba0947aa653f0e42897aad7a4adce4e620 (diff) |
[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.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/mm/util.c b/mm/util.c new file mode 100644 index 000000000000..5f4bb59da63c --- /dev/null +++ b/mm/util.c | |||
@@ -0,0 +1,39 @@ | |||
1 | #include <linux/slab.h> | ||
2 | #include <linux/string.h> | ||
3 | #include <linux/module.h> | ||
4 | |||
5 | /** | ||
6 | * kzalloc - allocate memory. The memory is set to zero. | ||
7 | * @size: how many bytes of memory are required. | ||
8 | * @flags: the type of memory to allocate. | ||
9 | */ | ||
10 | void *kzalloc(size_t size, gfp_t flags) | ||
11 | { | ||
12 | void *ret = kmalloc(size, flags); | ||
13 | if (ret) | ||
14 | memset(ret, 0, size); | ||
15 | return ret; | ||
16 | } | ||
17 | EXPORT_SYMBOL(kzalloc); | ||
18 | |||
19 | /* | ||
20 | * kstrdup - allocate space for and copy an existing string | ||
21 | * | ||
22 | * @s: the string to duplicate | ||
23 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory | ||
24 | */ | ||
25 | char *kstrdup(const char *s, gfp_t gfp) | ||
26 | { | ||
27 | size_t len; | ||
28 | char *buf; | ||
29 | |||
30 | if (!s) | ||
31 | return NULL; | ||
32 | |||
33 | len = strlen(s) + 1; | ||
34 | buf = kmalloc(len, gfp); | ||
35 | if (buf) | ||
36 | memcpy(buf, s, len); | ||
37 | return buf; | ||
38 | } | ||
39 | EXPORT_SYMBOL(kstrdup); | ||