mirror of
https://github.com/idris-lang/Idris2.git
synced 2024-09-11 13:36:08 +03:00
Windows fixes
This commit is contained in:
parent
ede324dc6c
commit
1bebd7d070
@ -6,10 +6,14 @@ IDRIS_SRCS = Network/Socket.idr Network/Socket/Data.idr Network/Socket/Raw.idr
|
||||
|
||||
TARGET = idris_net
|
||||
|
||||
SRCS = $(wildcard *.c)
|
||||
SRCS = idris_net.c
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
||||
ifeq ($(OS), windows)
|
||||
LDFLAGS += -lws2_32
|
||||
endif
|
||||
|
||||
|
||||
all: $(TARGET)$(SHLIB_SUFFIX)
|
||||
${IDRIS2} --build network.ipkg
|
||||
@ -20,7 +24,7 @@ build: $(TARGET)$(SHLIB_SUFFIX) $(IDRIS_SRCS)
|
||||
${IDRIS2} --build network.ipkg
|
||||
|
||||
$(TARGET)$(SHLIB_SUFFIX): $(OBJS)
|
||||
$(CC) -shared $(LDFLAGS) -o $@ $^
|
||||
$(CC) -shared -o $@ $^ $(LDFLAGS)
|
||||
|
||||
|
||||
-include $(DEPS)
|
||||
|
@ -8,6 +8,9 @@ DYLIBTARGET = $(TARGET)$(SHLIB_SUFFIX)
|
||||
CFLAGS += -O2
|
||||
|
||||
SRCS = $(wildcard *.c)
|
||||
ifeq ($(OS), windows)
|
||||
SRCS += windows/win_utils.c
|
||||
endif
|
||||
OBJS = $(SRCS:.c=.o)
|
||||
DEPS = $(OBJS:.o=.d)
|
||||
|
||||
|
@ -6,7 +6,12 @@
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
|
||||
#ifdef _WIN32
|
||||
extern char **_environ;
|
||||
#define environ _environ
|
||||
#else
|
||||
extern char** environ;
|
||||
#endif
|
||||
|
||||
int idris2_isNull(void* ptr) {
|
||||
return (ptr == NULL);
|
||||
|
66
support/c/windows/win_utils.c
Normal file
66
support/c/windows/win_utils.c
Normal file
@ -0,0 +1,66 @@
|
||||
#include <io.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <windows.h>
|
||||
|
||||
// THis file exists to avoid clashes between windows.h and idris_rts.h
|
||||
//
|
||||
|
||||
int win_fpoll(FILE *f)
|
||||
{
|
||||
HANDLE wh =(HANDLE) _get_osfhandle(_fileno(f));
|
||||
if (wh == INVALID_HANDLE_VALUE) {
|
||||
return -1;
|
||||
}
|
||||
DWORD ret = WaitForSingleObject(wh, 1000);
|
||||
// Imitate the return values of select()
|
||||
if (ret == WAIT_OBJECT_0)
|
||||
return 1;
|
||||
if (ret == WAIT_TIMEOUT)
|
||||
return 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
int widen_utf8(const char *filename_utf8, LPWSTR *filename_w)
|
||||
{
|
||||
int num_chars = MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, 0, 0);
|
||||
int size = sizeof(WCHAR);
|
||||
*filename_w = (LPWSTR)malloc(size * num_chars);
|
||||
MultiByteToWideChar(CP_UTF8, 0, filename_utf8, -1, *filename_w, num_chars);
|
||||
return num_chars;
|
||||
}
|
||||
|
||||
FILE *win32_u8fopen(const char *path, const char *mode)
|
||||
{
|
||||
LPWSTR wpath, wmode;
|
||||
widen_utf8(path, &wpath);
|
||||
widen_utf8(mode, &wmode);
|
||||
FILE *f = _wfopen(wpath, wmode);
|
||||
free(wpath);
|
||||
free(wmode);
|
||||
return f;
|
||||
}
|
||||
|
||||
FILE *win32_u8popen(const char *path, const char *mode)
|
||||
{
|
||||
LPWSTR wpath, wmode;
|
||||
widen_utf8(path, &wpath);
|
||||
widen_utf8(mode, &wmode);
|
||||
FILE *f = _wpopen(wpath, wmode);
|
||||
free(wpath);
|
||||
free(wmode);
|
||||
return f;
|
||||
}
|
||||
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec)
|
||||
{
|
||||
FILETIME ft;
|
||||
GetSystemTimePreciseAsFileTime(&ft);
|
||||
ULARGE_INTEGER t;
|
||||
t.HighPart = ft.dwHighDateTime;
|
||||
t.LowPart = ft.dwLowDateTime;
|
||||
|
||||
*nsec = (t.QuadPart % 10000000)*100;
|
||||
*sec = t.QuadPart / 10000000;
|
||||
*sec -= 11644473600; // LDAP epoch to Unix epoch
|
||||
}
|
9
support/c/windows/win_utils.h
Normal file
9
support/c/windows/win_utils.h
Normal file
@ -0,0 +1,9 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#pragma once
|
||||
|
||||
int win_fpoll(FILE *h);
|
||||
FILE *win32_u8fopen(const char *path, const char *mode);
|
||||
FILE *win32_u8popen(const char *path, const char *mode);
|
||||
void win32_gettime(int64_t* sec, int64_t* nsec);
|
Loading…
Reference in New Issue
Block a user