aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVincent Torri <vincent.torri@gmail.com>2019-05-03 13:09:07 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-05-03 13:13:57 +0100
commit7db4714db6ed4e540e1048692f29f3ea1f2b88ed (patch)
tree1b5099c40d8afa89cf6586d200599883535180e6
parentcsharp: Some docs improvements. (diff)
downloadefl-7db4714db6ed4e540e1048692f29f3ea1f2b88ed.tar.gz
replace strndup with eina_strndup, remove strndup definition in evil and elm_test_dnd
Test Plan: compilation Reviewers: cedric, zmike, raster Subscribers: #reviewers, #committers Tags: #efl Differential Revision: https://phab.enlightenment.org/D8814
-rw-r--r--src/bin/eina/eina_btlog/eina_btlog.c6
-rw-r--r--src/bin/elementary/test_dnd.c29
-rw-r--r--src/bin/eolian/docs.c2
-rw-r--r--src/lib/ecore_cocoa/ecore_cocoa_cnp.m2
-rw-r--r--src/lib/eina/eina_inline_slice.x4
-rw-r--r--src/lib/eina/eina_slice.h2
-rw-r--r--src/lib/eina/eina_str.h1
-rw-r--r--src/lib/elementary/elm_code_indent.c2
-rw-r--r--src/lib/elementary/elm_code_line.c4
-rw-r--r--src/lib/elementary/elm_code_text.c2
-rw-r--r--src/lib/elementary/elm_code_widget.c4
-rw-r--r--src/lib/elementary/elm_code_widget_undo.c2
-rw-r--r--src/lib/evas/canvas/evas_textblock_hyphenation.x2
-rw-r--r--src/lib/evil/evil_string.c16
-rw-r--r--src/lib/evil/evil_string.h20
15 files changed, 25 insertions, 73 deletions
diff --git a/src/bin/eina/eina_btlog/eina_btlog.c b/src/bin/eina/eina_btlog/eina_btlog.c
index 41464611db..913470a1a8 100644
--- a/src/bin/eina/eina_btlog/eina_btlog.c
+++ b/src/bin/eina/eina_btlog/eina_btlog.c
@@ -194,7 +194,7 @@ _atos(const char *prog, const char *bin_dir, const char *bin_name, unsigned long
if ((spaces == func_space_count) && (func_done == EINA_FALSE))
{
*s = '\0';
- *func_name = strndup(buf, (int)(s - &(buf[0])));
+ *func_name = eina_strndup(buf, (int)(s - &(buf[0])));
func_done = EINA_TRUE;
}
else if (*s == '(')
@@ -208,7 +208,7 @@ _atos(const char *prog, const char *bin_dir, const char *bin_name, unsigned long
else if ((*s == ':') && (func_done == EINA_TRUE))
{
*s = '\0';
- *file_name = strndup(f1, (int)(s - f1));
+ *file_name = eina_strndup(f1, (int)(s - f1));
s++;
len = strlen(s);
s[len - 1] = '\0'; /* Remove the closing parenthesis */
@@ -266,7 +266,7 @@ bt_input_translate(const char *line, char **comment)
(int)(fileend - filestart), filestart,
(int)(addrend - addrstart), addrstart,
(int)(baseend - basestart), basestart);
- *comment = strndup(line, addrstart - line);
+ *comment = eina_strndup(line, addrstart - line);
return local;
}
diff --git a/src/bin/elementary/test_dnd.c b/src/bin/elementary/test_dnd.c
index 93bed2a397..be0738e122 100644
--- a/src/bin/elementary/test_dnd.c
+++ b/src/bin/elementary/test_dnd.c
@@ -201,25 +201,6 @@ _grid_item_getcb(Evas_Object *obj, Evas_Coord x, Evas_Coord y, int *xposret, int
return item;
}
-static inline char *
-_strndup(const char *str, size_t len)
-{
- const char *p;
- char *ret;
- size_t slen;
-
- for (slen = 0, p = str;
- (slen < len) && (*p);
- p++, slen++);
-
- ret = malloc(slen + 1);
- if (!ret) return NULL;
-
- if (slen > 0) memcpy(ret, str, slen);
- ret[slen] = '\0';
- return ret;
-}
-
static void
_gl_poscb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it, Evas_Coord x, Evas_Coord y, int xposret, int yposret, Elm_Xdnd_Action action EINA_UNUSED)
{
@@ -237,7 +218,7 @@ _gl_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it, Elm_Se
if (ev->len <= 0)
return EINA_FALSE;
- char *dd = _strndup(ev->data, ev->len);
+ char *dd = eina_strndup(ev->data, ev->len);
if (!dd) return EINA_FALSE;
char *p = dd;
@@ -292,7 +273,7 @@ _grid_dropcb(void *data EINA_UNUSED, Evas_Object *obj, Elm_Object_Item *it, Elm_
if (ev->len <= 0)
return EINA_FALSE;
- char *dd = _strndup(ev->data, ev->len);
+ char *dd = eina_strndup(ev->data, ev->len);
if (!dd) return EINA_FALSE;
char *p = dd;
char *s = _drag_data_extract(&p);
@@ -1000,7 +981,7 @@ static Eina_Bool _drop_box_button_new_cb(void *data, Evas_Object *obj, Elm_Selec
if (ev->len <= 0)
return EINA_FALSE;
- char *dd = _strndup(ev->data, ev->len);
+ char *dd = eina_strndup(ev->data, ev->len);
if (!dd) return EINA_FALSE;
char *p = dd;
char *s = _drag_data_extract(&p);
@@ -1034,7 +1015,7 @@ static Eina_Bool _drop_but_icon_change_cb(void *data, Evas_Object *obj, Elm_Sele
if (ev->len <= 0)
return EINA_FALSE;
- char *dd = _strndup(ev->data, ev->len);
+ char *dd = eina_strndup(ev->data, ev->len);
if (!dd) return EINA_FALSE;
char *p = dd;
char *s = _drag_data_extract(&p);
@@ -1062,7 +1043,7 @@ static Eina_Bool _drop_bg_change_cb(void *data EINA_UNUSED, Evas_Object *obj, El
if (ev->len <= 0)
return EINA_FALSE;
- char *dd = _strndup(ev->data, ev->len);
+ char *dd = eina_strndup(ev->data, ev->len);
if (!dd) return EINA_FALSE;
char *p = dd;
char *s = _drag_data_extract(&p);
diff --git a/src/bin/eolian/docs.c b/src/bin/eolian/docs.c
index 9893005b4d..7120612c9d 100644
--- a/src/bin/eolian/docs.c
+++ b/src/bin/eolian/docs.c
@@ -95,7 +95,7 @@ _generate_ref(const Eolian_State *state, const char *refn, Eina_Strbuf *wbuf)
}
if (cl)
{
- char *meth = strndup(mname + 1, sfx - mname - 1);
+ char *meth = eina_strndup(mname + 1, sfx - mname - 1);
fn = eolian_class_function_by_name_get(cl, meth, ftype);
if (ftype == EOLIAN_UNRESOLVED)
ftype = eolian_function_type_get(fn);
diff --git a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
index de9163fa28..c5fd22e99d 100644
--- a/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
+++ b/src/lib/ecore_cocoa/ecore_cocoa_cnp.m
@@ -112,7 +112,7 @@ ecore_cocoa_clipboard_get(int *size,
NSString *str = [items objectAtIndex: 0];
data = (void *)[str UTF8String];
len = [str lengthOfBytesUsingEncoding: NSUTF8StringEncoding];
- data = strndup((const char *)data, len);
+ data = eina_strndup((const char *)data, len);
if (EINA_UNLIKELY(!data))
{
diff --git a/src/lib/eina/eina_inline_slice.x b/src/lib/eina/eina_inline_slice.x
index f0188bdf69..e11a468cce 100644
--- a/src/lib/eina/eina_inline_slice.x
+++ b/src/lib/eina/eina_inline_slice.x
@@ -246,7 +246,7 @@ static inline char *
eina_slice_strdup(const Eina_Slice slice)
{
if (slice.len != 0)
- return strndup((const char *)slice.mem, slice.len);
+ return eina_strndup((const char *)slice.mem, slice.len);
return strdup("");
}
@@ -254,7 +254,7 @@ static inline char *
eina_rw_slice_strdup(const Eina_Rw_Slice rw_slice)
{
if (rw_slice.len != 0)
- return strndup((const char *)rw_slice.mem, rw_slice.len);
+ return eina_strndup((const char *)rw_slice.mem, rw_slice.len);
return strdup("");
}
diff --git a/src/lib/eina/eina_slice.h b/src/lib/eina/eina_slice.h
index fab84e9dc8..a354eaa566 100644
--- a/src/lib/eina/eina_slice.h
+++ b/src/lib/eina/eina_slice.h
@@ -28,6 +28,8 @@
#include <sys/types.h>
+#include "eina_str.h"
+
/**
* @addtogroup Eina_Slice_Group Memory Slices
*
diff --git a/src/lib/eina/eina_str.h b/src/lib/eina/eina_str.h
index c7d7e4ecca..961ac58980 100644
--- a/src/lib/eina/eina_str.h
+++ b/src/lib/eina/eina_str.h
@@ -3,6 +3,7 @@
#include <stddef.h>
#include <string.h>
+#include <time.h>
#include "eina_types.h"
diff --git a/src/lib/elementary/elm_code_indent.c b/src/lib/elementary/elm_code_indent.c
index 9ce4cb0962..e9f0bc9d05 100644
--- a/src/lib/elementary/elm_code_indent.c
+++ b/src/lib/elementary/elm_code_indent.c
@@ -16,7 +16,7 @@ elm_code_line_indent_startswith_keyword(Elm_Code_Line *line)
unsigned int textlen;
text = (char *)elm_code_line_text_get(line, &textlen);
- text = strndup(text, textlen);
+ text = eina_strndup(text, textlen);
ret = regcomp(&regex, "^\\s*("
"((if|else\\s*if|while|for|switch)\\s*\\(.*\\)\\s*\\{?)|"
diff --git a/src/lib/elementary/elm_code_line.c b/src/lib/elementary/elm_code_line.c
index 3c74a47cd0..2f9e8edd99 100644
--- a/src/lib/elementary/elm_code_line.c
+++ b/src/lib/elementary/elm_code_line.c
@@ -68,9 +68,9 @@ EAPI void elm_code_line_split_at(Elm_Code_Line *line, unsigned int position)
char *content;
unsigned int length;
- content = (char *) elm_code_line_text_get(line, &length);
+ content = (char *) elm_code_line_text_get(line, &length);
if (!content) return;
- content = strndup(content, length);
+ content = eina_strndup(content, length);
if (!content) return;
elm_code_file_line_insert(line->file, line->number + 1, "", 0, NULL);
newline = elm_code_file_line_get(line->file, line->number + 1);
diff --git a/src/lib/elementary/elm_code_text.c b/src/lib/elementary/elm_code_text.c
index 641dc41604..d27081a251 100644
--- a/src/lib/elementary/elm_code_text.c
+++ b/src/lib/elementary/elm_code_text.c
@@ -104,7 +104,7 @@ elm_code_line_text_substr(Elm_Code_Line *line, unsigned int position, int length
length = line->length - position;
content = elm_code_line_text_get(line, NULL);
- return strndup(content + position, length);
+ return eina_strndup(content + position, length);
}
static void
diff --git a/src/lib/elementary/elm_code_widget.c b/src/lib/elementary/elm_code_widget.c
index 0720a5253b..8d824e415f 100644
--- a/src/lib/elementary/elm_code_widget.c
+++ b/src/lib/elementary/elm_code_widget.c
@@ -1439,7 +1439,7 @@ _elm_code_widget_change_create(unsigned int start_col, unsigned int start_line,
info->end_col = end_col;
info->end_line = end_line;
- info->content = strndup(text, length);
+ info->content = eina_strndup(text, length);
info->length = length;
return info;
@@ -1523,7 +1523,7 @@ _elm_code_widget_newline(Elm_Code_Widget *widget)
line = elm_code_file_line_get(code->file, row);
}
oldtext = (char *) elm_code_line_text_get(line, &oldlen);
- oldtext = strndup(oldtext, oldlen);
+ oldtext = eina_strndup(oldtext, oldlen);
position = elm_code_widget_line_text_position_for_column_get(widget, line, col);
elm_code_line_split_at(line, position);
diff --git a/src/lib/elementary/elm_code_widget_undo.c b/src/lib/elementary/elm_code_widget_undo.c
index 2143e4c244..28cf85b8d8 100644
--- a/src/lib/elementary/elm_code_widget_undo.c
+++ b/src/lib/elementary/elm_code_widget_undo.c
@@ -33,7 +33,7 @@ _elm_code_widget_undo_info_copy(Elm_Code_Widget_Change_Info *info)
copy = calloc(1, sizeof(*info));
if (!copy) return NULL;
memcpy(copy, info, sizeof(*info));
- copy->content = strndup(info->content, info->length);
+ copy->content = eina_strndup(info->content, info->length);
return copy;
}
diff --git a/src/lib/evas/canvas/evas_textblock_hyphenation.x b/src/lib/evas/canvas/evas_textblock_hyphenation.x
index 22c4adf3a1..a12a9d6b51 100644
--- a/src/lib/evas/canvas/evas_textblock_hyphenation.x
+++ b/src/lib/evas/canvas/evas_textblock_hyphenation.x
@@ -72,7 +72,7 @@ _dict_hyphen_load(const char *lang)
ERR("Couldn't load hyphen dictionary: %s\n", dic_off - 5);
continue;
}
- _dicts_hyphen[_hyphens_num].lang = strndup(dic_off - 5, 5);
+ _dicts_hyphen[_hyphens_num].lang = eina_strndup(dic_off - 5, 5);
_dicts_hyphen[_hyphens_num++].dict = dict;
break;
}
diff --git a/src/lib/evil/evil_string.c b/src/lib/evil/evil_string.c
index 08ab2d7a02..3620ce5e89 100644
--- a/src/lib/evil/evil_string.c
+++ b/src/lib/evil/evil_string.c
@@ -11,24 +11,10 @@
/*
- * bit related functions
+ * string related functions
*
*/
-char *
-strndup(const char *str, size_t n)
-{
- size_t slen = strnlen(str, n);
- char *ret;
-
- ret = malloc (slen + 1);
- if (!ret) return NULL;
-
- if (slen > 0) memcpy(ret, str, slen);
- ret[slen] = '\0';
- return ret;
-}
-
char *strcasestr(const char *haystack, const char *needle)
{
size_t length_needle;
diff --git a/src/lib/evil/evil_string.h b/src/lib/evil/evil_string.h
index 6dbdb34d96..872834f238 100644
--- a/src/lib/evil/evil_string.h
+++ b/src/lib/evil/evil_string.h
@@ -15,27 +15,9 @@
/*
- * bit related functions
+ * string 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.
- *
- * @since 1.13
- */
-EAPI char *strndup(const char *str, size_t n);
/**
* @brief Locate a substring into a string, ignoring case.