diff --git a/GSWAdaptors/common/GSWUtil.c b/GSWAdaptors/common/GSWUtil.c index 72c5dee..49e1638 100644 --- a/GSWAdaptors/common/GSWUtil.c +++ b/GSWAdaptors/common/GSWUtil.c @@ -606,3 +606,25 @@ void FormatAPRTime(char *date_str, apr_time_t t) } #endif + +#ifndef __USE_GNU +char* gsw_strndup(const char *s, size_t len) +{ + char *dups=NULL; + + // search end of string + const char *end = memchr(s, '\0', len); + + if (end) + len=end-s; + + dups = malloc(len+1); // +1 for \0 + + if (len>0) + memcpy(dups,s,len); + + dups[len]='\0'; + return dups; +} +#endif + diff --git a/GSWAdaptors/common/GSWUtil.h b/GSWAdaptors/common/GSWUtil.h index bdda47f..8cdabc3 100644 --- a/GSWAdaptors/common/GSWUtil.h +++ b/GSWAdaptors/common/GSWUtil.h @@ -128,6 +128,12 @@ void GSWLog_Init(GSWDict *p_pDict, int p_iLevel); void FormatAPRTime(char *date_str, apr_time_t t); // 2003/04/05 10:12:25.123 #endif +#ifdef __USE_GNU +#define gsw_strndup(a,b) strndup((a),(b)) +#else + extern char* gsw_strndup(const char *s, size_t len); +#endif + #ifdef __cplusplus } #endif // __cplusplus