1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-06-23 06:25:25 +00:00

Leigh Smith's MINGW32 compatibility patch, with modifications for better

autoconf feng shui

svn path=/trunk/net/; revision=5490
This commit is contained in:
brendan 2003-10-20 03:08:46 +00:00
parent c6313c016c
commit 5a30452547
3 changed files with 33 additions and 9 deletions

View File

@ -50,13 +50,14 @@
#define EWOULDBLOCK WSAEWOULDBLOCK #define EWOULDBLOCK WSAEWOULDBLOCK
#define EALREADY WSAEALREADY #define EALREADY WSAEALREADY
#define socklen_t int #define socklen_t int
#ifndef __MINGW32__
#define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list)) #define va_copy(ap1, ap2) memcpy(&ap1, &ap2, sizeof(va_list))
#endif #endif
#endif
#include "sock.h" #include "sock.h"
#include "resolver.h" #include "resolver.h"
/* sock_initialize /* sock_initialize
** **
** initializes the socket library. you must call this ** initializes the socket library. you must call this
@ -160,7 +161,8 @@ int sock_valid_socket(sock_t sock)
socklen_t optlen; socklen_t optlen;
optlen = sizeof(int); optlen = sizeof(int);
ret = getsockopt(sock, SOL_SOCKET, SO_TYPE, &optval, &optlen); /* apparently on windows getsockopt.optval is a char * */
ret = getsockopt(sock, SOL_SOCKET, SO_TYPE, (void*) &optval, &optlen);
return (ret == 0); return (ret == 0);
} }
@ -193,7 +195,11 @@ int inet_aton(const char *s, struct in_addr *a)
int sock_set_blocking(sock_t sock, const int block) int sock_set_blocking(sock_t sock, const int block)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifdef __MINGW32__
u_long varblock = block;
#else
int varblock = block; int varblock = block;
#endif
#endif #endif
if ((!sock_valid_socket(sock)) || (block < 0) || (block > 1)) if ((!sock_valid_socket(sock)) || (block < 0) || (block > 1))
@ -433,10 +439,14 @@ int sock_connected (int sock, unsigned timeout)
switch (select(sock + 1, NULL, &wfds, NULL, &tv)) switch (select(sock + 1, NULL, &wfds, NULL, &tv))
{ {
case 0: return SOCK_TIMEOUT; case 0:
default: if (getsockopt(sock, SOL_SOCKET, SO_ERROR, &val, &size) < 0) return SOCK_TIMEOUT;
val = SOCK_ERROR; default:
case -1: return val; /* on windows getsockopt.val is defined as char* */
if (getsockopt(sock, SOL_SOCKET, SO_ERROR, (void*) &val, &size) < 0)
val = SOCK_ERROR;
case -1:
return val;
} }
} }

View File

@ -24,11 +24,14 @@
#include <stdarg.h> #include <stdarg.h>
#ifdef _WIN32 #ifdef HAVE_WINSOCK2_H
#include <winsock2.h> #include <winsock2.h>
#include <os.h> #endif
#else
#ifdef HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#elif _WIN32
#include <os.h>
#endif #endif
#ifdef HAVE_SYS_UIO_H #ifdef HAVE_SYS_UIO_H

View File

@ -24,6 +24,10 @@
#include <sys/select.h> #include <sys/select.h>
#endif #endif
#ifdef __MINGW32__
#include <sys/timeb.h>
#endif
#include "timing.h" #include "timing.h"
/* see timing.h for an explanation of _mangle() */ /* see timing.h for an explanation of _mangle() */
@ -34,7 +38,14 @@
uint64_t timing_get_time(void) uint64_t timing_get_time(void)
{ {
#ifdef _WIN32 #ifdef _WIN32
#ifdef __MINGW32__
struct timeb t;
ftime(&t);
return t.time * 1000 + t.millitm)
#else
return timeGetTime(); return timeGetTime();
#endif
#else #else
struct timeval mtv; struct timeval mtv;