win32/win32_compat.c: Reformat this file
This file has been reformatted with clang-format --style=file and the Linux kernel .clang-format style file. Signed-off-by: Bart Van Assche <bvanassche@acm.org>
This commit is contained in:
@@ -46,14 +46,14 @@ static int dummy ATTRIBUTE((unused));
|
|||||||
/* Windows needs this header file for the implementation of inet_aton() */
|
/* Windows needs this header file for the implementation of inet_aton() */
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
int win32_inet_pton(int af, const char * src, void * dst)
|
int win32_inet_pton(int af, const char *src, void *dst)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sa;
|
struct sockaddr_in sa;
|
||||||
int len = sizeof(SOCKADDR);
|
int len = sizeof(SOCKADDR);
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
int strLen = strlen(src) + 1;
|
int strLen = strlen(src) + 1;
|
||||||
#ifdef UNICODE
|
#ifdef UNICODE
|
||||||
wchar_t *srcNonConst = (wchar_t *)malloc(strLen*sizeof(wchar_t));
|
wchar_t *srcNonConst = (wchar_t *)malloc(strLen * sizeof(wchar_t));
|
||||||
memset(srcNonConst, 0, strLen);
|
memset(srcNonConst, 0, strLen);
|
||||||
MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen);
|
MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen);
|
||||||
#else
|
#else
|
||||||
@@ -62,14 +62,11 @@ int win32_inet_pton(int af, const char * src, void * dst)
|
|||||||
strncpy(srcNonConst, src, strLen);
|
strncpy(srcNonConst, src, strLen);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)&sa,&len) == 0 )
|
if (WSAStringToAddress(srcNonConst, af, NULL, (LPSOCKADDR)&sa, &len) ==
|
||||||
{
|
0) {
|
||||||
ret = 1;
|
ret = 1;
|
||||||
}
|
} else {
|
||||||
else
|
if (WSAGetLastError() == WSAEINVAL) {
|
||||||
{
|
|
||||||
if( WSAGetLastError() == WSAEINVAL )
|
|
||||||
{
|
|
||||||
ret = -1;
|
ret = -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -89,16 +86,13 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
|
|||||||
FD_ZERO(&ifds);
|
FD_ZERO(&ifds);
|
||||||
FD_ZERO(&ofds);
|
FD_ZERO(&ofds);
|
||||||
FD_ZERO(&efds);
|
FD_ZERO(&efds);
|
||||||
for (i = 0, op = ip = 0; i < nfds; ++i)
|
for (i = 0, op = ip = 0; i < nfds; ++i) {
|
||||||
{
|
|
||||||
fds[i].revents = 0;
|
fds[i].revents = 0;
|
||||||
if(fds[i].events & (POLLIN|POLLPRI))
|
if (fds[i].events & (POLLIN | POLLPRI)) {
|
||||||
{
|
|
||||||
ip = &ifds;
|
ip = &ifds;
|
||||||
FD_SET(fds[i].fd, ip);
|
FD_SET(fds[i].fd, ip);
|
||||||
}
|
}
|
||||||
if(fds[i].events & POLLOUT)
|
if (fds[i].events & POLLOUT) {
|
||||||
{
|
|
||||||
op = &ofds;
|
op = &ofds;
|
||||||
FD_SET(fds[i].fd, op);
|
FD_SET(fds[i].fd, op);
|
||||||
}
|
}
|
||||||
@@ -106,12 +100,9 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set up the timeval structure for the timeout parameter
|
// Set up the timeval structure for the timeout parameter
|
||||||
if(timo < 0)
|
if (timo < 0) {
|
||||||
{
|
|
||||||
toptr = 0;
|
toptr = 0;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
toptr = &timeout;
|
toptr = &timeout;
|
||||||
timeout.tv_sec = timo / 1000;
|
timeout.tv_sec = timo / 1000;
|
||||||
timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
|
timeout.tv_usec = (timo - timeout.tv_sec * 1000) * 1000;
|
||||||
@@ -126,25 +117,24 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
|
|||||||
printf("Exiting select rc=%d\n", rc);
|
printf("Exiting select rc=%d\n", rc);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(rc <= 0)
|
if (rc <= 0)
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
if(rc > 0)
|
if (rc > 0) {
|
||||||
{
|
for (i = 0; i < nfds; ++i) {
|
||||||
for (i = 0; i < nfds; ++i)
|
|
||||||
{
|
|
||||||
int fd = fds[i].fd;
|
int fd = fds[i].fd;
|
||||||
if(fds[i].events & (POLLIN|POLLPRI) && FD_ISSET(fd, &ifds))
|
if (fds[i].events & (POLLIN | POLLPRI) &&
|
||||||
|
FD_ISSET(fd, &ifds))
|
||||||
fds[i].revents |= POLLIN;
|
fds[i].revents |= POLLIN;
|
||||||
if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
|
if (fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
|
||||||
fds[i].revents |= POLLOUT;
|
fds[i].revents |= POLLOUT;
|
||||||
if(FD_ISSET(fd, &efds)) // Some error was detected ... should be some way to know.
|
if (FD_ISSET(fd,
|
||||||
|
&efds)) // Some error was detected ... should be some way to know.
|
||||||
fds[i].revents |= POLLHUP;
|
fds[i].revents |= POLLHUP;
|
||||||
#ifdef DEBUG_POLL
|
#ifdef DEBUG_POLL
|
||||||
printf("%d %d %d revent = %x\n",
|
printf("%d %d %d revent = %x\n", FD_ISSET(fd, &ifds),
|
||||||
FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
|
FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
|
||||||
fds[i].revents
|
fds[i].revents);
|
||||||
);
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,13 +142,12 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
|
||||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
|
||||||
#else
|
#else
|
||||||
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
struct timezone
|
struct timezone {
|
||||||
{
|
|
||||||
int tz_minuteswest; /* minutes W of Greenwich */
|
int tz_minuteswest; /* minutes W of Greenwich */
|
||||||
int tz_dsttime; /* type of dst correction */
|
int tz_dsttime; /* type of dst correction */
|
||||||
};
|
};
|
||||||
@@ -169,8 +158,7 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
|
|||||||
unsigned __int64 tmpres = 0;
|
unsigned __int64 tmpres = 0;
|
||||||
static int tzflag;
|
static int tzflag;
|
||||||
|
|
||||||
if (NULL != tv)
|
if (NULL != tv) {
|
||||||
{
|
|
||||||
GetSystemTimeAsFileTime(&ft);
|
GetSystemTimeAsFileTime(&ft);
|
||||||
|
|
||||||
tmpres |= ft.dwHighDateTime;
|
tmpres |= ft.dwHighDateTime;
|
||||||
@@ -184,10 +172,8 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
|
|||||||
tv->tv_usec = (long)(tmpres % 1000000UL);
|
tv->tv_usec = (long)(tmpres % 1000000UL);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (NULL != tz)
|
if (NULL != tz) {
|
||||||
{
|
if (!tzflag) {
|
||||||
if (!tzflag)
|
|
||||||
{
|
|
||||||
_tzset();
|
_tzset();
|
||||||
tzflag++;
|
tzflag++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user