on master help sign in
Merge pull request #1939 from melted/fix_rts
ebab239David Christiansen
rts/Makefile+1−1
@@ -18,7 +18,7 @@ endif
18endif
18endif
19
19
20ifeq ($(OS), windows)
20ifeq ($(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
22else
22else
23 OBJS += idris_stdfgn.o idris_net.o
23 OBJS += idris_stdfgn.o idris_net.o
24endif
24endif
rts/windows/idris_stdfgn.c+10−3
@@ -5,9 +5,12 @@
5#include <fcntl.h>
5#include <fcntl.h>
6#include <stdio.h>
6#include <stdio.h>
7#include <time.h>
7#include <time.h>
8+#include <io.h>
8
9
9extern char** environ;
10extern char** environ;
10
11
12+int win_fpoll(void* h);
13+
11void putStr(char* str) {
14void putStr(char* str) {
12 printf("%s", str);
15 printf("%s", str);
13}
16}
@@ -32,14 +35,18 @@ int fileError(void* h) {
32 return ferror(f);
35 return ferror(f);
33}
36}
34
37
35−void fputStr(void* h, char* str) {
38+int idris_writeStr(void* h, char* str) {
36 FILE* f = (FILE*)h;
39 FILE* f = (FILE*)h;
37− fputs(str, f);
40+ if (fputs(str, f)) {
41+ return 0;
42+ } else {
43+ return -1;
44+ }
38}
45}
39
46
40int fpoll(void* h)
47int fpoll(void* h)
41{
48{
42− return 0;
49+ return win_fpoll(h);
43}
50}
44
51
45void* do_popen(const char* cmd, const char* mode) {
52void* 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+}