diff options
Diffstat (limited to 'mm/util.c')
-rw-r--r-- | mm/util.c | 26 |
1 files changed, 24 insertions, 2 deletions
@@ -6,7 +6,6 @@ | |||
6 | 6 | ||
7 | /** | 7 | /** |
8 | * kstrdup - allocate space for and copy an existing string | 8 | * kstrdup - allocate space for and copy an existing string |
9 | * | ||
10 | * @s: the string to duplicate | 9 | * @s: the string to duplicate |
11 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory | 10 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory |
12 | */ | 11 | */ |
@@ -27,6 +26,30 @@ char *kstrdup(const char *s, gfp_t gfp) | |||
27 | EXPORT_SYMBOL(kstrdup); | 26 | EXPORT_SYMBOL(kstrdup); |
28 | 27 | ||
29 | /** | 28 | /** |
29 | * kstrndup - allocate space for and copy an existing string | ||
30 | * @s: the string to duplicate | ||
31 | * @max: read at most @max chars from @s | ||
32 | * @gfp: the GFP mask used in the kmalloc() call when allocating memory | ||
33 | */ | ||
34 | char *kstrndup(const char *s, size_t max, gfp_t gfp) | ||
35 | { | ||
36 | size_t len; | ||
37 | char *buf; | ||
38 | |||
39 | if (!s) | ||
40 | return NULL; | ||
41 | |||
42 | len = strnlen(s, max); | ||
43 | buf = kmalloc_track_caller(len+1, gfp); | ||
44 | if (buf) { | ||
45 | memcpy(buf, s, len); | ||
46 | buf[len] = '\0'; | ||
47 | } | ||
48 | return buf; | ||
49 | } | ||
50 | EXPORT_SYMBOL(kstrndup); | ||
51 | |||
52 | /** | ||
30 | * kmemdup - duplicate region of memory | 53 | * kmemdup - duplicate region of memory |
31 | * | 54 | * |
32 | * @src: memory region to duplicate | 55 | * @src: memory region to duplicate |
@@ -80,7 +103,6 @@ EXPORT_SYMBOL(krealloc); | |||
80 | 103 | ||
81 | /* | 104 | /* |
82 | * strndup_user - duplicate an existing string from user space | 105 | * strndup_user - duplicate an existing string from user space |
83 | * | ||
84 | * @s: The string to duplicate | 106 | * @s: The string to duplicate |
85 | * @n: Maximum number of bytes to copy, including the trailing NUL. | 107 | * @n: Maximum number of bytes to copy, including the trailing NUL. |
86 | */ | 108 | */ |