move strndup to libi3
This commit is contained in:
24
src/util.c
24
src/util.c
@ -415,27 +415,3 @@ void *memmem(const void *l, size_t l_len, const void *s, size_t s_len) {
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__APPLE__)
|
||||
|
||||
/*
|
||||
* Taken from FreeBSD
|
||||
* Returns a pointer to a new string which is a duplicate of the
|
||||
* string, but only copies at most n characters.
|
||||
*
|
||||
*/
|
||||
char *strndup(const char *str, size_t n) {
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
for (len = 0; len < n && str[len]; len++)
|
||||
continue;
|
||||
|
||||
if ((copy = malloc(len + 1)) == NULL)
|
||||
return (NULL);
|
||||
memcpy(copy, str, len);
|
||||
copy[len] = '\0';
|
||||
return (copy);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
Reference in New Issue
Block a user