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);
/**
+ * @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);
}
/**