Fix Windows RTS
Fixup idris_writeStr (with name change)
Add the functionality to fpoll.
commit9fb967490c00a88eecb3aa1b711bbf1809e30d47
authorNiklas Larsson <niklas@mm.st>
dateSun 22 Feb 2015, 20:25 (12 years ago)
parentbbf672a
rts/Makefile+1−1
@@ -18,7 +18,7 @@ endif
1818endif
1919
2020ifeq ($(OS), windows)
21− OBJS += windows/idris_stdfgn.o windows/idris_net.o
21+ OBJS += windows/idris_stdfgn.o windows/idris_net.o windows/win_utils.o
2222else
2323 OBJS += idris_stdfgn.o idris_net.o
2424endif
rts/windows/idris_stdfgn.c+10−3
@@ -5,9 +5,12 @@
55#include <fcntl.h>
66#include <stdio.h>
77#include <time.h>
8+#include <io.h>
89
910extern char** environ;
1011
12+int win_fpoll(void* h);
13+
1114void putStr(char* str) {
1215 printf("%s", str);
1316}
@@ -32,14 +35,18 @@ int fileError(void* h) {
3235 return ferror(f);
3336}
3437
35−void fputStr(void* h, char* str) {
38+int idris_writeStr(void* h, char* str) {
3639 FILE* f = (FILE*)h;
37− fputs(str, f);
40+ if (fputs(str, f)) {
41+ return 0;
42+ } else {
43+ return -1;
44+ }
3845}
3946
4047int fpoll(void* h)
4148{
42− return 0;
49+ return win_fpoll(h);
4350}
4451
4552void* do_popen(const char* cmd, const char* mode) {
rts/windows/win_utils.cnew file+21
@@ -0,0 +1,21 @@
1+#include <windows.h>
2+#include <io.h>
3+#include <stdio.h>
4+
5+// THis file exists to avoid clashes between windows.h and idris_rts.h
6+//
7+
8+int win_fpoll(void* h)
9+{
10+ HANDLE wh =(HANDLE) _get_osfhandle(_fileno((FILE*)h));
11+ if (wh == INVALID_HANDLE_VALUE) {
12+ return -1;
13+ }
14+ DWORD ret = WaitForSingleObject(wh, 1000);
15+ // Imitate the return values of select()
16+ if (ret == WAIT_OBJECT_0)
17+ return 1;
18+ if (ret == WAIT_TIMEOUT)
19+ return 0;
20+ return -1;
21+}