summaryrefslogtreecommitdiff
path: root/src/lib/evil
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
parentb36e2fc701865db12c21fc94e92f52cc2471ab47 (diff)
evil: add strndup().
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
Diffstat (limited to 'src/lib/evil')
-rw-r--r--src/lib/evil/evil_string.c15
-rw-r--r--src/lib/evil/evil_string.h16
2 files changed, 31 insertions, 0 deletions
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
index 7d7d88c13a..151f8e5a01 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;
diff --git a/src/lib/evil/evil_string.h b/src/lib/evil/evil_string.h
index a51475db95..372a4e4253 100644
--- a/src/lib/evil/evil_string.h
+++ b/src/lib/evil/evil_string.h
@@ -18,6 +18,22 @@
18 * bit related functions 18 * bit related functions
19 * 19 *
20 */ 20 */
21/**
22 * @brief Duplicate a string
23 *
24 * @param str String to be duplicated
25 * @param n size of new duplicated string
26 * @return The strndup() function returns a pointer to the duplicated string, or NULL if insufficient memory was available.
27 *
28 * This function returns a pointer to a new string which is a duplicate of the string str,
29 * but only copies at most n bytes. If str is longer than n, only n bytes are copied,
30 * and a terminating null byte ('\0') is added.
31 *
32 * Conformity: BSD
33 *
34 * Supported OS: Windows XP.
35 */
36EAPI char *strndup(const char *str, size_t n);
21 37
22/** 38/**
23 * @brief Return the position of the first (least significant) bit set in a word 39 * @brief Return the position of the first (least significant) bit set in a word