Fixes for windows
This commit is contained in:
parent
301c2e9700
commit
12f70e6ce9
@ -1,6 +1,10 @@
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include <unistd.h>
|
||||
#include "MagiDoor.h"
|
||||
|
||||
@ -16,7 +20,11 @@ char md_getc() {
|
||||
if (ret == 0) {
|
||||
md_exit(0);
|
||||
}
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
if (ret == SOCKET_ERROR && WSAGetLastError() == WSAEWOULDBLOCK) {
|
||||
#else
|
||||
if (ret == -1 && (errno == EAGAIN || errno == EWOULDBLOCK)) {
|
||||
#endif
|
||||
usleep(1);
|
||||
continue;
|
||||
}
|
||||
|
20
MD_Init.c
20
MD_Init.c
@ -1,5 +1,9 @@
|
||||
#include <stdio.h>
|
||||
#if defined(WIN32) || defined(_MSC_VER)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <termios.h>
|
||||
#endif
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
@ -15,7 +19,10 @@
|
||||
|
||||
MDDoorControl_t mdcontrol;
|
||||
|
||||
#if defined(WIN32) || defined(_MSC_VER)
|
||||
#else
|
||||
struct termios ttysave;
|
||||
#endif
|
||||
|
||||
static void md_cfg_read_line(char *buffer, int len, FILE *fptr) {
|
||||
fgets(buffer, len, fptr);
|
||||
@ -171,18 +178,20 @@ int read_doorsys(const char *dropfile) {
|
||||
|
||||
void md_exit(int exitcode) {
|
||||
if (mdcontrol.socket == -1) {
|
||||
#if !defined(WIN32) && !defined(_MSC_VER)
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttysave);
|
||||
} else {
|
||||
#if defined(WIN32) || defined (_MSC_VER)
|
||||
WSACleanup();
|
||||
#endif
|
||||
} else {
|
||||
// nothing
|
||||
}
|
||||
exit(exitcode);
|
||||
}
|
||||
|
||||
int md_init(const char *dropfile) {
|
||||
char *filename = strrchr(dropfile, PATH_SEP);
|
||||
#if !defined(WIN32) && !defined(_MSC_VER)
|
||||
struct termios ttystate;
|
||||
#endif
|
||||
int ret;
|
||||
|
||||
if (filename == NULL) {
|
||||
@ -198,6 +207,8 @@ int md_init(const char *dropfile) {
|
||||
}
|
||||
|
||||
if (mdcontrol.socket == -1) {
|
||||
#if defined(WIN32) || defined(_MSC_VER)
|
||||
#else
|
||||
tcgetattr(STDIN_FILENO, &ttystate);
|
||||
ttysave = ttystate;
|
||||
|
||||
@ -207,7 +218,8 @@ int md_init(const char *dropfile) {
|
||||
ttystate.c_cc[VMIN] = 1;
|
||||
ttystate.c_cc[VTIME] = 0;
|
||||
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
|
||||
tcsetattr(STDIN_FILENO, TCSANOW, &ttystate);
|
||||
#endif
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
@ -2,7 +2,11 @@
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#if defined(_MSC_VER) || defined(WIN32)
|
||||
#include <winsock2.h>
|
||||
#else
|
||||
#include <sys/socket.h>
|
||||
#endif
|
||||
#include "MagiDoor.h"
|
||||
|
||||
void md_putchar(char c) {
|
||||
|
9
buildwin.sh
Executable file
9
buildwin.sh
Executable 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
|
Loading…
x
Reference in New Issue
Block a user