cedric pushed a commit to branch master.

http://git.enlightenment.org/core/efl.git/commit/?id=a0b6f87c4416f50ba238c26e59d842ada37f833d

commit a0b6f87c4416f50ba238c26e59d842ada37f833d
Author: Michelle Legrand <[email protected]>
Date:   Thu Feb 12 14:45:07 2015 +0100

    evil: add strndup().
    
    Signed-off-by: Cedric BAIL <[email protected]>
---
 src/lib/evil/evil_string.c | 15 +++++++++++++++
 src/lib/evil/evil_string.h | 16 ++++++++++++++++
 2 files changed, 31 insertions(+)

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 @@
  *
  */
 
+char *
+strndup(const char *str, size_t n)
+{
+   size_t slen = strlen(str);
+   char *ret;
+
+   if (slen > n) slen = n;
+   ret = malloc (slen + 1);
+   if (!ret) return NULL;
+
+   if (slen > 0) memcpy(ret, str, slen);
+   ret[slen] = '\0';
+   return ret;
+}
+
 int ffs(int i)
 {
    int size;
diff --git a/src/lib/evil/evil_string.h b/src/lib/evil/evil_string.h
index a51475d..372a4e4 100644
--- a/src/lib/evil/evil_string.h
+++ b/src/lib/evil/evil_string.h
@@ -18,6 +18,22 @@
  * bit related functions
  *
  */
+/**
+ * @brief Duplicate a string
+ *
+ * @param str String to be duplicated
+ * @param n size of new duplicated string
+ * @return The strndup() function returns a pointer to the duplicated string, 
or NULL if insufficient memory was available.
+ *
+ * This function returns a pointer to a new string which is a duplicate of the 
string str, 
+ * but only copies at most n bytes. If str is longer than n, only n bytes are 
copied,
+ * and a terminating null byte ('\0') is added.
+ *
+ * Conformity: BSD
+ *
+ * Supported OS: Windows XP.
+ */
+EAPI char *strndup(const char *str, size_t n);
 
 /**
  * @brief Return the position of the first (least significant) bit set in a 
word

-- 


Reply via email to