Eina unicode: Added eina_unicode_strndup.
authortasn <tasn>
Tue, 8 Feb 2011 13:43:03 +0000 (13:43 +0000)
committertasn <tasn@7cbeb6ba-43b4-40fd-8cce-4c39aea84d33>
Tue, 8 Feb 2011 13:43:03 +0000 (13:43 +0000)
git-svn-id: http://svn.enlightenment.org/svn/e/trunk/eina@56807 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33

src/include/eina_unicode.h
src/lib/eina_unicode.c

index 8a20d26..152177b 100644 (file)
@@ -46,6 +46,8 @@ EAPI size_t        eina_unicode_strnlen(const Eina_Unicode *ustr, int n) EINA_AR
 
 EAPI Eina_Unicode *eina_unicode_strdup(const Eina_Unicode *text) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
 
+EAPI Eina_Unicode *eina_unicode_strndup(const Eina_Unicode *text, size_t n) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_MALLOC;
+
 EAPI int           eina_unicode_strcmp(const Eina_Unicode *a, const Eina_Unicode *b) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1, 2) EINA_PURE;
 
 EAPI Eina_Unicode *eina_unicode_strcpy(Eina_Unicode *dest, const Eina_Unicode *source) EINA_ARG_NONNULL(1, 2);
index c9e679c..6c8f7e9 100644 (file)
@@ -109,19 +109,30 @@ eina_unicode_strnlen(const Eina_Unicode *ustr, int n)
 
 
 /**
+ * @brief Same as strdup but cuts on n. Assumes n < len
+ * @since 1.1.0
+ */
+EAPI Eina_Unicode *
+eina_unicode_strndup(const Eina_Unicode *text, size_t n)
+{
+   Eina_Unicode *ustr;
+
+   ustr = (Eina_Unicode *) malloc((n + 1) * sizeof(Eina_Unicode));
+   memcpy(ustr, text, n * sizeof(Eina_Unicode));
+   ustr[n] = 0;
+   return ustr;
+}
+
+/**
  * @brief Same as the standard strdup just with Eina_Unicode instead of char.
  */
 EAPI Eina_Unicode *
 eina_unicode_strdup(const Eina_Unicode *text)
 {
-   Eina_Unicode *ustr;
    size_t len;
 
    len = eina_unicode_strlen(text);
-   ustr = (Eina_Unicode *)malloc((len + 1) * sizeof(Eina_Unicode));
-   memcpy(ustr, text, len * sizeof(Eina_Unicode));
-   ustr[len] = 0;
-   return ustr;
+   return eina_unicode_strndup(text, len);
 }
 
 /**