diff options
author | Denis Krjuchkov <denis@crazydev.net> | 2013-01-11 13:51:39 +0600 |
---|---|---|
committer | Denis Krjuchkov <denis@crazydev.net> | 2013-01-11 13:51:39 +0600 |
commit | a98aa666203cad87913303d2f8b9ca07640518c3 (patch) | |
tree | 7fc9aa4231dbe86e227cd50d84f16d937898c28b /src/string_util.h | |
parent | 631a26899610e11a6c6456c2a5750dace68958f7 (diff) | |
download | mpd-a98aa666203cad87913303d2f8b9ca07640518c3.tar.gz mpd-a98aa666203cad87913303d2f8b9ca07640518c3.tar.xz mpd-a98aa666203cad87913303d2f8b9ca07640518c3.zip |
string_util.c: provide fallback strndup() implementation
This patch also adds extern "C" { } wrapper around string_util.h
to allow its usage in C++ code
Diffstat (limited to 'src/string_util.h')
-rw-r--r-- | src/string_util.h | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/string_util.h b/src/string_util.h index c1d316f0c..374fd0f91 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -23,6 +23,11 @@ #include "gcc.h" #include <stdbool.h> +#include <stdlib.h> /* for size_t */ + +#ifdef __cplusplus +extern "C" { +#endif /** * Remove the "const" attribute from a string pointer. This is a @@ -78,4 +83,25 @@ strchug_fast(char *p) bool string_array_contains(const char *const* haystack, const char *needle); +#if !defined(HAVE_STRNDUP) + +/** + * Duplicates the string to a newly allocated buffer + * copying at most n characters. + * + * @param str a string to duplicate + * @param n maximal number of characters to copy + * @return a pointer to the duplicated string, + * or NULL if memory allocation failed. + */ +gcc_malloc +char * +strndup(const char *str, size_t n); + +#endif + +#ifdef __cplusplus +} /* extern "C" */ +#endif + #endif |