diff --git a/mach/proto/mcg/main.c b/mach/proto/mcg/main.c index aa0fa4816..9f4982d66 100644 --- a/mach/proto/mcg/main.c +++ b/mach/proto/mcg/main.c @@ -15,7 +15,7 @@ bool tracing(char k) if (!tracechars) return false; - return index(tracechars, k); + return strchr(tracechars, k); } void tracef(char k, const char* fmt, ...) diff --git a/mach/proto/mcg/mcg.h b/mach/proto/mcg/mcg.h index 0bd9928df..9991d5001 100644 --- a/mach/proto/mcg/mcg.h +++ b/mach/proto/mcg/mcg.h @@ -9,6 +9,7 @@ #include #include #include +#include "system.h" #include "em_arith.h" #include "em_label.h" #include "em.h" diff --git a/modules/src/system/strndup.c b/modules/src/system/strndup.c new file mode 100644 index 000000000..798b9b71b --- /dev/null +++ b/modules/src/system/strndup.c @@ -0,0 +1,19 @@ +#include +#include +#include "system.h" + +#if defined WIN32 +/* Really? */ +char* strndup(const char* s, size_t n) +{ + size_t len = strnlen(s, n); + char* ns = malloc(len + 1); + if (!ns) + return NULL; + + ns[len] = '\0'; + memcpy(ns, s, len); + return ns; +} +#endif + diff --git a/modules/src/system/system.h b/modules/src/system/system.h index 12c27916b..2489c1f03 100644 --- a/modules/src/system/system.h +++ b/modules/src/system/system.h @@ -84,4 +84,9 @@ void sys_basename(const char *str, register char *dst); * the same semantics as ISO C90 tmpnam() */ char* sys_tmpnam(char *buffer); +#if defined WIN32 +/* Really? */ +extern char* strndup(const char* s, size_t n); +#endif + #endif /* __SYSTEM_INCLUDED__ */