Merge pull request #364 from Daniel-Abrecht/strndup

Fix mingw build: add strndup implementation to win32_compat.c
master
Ronnie Sahlberg 2021-10-04 16:43:21 +10:00 committed by GitHub
commit 4fa3b79569
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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