mirror of
https://github.com/Tha14/toxic.git
synced 2024-11-23 02:13:01 +01:00
Merge pull request #14 from jin-eld/win32
Make sure toxic compiles on MinGW/Win32 again
This commit is contained in:
commit
70936935c9
@ -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],
|
||||
[
|
||||
|
@ -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
|
||||
}
|
||||
|
29
src/main.c
29
src/main.c
@ -6,6 +6,10 @@
|
||||
#include "config.h"
|
||||
#endif
|
||||
|
||||
#ifndef SIGWINCH
|
||||
#define SIGWINCH 28
|
||||
#endif
|
||||
|
||||
#include <curses.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
@ -15,11 +19,13 @@
|
||||
#include <signal.h>
|
||||
#include <locale.h>
|
||||
#include <string.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#ifdef _win32
|
||||
#ifdef WIN32
|
||||
#include <direct.h>
|
||||
#include <winsock2.h>
|
||||
#include <ws2tcpip.h>
|
||||
#else
|
||||
#include <netdb.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h>
|
||||
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user