From bb8a2b770043838f666056ef867e69537a366a9f Mon Sep 17 00:00:00 2001 From: jin-eld Date: Tue, 27 Aug 2013 10:45:21 +0300 Subject: [PATCH] Make sure toxic compiles on MinGW/Win32 again The config dir stuff is simply broken and needs to be fixed. So for now disabled it, until someone has time to look into it. --- configure.ac | 2 ++ src/configdir.c | 21 ++++++++++++++------- src/main.c | 31 ++++++++++++++++++++++++++++--- 3 files changed, 44 insertions(+), 10 deletions(-) diff --git a/configure.ac b/configure.ac index 8de91a0..a764e18 100644 --- a/configure.ac +++ b/configure.ac @@ -238,6 +238,8 @@ if test "x$NCURSES_FOUND" = "xno"; then AC_MSG_ERROR([required library winsock2 was not found on the system, please check your MinGW installation]) ] ) + AC_DEFINE([_WIN32_WINNT], [0x501], + [enable getaddrinfo/freeaddrinfo on XP and higher]) else AC_CHECK_LIB([ncursesw], [wget_wch], [ diff --git a/src/configdir.c b/src/configdir.c index a032546..193b162 100644 --- a/src/configdir.c +++ b/src/configdir.c @@ -49,7 +49,10 @@ char *get_user_config_dir(void) { char *user_config_dir; -#ifdef WIN32 +#ifdef __WIN32__ +#warning Please fix configdir for Win32 + return NULL; +#if 0 char appdata[MAX_PATH]; BOOL ok; @@ -62,6 +65,7 @@ char *get_user_config_dir(void) user_config_dir = strdup(appdata); return user_config_dir; +#endif #else /* WIN32 */ @@ -126,11 +130,10 @@ char *get_user_config_dir(void) */ int create_user_config_dir(char *path) { - - int mkdir_err; - -#ifdef WIN32 - +#ifdef __WIN32__ +#warning Please fix configdir for Win32 + return -1; +#if 0 char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1); strcpy(fullpath, path); strcat(fullpath, CONFIGDIR); @@ -143,7 +146,11 @@ int create_user_config_dir(char *path) return -1; } + free(fullpath); +#endif + #else + int mkdir_err; mkdir_err = mkdir(path, 0700); struct stat buf; @@ -163,7 +170,7 @@ int create_user_config_dir(char *path) return -1; } -#endif free(fullpath); return 0; +#endif } diff --git a/src/main.c b/src/main.c index dc52753..3d70c7a 100644 --- a/src/main.c +++ b/src/main.c @@ -6,6 +6,10 @@ #include "config.h" #endif +#ifndef SIGWINCH + #define SIGWINCH 28 +#endif + #include #include #include @@ -15,11 +19,13 @@ #include #include #include -#include -#ifdef _win32 -#include +#ifdef WIN32 + #include + #include + #include #else +#include #include #include #include @@ -122,16 +128,32 @@ uint32_t resolve_addr(const char *address) hints.ai_family = AF_INET; // IPv4 only right now. hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses. +#ifdef __WIN32__ + int res; + WSADATA wsa_data; + + res = WSAStartup(MAKEWORD(2, 2), &wsa_data); + if (res != 0) + { + return 0; + } +#endif rc = getaddrinfo(address, "echo", &hints, &server); // Lookup failed. if (rc != 0) { +#ifdef __WIN32__ + WSACleanup(); +#endif return 0; } // IPv4 records only.. if (server->ai_family != AF_INET) { freeaddrinfo(server); +#ifdef __WIN32__ + WSACleanup(); +#endif return 0; } @@ -139,6 +161,9 @@ uint32_t resolve_addr(const char *address) addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr; freeaddrinfo(server); +#ifdef __WIN32__ + WSACleanup(); +#endif return addr; }