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_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
|
else
|
||||||
AC_CHECK_LIB([ncursesw], [wget_wch],
|
AC_CHECK_LIB([ncursesw], [wget_wch],
|
||||||
[
|
[
|
||||||
|
@ -49,7 +49,10 @@
|
|||||||
char *get_user_config_dir(void)
|
char *get_user_config_dir(void)
|
||||||
{
|
{
|
||||||
char *user_config_dir;
|
char *user_config_dir;
|
||||||
#ifdef WIN32
|
#ifdef __WIN32__
|
||||||
|
#warning Please fix configdir for Win32
|
||||||
|
return NULL;
|
||||||
|
#if 0
|
||||||
char appdata[MAX_PATH];
|
char appdata[MAX_PATH];
|
||||||
BOOL ok;
|
BOOL ok;
|
||||||
|
|
||||||
@ -62,6 +65,7 @@ char *get_user_config_dir(void)
|
|||||||
user_config_dir = strdup(appdata);
|
user_config_dir = strdup(appdata);
|
||||||
|
|
||||||
return user_config_dir;
|
return user_config_dir;
|
||||||
|
#endif
|
||||||
|
|
||||||
#else /* WIN32 */
|
#else /* WIN32 */
|
||||||
|
|
||||||
@ -126,11 +130,10 @@ char *get_user_config_dir(void)
|
|||||||
*/
|
*/
|
||||||
int create_user_config_dir(char *path)
|
int create_user_config_dir(char *path)
|
||||||
{
|
{
|
||||||
|
#ifdef __WIN32__
|
||||||
int mkdir_err;
|
#warning Please fix configdir for Win32
|
||||||
|
return -1;
|
||||||
#ifdef WIN32
|
#if 0
|
||||||
|
|
||||||
char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1);
|
char *fullpath = malloc(strlen(path) + strlen(CONFIGDIR) + 1);
|
||||||
strcpy(fullpath, path);
|
strcpy(fullpath, path);
|
||||||
strcat(fullpath, CONFIGDIR);
|
strcat(fullpath, CONFIGDIR);
|
||||||
@ -143,7 +146,11 @@ int create_user_config_dir(char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
free(fullpath);
|
||||||
|
#endif
|
||||||
|
|
||||||
#else
|
#else
|
||||||
|
int mkdir_err;
|
||||||
|
|
||||||
mkdir_err = mkdir(path, 0700);
|
mkdir_err = mkdir(path, 0700);
|
||||||
struct stat buf;
|
struct stat buf;
|
||||||
@ -163,7 +170,7 @@ int create_user_config_dir(char *path)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
|
||||||
free(fullpath);
|
free(fullpath);
|
||||||
return 0;
|
return 0;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
31
src/main.c
31
src/main.c
@ -6,6 +6,10 @@
|
|||||||
#include "config.h"
|
#include "config.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef SIGWINCH
|
||||||
|
#define SIGWINCH 28
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@ -15,11 +19,13 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netdb.h>
|
|
||||||
|
|
||||||
#ifdef _win32
|
#ifdef WIN32
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
|
#include <winsock2.h>
|
||||||
|
#include <ws2tcpip.h>
|
||||||
#else
|
#else
|
||||||
|
#include <netdb.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.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_family = AF_INET; // IPv4 only right now.
|
||||||
hints.ai_socktype = SOCK_DGRAM; // type of socket Tox uses.
|
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);
|
rc = getaddrinfo(address, "echo", &hints, &server);
|
||||||
|
|
||||||
// Lookup failed.
|
// Lookup failed.
|
||||||
if (rc != 0) {
|
if (rc != 0) {
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// IPv4 records only..
|
// IPv4 records only..
|
||||||
if (server->ai_family != AF_INET) {
|
if (server->ai_family != AF_INET) {
|
||||||
freeaddrinfo(server);
|
freeaddrinfo(server);
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,6 +161,9 @@ uint32_t resolve_addr(const char *address)
|
|||||||
addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
|
addr = ((struct sockaddr_in *)server->ai_addr)->sin_addr.s_addr;
|
||||||
|
|
||||||
freeaddrinfo(server);
|
freeaddrinfo(server);
|
||||||
|
#ifdef __WIN32__
|
||||||
|
WSACleanup();
|
||||||
|
#endif
|
||||||
return addr;
|
return addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user