From: tasn Date: Tue, 8 Feb 2011 13:43:03 +0000 (+0000) Subject: Eina unicode: Added eina_unicode_strndup. X-Git-Tag: 2.0_alpha~70^2~202 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=29efafe98f9cf2a2b33465bab4494831d40c85f8;p=framework%2Fuifw%2Feina.git Eina unicode: Added eina_unicode_strndup. git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/eina@56807 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- diff --git a/src/include/eina_unicode.h b/src/include/eina_unicode.h index 8a20d26..152177b 100644 --- a/src/include/eina_unicode.h +++ b/src/include/eina_unicode.h @@ -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); diff --git a/src/lib/eina_unicode.c b/src/lib/eina_unicode.c index c9e679c..6c8f7e9 100644 --- a/src/lib/eina_unicode.c +++ b/src/lib/eina_unicode.c @@ -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); } /**