diff options
Diffstat (limited to '')
-rw-r--r-- | src/string_util.h | 46 |
1 files changed, 42 insertions, 4 deletions
diff --git a/src/string_util.h b/src/string_util.h index dc80a46ef..62de53873 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -20,18 +20,26 @@ #ifndef MPD_STRING_UTIL_H #define MPD_STRING_UTIL_H -#include <glib.h> +#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 * dirty hack, don't use it unless you know what you're doing! */ -G_GNUC_CONST +gcc_const static inline char * deconst_string(const char *p) { +#ifdef __cplusplus + return const_cast<char *>(p); +#else union { const char *in; char *out; @@ -40,6 +48,7 @@ deconst_string(const char *p) }; return u.out; +#endif } /** @@ -49,14 +58,14 @@ deconst_string(const char *p) * This is a faster version of g_strchug(), because it does not move * data. */ -G_GNUC_PURE +gcc_pure const char * strchug_fast_c(const char *p); /** * Same as strchug_fast_c(), but works with a writable pointer. */ -G_GNUC_PURE +gcc_pure static inline char * strchug_fast(char *p) { @@ -74,4 +83,33 @@ strchug_fast(char *p) bool string_array_contains(const char *const* haystack, const char *needle); +#ifndef HAVE_STRNLEN + +gcc_pure +size_t +strnlen(const char *s, size_t max); + +#endif + +#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 |