Fix mingw build: add strndup implementation to win32_compat.c
parent
b1fbe322be
commit
939814826f
|
@ -33,6 +33,7 @@ THE SOFTWARE.
|
||||||
#include <io.h>
|
#include <io.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
|
#include <stddef.h> // For size_t type
|
||||||
|
|
||||||
typedef unsigned long fsblkcnt_t;
|
typedef unsigned long fsblkcnt_t;
|
||||||
typedef unsigned long fsfilcnt_t;
|
typedef unsigned long fsfilcnt_t;
|
||||||
|
@ -151,4 +152,8 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz);
|
||||||
|
|
||||||
#define DllExport
|
#define DllExport
|
||||||
|
|
||||||
|
#ifdef __MINGW32__
|
||||||
|
char* strndup(const char *s, size_t n);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif//win32_COMPAT_H_
|
#endif//win32_COMPAT_H_
|
||||||
|
|
|
@ -197,6 +197,23 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
|
||||||
|
|
||||||
return 0;
|
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
|
||||||
#endif
|
|
||||||
|
|
Loading…
Reference in New Issue