Fixes for windows

This commit is contained in:
Andrew Pamment 2019-12-01 16:28:14 +10:00
parent 301c2e9700
commit 12f70e6ce9
4 changed files with 37 additions and 4 deletions

View File

@ -1,6 +1,10 @@
#include <errno.h> #include <errno.h>
#include <stdio.h> #include <stdio.h>
#if defined(_MSC_VER) || defined(WIN32)
#include <winsock2.h>
#else
#include <sys/socket.h> #include <sys/socket.h>
#endif
#include <unistd.h> #include <unistd.h>
#include "MagiDoor.h" #include "MagiDoor.h"
@ -16,7 +20,11 @@ char md_getc() {
if (ret == 0) { if (ret == 0) {
md_exit(0); md_exit(0);
} }
#if defined(_MSC_VER) || defined(WIN32)
if (ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) {
#else
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) { if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
#endif
usleep(1); usleep(1);
continue; continue;
} }

View File

@ -1,5 +1,9 @@
#include <stdio.h> #include <stdio.h>
#if defined(WIN32) || defined(_MSC_VER)
#include <winsock2.h>
#else
#include <termios.h> #include <termios.h>
#endif
#include <string.h> #include <string.h>
#include <stdlib.h> #include <stdlib.h>
#include <unistd.h> #include <unistd.h>
@ -15,7 +19,10 @@
MDDoorControl_t mdcontrol; MDDoorControl_t mdcontrol;
#if defined(WIN32) || defined(_MSC_VER)
#else
struct termios ttysave; struct termios ttysave;
#endif
static void md_cfg_read_line(char *buffer, int len, FILE *fptr) { static void md_cfg_read_line(char *buffer, int len, FILE *fptr) {
fgets(buffer, len, fptr); fgets(buffer, len, fptr);
@ -171,18 +178,20 @@ int read_doorsys(const char *dropfile) {
void md_exit(int exitcode) { void md_exit(int exitcode) {
if (mdcontrol.socket == -1) { if (mdcontrol.socket == -1) {
#if !defined(WIN32) && !defined(_MSC_VER)
tcsetattr(STDIN_FILENO, TCSANOW, &ttysave); tcsetattr(STDIN_FILENO, TCSANOW, &ttysave);
} else {
#if defined(WIN32) || defined (_MSC_VER)
WSACleanup();
#endif #endif
} else {
// nothing
} }
exit(exitcode); exit(exitcode);
} }
int md_init(const char *dropfile) { int md_init(const char *dropfile) {
char *filename = strrchr(dropfile, PATH_SEP); char *filename = strrchr(dropfile, PATH_SEP);
#if !defined(WIN32) && !defined(_MSC_VER)
struct termios ttystate; struct termios ttystate;
#endif
int ret; int ret;
if (filename == NULL) { if (filename == NULL) {
@ -198,6 +207,8 @@ int md_init(const char *dropfile) {
} }
if (mdcontrol.socket == -1) { if (mdcontrol.socket == -1) {
#if defined(WIN32) || defined(_MSC_VER)
#else
tcgetattr(STDIN_FILENO, &ttystate); tcgetattr(STDIN_FILENO, &ttystate);
ttysave = ttystate; ttysave = ttystate;
@ -207,7 +218,8 @@ int md_init(const char *dropfile) {
ttystate.c_cc[VMIN] = 1; ttystate.c_cc[VMIN] = 1;
ttystate.c_cc[VTIME] = 0; ttystate.c_cc[VTIME] = 0;
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate); tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
#endif
} }
return ret; return ret;

View File

@ -2,7 +2,11 @@
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#if defined(_MSC_VER) || defined(WIN32)
#include <winsock2.h>
#else
#include <sys/socket.h> #include <sys/socket.h>
#endif
#include "MagiDoor.h" #include "MagiDoor.h"
void md_putchar(char c) { void md_putchar(char c) {

9
buildwin.sh Executable file
View File

@ -0,0 +1,9 @@
#!/bin/bash
i686-w64-mingw32-gcc -c MD_Init.c
i686-w64-mingw32-gcc -c MD_Printf.c
i686-w64-mingw32-gcc -c MD_Getc.c
i686-w64-mingw32-gcc -c MD_Sendfile.c
i686-w64-mingw32-gcc -shared -o mdoor.dll *.o -lws2_32 -Wl,--out-implib,libmdoor.a
rm *.o