summaryrefslogtreecommitdiff
path: root/src/lib/eina
diff options
context:
space:
mode:
authorCedric BAIL <cedric.bail@free.fr>2019-05-29 13:49:26 -0400
committerMike Blumenkrantz <zmike@samsung.com>2019-05-29 13:49:26 -0400
commit2a3bf30abc084761e2c0212454ae623facaf1e24 (patch)
treee860aa093f20ad51f99e7cd80486199164d65dcb /src/lib/eina
parent202c945bd316c4336834b793d70cc4e2ae3c811a (diff)
eina: add eina_slstr_copy_new_length.
Reviewers: SanghyeonLee, bu5hm4n, zmike, segfaultxavi, lauromoura, felipealmeida, raster Reviewed By: bu5hm4n, zmike Subscribers: #reviewers, #committers Tags: #efl Maniphest Tasks: T7832 Differential Revision: https://phab.enlightenment.org/D8800
Diffstat (limited to 'src/lib/eina')
-rw-r--r--src/lib/eina/eina_slstr.c17
-rw-r--r--src/lib/eina/eina_slstr.h19
2 files changed, 36 insertions, 0 deletions
diff --git a/src/lib/eina/eina_slstr.c b/src/lib/eina/eina_slstr.c
index 143965a..017b692 100644
--- a/src/lib/eina/eina_slstr.c
+++ b/src/lib/eina/eina_slstr.c
@@ -109,6 +109,23 @@ eina_slstr_copy_new(const char *string)
109} 109}
110 110
111EAPI Eina_Slstr * 111EAPI Eina_Slstr *
112eina_slstr_copy_new_length(const char *string, size_t len)
113{
114 Eina_FreeQ *fq;
115 char *copy;
116
117 if (!string) return NULL;
118
119 fq = _slstr_freeq_get(EINA_FALSE);
120 EINA_SAFETY_ON_NULL_RETURN_VAL(fq, NULL);
121
122 copy = eina_strndup(string, len);
123 if (!copy) return NULL;
124 eina_freeq_ptr_add(fq, copy, free, len);
125 return copy;
126}
127
128EAPI Eina_Slstr *
112eina_slstr_steal_new(char *string) 129eina_slstr_steal_new(char *string)
113{ 130{
114 Eina_FreeQ *fq; 131 Eina_FreeQ *fq;
diff --git a/src/lib/eina/eina_slstr.h b/src/lib/eina/eina_slstr.h
index ce93e23..7f6144f 100644
--- a/src/lib/eina/eina_slstr.h
+++ b/src/lib/eina/eina_slstr.h
@@ -52,6 +52,25 @@ EAPI Eina_Slstr *
52eina_slstr_copy_new(const char *string); 52eina_slstr_copy_new(const char *string);
53 53
54/** 54/**
55 * @brief Create a new short lived string by duplicating another string.
56 *
57 * @param[in] string An existing string, it will be copied.
58 * @param[in] len How many charactere max to copy.
59 * @return A new Eina_Slstr or NULL if out of memory.
60 *
61 * Usage example:
62 * @code
63 * char local[200];
64 * sprintf(local, "Hello %d", value);
65 * return eina_slstr_copy_new_length(local, 5);
66 * @endcode
67 *
68 * @since 1.19
69 */
70EAPI Eina_Slstr *
71eina_slstr_copy_new_length(const char *string, size_t len);
72
73/**
55 * @brief Create a new short lived string by taking ownership of a string. 74 * @brief Create a new short lived string by taking ownership of a string.
56 * 75 *
57 * @param[in] string An existing string. It will not be duplicated. 76 * @param[in] string An existing string. It will not be duplicated.