Add replacement for strndup(). MinGW doesn't have it. From Pete Batard again.

This commit is contained in:
rocky
2012-01-16 20:14:41 -05:00
parent 0faac0dabb
commit 8238905c98
2 changed files with 17 additions and 2 deletions

View File

@@ -59,6 +59,21 @@
# define CharNext(p) ((p) + 1)
#endif
#ifndef HAVE_STRNDUP
static inline char *strndup(const char *s, size_t n)
{
char *result;
size_t len = strlen (s);
if (n < len)
len = n;
result = (char *) malloc (len + 1);
if (!result)
return 0;
result[len] = '\0';
return (char *) strncpy (result, s, len);
}
#endif /*HAVE_STRNDUP*/
static char *
strrdirsep(const char *path)
{