mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-02-21 02:41:04 +00:00
o implement our own function for strndup if not compiled with
__USE_GNU. In other parts, we must use gsw_strndup instead of strndup. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@18209 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
44922ef123
commit
5ecdc9d9db
2 changed files with 28 additions and 0 deletions
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue