mirror of
https://github.com/asterisk/asterisk.git
synced 2025-09-05 20:20:07 +00:00
first phase of proper fix for portable string function problems (bug #4669)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@6133 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
26
utils.c
26
utils.c
@@ -535,4 +535,28 @@ char *ast_strcasestr(const char *haystack, const char *needle)
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
#endif /* LINUX */
|
||||
|
||||
size_t ast_strnlen(const char *s, size_t n)
|
||||
{
|
||||
size_t len;
|
||||
|
||||
for (len=0; len < n; len++)
|
||||
if (s[len] == '\0')
|
||||
break;
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
char *ast_strndup(const char *s, size_t n)
|
||||
{
|
||||
size_t len = ast_strnlen(s, n);
|
||||
char *new = malloc(len + 1);
|
||||
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
new[len] = '\0';
|
||||
return memcpy(new, s, len);
|
||||
}
|
||||
|
||||
#endif /* !LINUX */
|
||||
|
Reference in New Issue
Block a user