Fix mingw build: add strndup implementation to win32_compat.c

master
Daniel Abrecht 2021-10-03 12:51:42 +00:00
parent b1fbe322be
commit 939814826f
2 changed files with 23 additions and 1 deletions

View File

@ -33,6 +33,7 @@ THE SOFTWARE.
#include <io.h>
#include <sys/stat.h>
#include <time.h>
#include <stddef.h> // For size_t type
typedef unsigned long fsblkcnt_t;
typedef unsigned long fsfilcnt_t;
@ -151,4 +152,8 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz);
#define DllExport
#ifdef __MINGW32__
char* strndup(const char *s, size_t n);
#endif
#endif//win32_COMPAT_H_

View File

@ -197,6 +197,23 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
return 0;
}
#endif
#ifdef __MINGW32__
char* strndup(const char* s, size_t n)
{
size_t len;
for(len=0; len<n && s[len]; len++);
len += 1;
if(!len)
return 0;
char* copy = malloc(len);
if(!copy)
return 0;
memcpy(copy, s, len-1);
copy[len-1] = 0;
return copy;
}
#endif
#endif
#endif