summaryrefslogtreecommitdiffstats
path: root/src/util/strndup.h
diff options
context:
space:
mode:
authorEmil Velikov <[email protected]>2017-03-20 16:04:41 +0000
committerEmil Velikov <[email protected]>2017-03-22 16:55:23 +0000
commite325fc12dbdea2a0fdf10b279be39cf15cf2ca8b (patch)
tree0f8ebc4eae032de7bf05976f8e8e214b11df7916 /src/util/strndup.h
parentd542d2fc13fd67a444c202b706fa44a34cc53c90 (diff)
util: inline strndup implementation in the header
Signed-off-by: Emil Velikov <[email protected]> Acked-by: Vedran Miletić <[email protected]> Acked-by: Juha-Pekka Heikkila <[email protected]> Reviewed-by: Edward O'Callaghan <[email protected]>
Diffstat (limited to 'src/util/strndup.h')
-rw-r--r--src/util/strndup.h22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/util/strndup.h b/src/util/strndup.h
index a3d73984132..6d1868370fd 100644
--- a/src/util/strndup.h
+++ b/src/util/strndup.h
@@ -28,16 +28,34 @@
#if defined(_WIN32)
+#include <string.h>
+
#ifdef __cplusplus
extern "C" {
#endif
-char *strndup(const char *str, size_t max);
+static inline char *
+strndup(const char *str, size_t max)
+{
+ size_t n;
+ char *ptr;
+
+ if (!str)
+ return NULL;
+
+ n = strnlen(str, max);
+ ptr = (char *) calloc(n + 1, sizeof(char));
+ if (!ptr)
+ return NULL;
+
+ memcpy(ptr, str, n);
+ return ptr;
+}
#ifdef __cplusplus
}
#endif
-#endif
+#endif /* _WIN32 */
#endif /* STRNDUP_H */