summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-01-15 18:41:29 +0100
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2020-01-15 19:06:07 +0100
commitffb608581652fa241b4482e36dbc2a26f8336789 (patch)
tree07d571953f52da513acce61b9e0806f3bca3ce45
parentd990ab7dba5a4710fa2189b664af0632b54243b1 (diff)
eina - eina_strndup - use universal impl because strndup is an issue
freebsd/clang report strndup is not defined and string.h doesnt seem to help if its included so move to the universal re-implementation that was there for win32 anyway
-rw-r--r--src/lib/eina/eina_inline_str.x10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/lib/eina/eina_inline_str.x b/src/lib/eina/eina_inline_str.x
index d61eda5d7a..1ca5093ba2 100644
--- a/src/lib/eina/eina_inline_str.x
+++ b/src/lib/eina/eina_inline_str.x
@@ -19,6 +19,8 @@
19#ifndef EINA_STR_INLINE_H_ 19#ifndef EINA_STR_INLINE_H_
20#define EINA_STR_INLINE_H_ 20#define EINA_STR_INLINE_H_
21 21
22#include <string.h>
23
22/** 24/**
23 * @addtogroup Eina_String_Group String 25 * @addtogroup Eina_String_Group String
24 * 26 *
@@ -92,14 +94,15 @@ eina_strdup(const char *str)
92static inline char * 94static inline char *
93eina_strndup(const char *str, size_t n) 95eina_strndup(const char *str, size_t n)
94{ 96{
95#ifdef _WIN32
96 char *ret; 97 char *ret;
98 const char *p;
97 size_t slen; 99 size_t slen;
98 100
99 if (!str) 101 if (!str)
100 return NULL; 102 return NULL;
101 103
102 slen = strnlen(str, n); 104 for (p = str; (*p) && ((size_t)(p - str) < n); p++)
105 slen = (size_t)(p - str);
103 ret = (char *)malloc(slen + 1); /* cast for C++ code */ 106 ret = (char *)malloc(slen + 1); /* cast for C++ code */
104 if (!ret) 107 if (!ret)
105 return NULL; 108 return NULL;
@@ -108,9 +111,6 @@ eina_strndup(const char *str, size_t n)
108 ret[slen] = '\0'; 111 ret[slen] = '\0';
109 112
110 return ret; 113 return ret;
111#else
112 return str ? strndup(str, n) : NULL;
113#endif
114} 114}
115 115
116/** 116/**