fixed MSVC support

This commit is contained in:
2023-06-01 22:22:44 -05:00
parent 5169aca6d0
commit 8dfd7744c2
7 changed files with 732 additions and 12 deletions

59
src/_time.h Normal file
View File

@@ -0,0 +1,59 @@
#ifndef COSMO_TIME_H
#define COSMO_TIME_H
#ifdef _WIN32
#include <windows.h>
#include <time.h>
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 116444736000000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 116444736000000000ULL
#endif
struct timezone
{
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
int gettimeofday(struct timeval *tv, struct timezone *tz)
{
FILETIME ft;
unsigned __int64 tmpres = 0;
static int tzflag;
if (NULL != tv)
{
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
tmpres <<= 32;
tmpres |= ft.dwLowDateTime;
/*converting file time to unix epoch*/
tmpres /= 10; /*convert into microseconds*/
tmpres -= DELTA_EPOCH_IN_MICROSECS;
tv->tv_sec = (long)(tmpres / 1000000UL);
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
_tzset();
tzflag++;
}
tz->tz_minuteswest = _timezone / 60;
tz->tz_dsttime = _daylight;
}
return 0;
}
#else
#include <sys/time.h>
#endif
#endif

View File

@@ -6,7 +6,7 @@
#include "cvm.h"
#include <math.h>
#include <sys/time.h>
#include "_time.h"
// ================================================================ [BASELIB]
@@ -423,7 +423,7 @@ int cosmoB_sFind(CState *state, int nargs, CValue *args)
}
// success! push the index
cosmoV_pushNumber(state, indx - str->str);
cosmoV_pushNumber(state, (cosmo_Number)(indx - str->str));
} else if (nargs == 3) {
if (!IS_STRING(args[0]) || !IS_STRING(args[1]) || !IS_NUMBER(args[2])) {
cosmoV_typeError(state, "string.find()", "<string>, <string>, <number>", "%s, %s, %s",
@@ -445,7 +445,7 @@ int cosmoB_sFind(CState *state, int nargs, CValue *args)
}
// success! push the index
cosmoV_pushNumber(state, indx - str->str);
cosmoV_pushNumber(state, (cosmo_Number)(indx - str->str));
} else {
cosmoV_error(state, "string.find() expected 2 or 3 arguments, got %d!", nargs);
return 0;
@@ -557,7 +557,7 @@ int cosmoB_sLen(CState *state, int nargs, CValue *args)
return 0;
}
cosmoV_pushNumber(state, strlen(cosmoV_readCString(args[0])));
cosmoV_pushNumber(state, (cosmo_Number)strlen(cosmoV_readCString(args[0])));
return 1;
}

View File

@@ -8,7 +8,6 @@
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
// we don't actually hash the whole string :eyes:
uint32_t hashString(const char *str, size_t sz)