diff --git a/src/core/peg.c b/src/core/peg.c
index 4267b7b7..3c11b3e5 100644
--- a/src/core/peg.c
+++ b/src/core/peg.c
@@ -1400,7 +1400,7 @@ static Janet cfun_peg_replace_generic(int32_t argc, Janet *argv, int only_one) {
                 janet_buffer_push_bytes(ret, c.bytes.bytes + trail, (i - trail));
                 trail = i;
             }
-            int32_t nexti = result - c.bytes.bytes;
+            int32_t nexti = (int32_t)(result - c.bytes.bytes);
             janet_buffer_push_bytes(ret, c.repl.bytes, c.repl.len);
             trail = nexti;
             if (nexti == i) nexti++;
diff --git a/src/core/util.h b/src/core/util.h
index dd239a4b..e8eb9b81 100644
--- a/src/core/util.h
+++ b/src/core/util.h
@@ -100,6 +100,9 @@ void janet_core_cfuns(JanetTable *env, const char *regprefix, const JanetReg *cf
 /* Clock gettime */
 #if !defined(JANET_REDUCED_OS) || !defined(JANET_SINGLE_THREADED)
 #include <time.h>
+#ifndef JANET_WINDOWS
+#include <sys/time.h>
+#endif
 #define JANET_GETTIME
 int janet_gettime(struct timespec *spec);
 #endif