summaryrefslogtreecommitdiff
path: root/src/lib/evil/evil_string.c
diff options
context:
space:
mode:
authorMichelle Legrand <legrand.michelle@outlook.com>2015-02-12 14:45:07 +0100
committerCedric BAIL <cedric@osg.samsung.com>2015-03-12 07:43:58 +0100
commita0b6f87c4416f50ba238c26e59d842ada37f833d (patch)
treeb663d86d327c9b0bb07a554488009bc1bfbc58de /src/lib/evil/evil_string.c
parentb36e2fc701865db12c21fc94e92f52cc2471ab47 (diff)
evil: add strndup().
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/evil/evil_string.c')
-rw-r--r--src/lib/evil/evil_string.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
index 7d7d88c..151f8e5 100644
--- a/src/lib/evil/evil_string.c
+++ b/src/lib/evil/evil_string.c
@@ -11,6 +11,21 @@
11 * 11 *
12 */ 12 */
13 13
14char *
15strndup(const char *str, size_t n)
16{
17 size_t slen = strlen(str);
18 char *ret;
19
20 if (slen > n) slen = n;
21 ret = malloc (slen + 1);
22 if (!ret) return NULL;
23
24 if (slen > 0) memcpy(ret, str, slen);
25 ret[slen] = '\0';
26 return ret;
27}
28
14int ffs(int i) 29int ffs(int i)
15{ 30{
16 int size; 31 int size;