| Matt Mackall | 30992c9 | 2006-01-08 01:01:43 -0800 | [diff] [blame] | 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); |