mirror of
https://github.com/mdbtools/mdbtools.git
synced 2026-03-10 00:20:54 +08:00
Windows portability fixes
This commit is contained in:
@@ -5,6 +5,13 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
|
// for ntohl
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <winsock.h>
|
||||||
|
#else
|
||||||
|
#include <arpa/inet.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
typedef uint16_t guint16;
|
typedef uint16_t guint16;
|
||||||
typedef uint32_t guint32;
|
typedef uint32_t guint32;
|
||||||
typedef uint64_t guint64;
|
typedef uint64_t guint64;
|
||||||
|
|||||||
@@ -34,7 +34,13 @@ char **g_strsplit(const char *haystack, const char *needle, int something) {
|
|||||||
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while ((found = strstr(haystack, needle))) {
|
while ((found = strstr(haystack, needle))) {
|
||||||
ret[i++] = strndup(haystack, found - haystack);
|
// Windows lacks strndup
|
||||||
|
size_t chunk_len = found - haystack;
|
||||||
|
char *chunk = malloc(chunk_len + 1);
|
||||||
|
memcpy(chunk, haystack, chunk_len);
|
||||||
|
chunk[chunk_len] = 0;
|
||||||
|
|
||||||
|
ret[i++] = chunk;
|
||||||
haystack = found + strlen(needle);
|
haystack = found + strlen(needle);
|
||||||
}
|
}
|
||||||
ret[i] = strdup(haystack);
|
ret[i] = strdup(haystack);
|
||||||
@@ -65,11 +71,11 @@ char *g_strconcat(const char *first, ...) {
|
|||||||
|
|
||||||
ret = malloc(len+1);
|
ret = malloc(len+1);
|
||||||
|
|
||||||
char *pos = stpcpy(ret, first);
|
char *pos = strcpy(ret, first) + strlen(first);
|
||||||
|
|
||||||
va_start(argp, first);
|
va_start(argp, first);
|
||||||
while ((arg = va_arg(argp, char *))) {
|
while ((arg = va_arg(argp, char *))) {
|
||||||
pos = stpcpy(pos, arg);
|
pos = strcpy(pos, arg) + strlen(arg);
|
||||||
}
|
}
|
||||||
va_end(argp);
|
va_end(argp);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user