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:
Bart Van Assche
2021-05-23 12:20:07 -07:00
parent 2a5a0b3291
commit ca9c585ef6

View File

@@ -46,14 +46,14 @@ static int dummy ATTRIBUTE((unused));
/* Windows needs this header file for the implementation of inet_aton() */
#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;
int len = sizeof(SOCKADDR);
int ret = -1;
int strLen = strlen(src) + 1;
#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);
MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen);
#else
@@ -62,14 +62,11 @@ int win32_inet_pton(int af, const char * src, void * dst)
strncpy(srcNonConst, src, strLen);
#endif
if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)&sa,&len) == 0 )
{
if (WSAStringToAddress(srcNonConst, af, NULL, (LPSOCKADDR)&sa, &len) ==
0) {
ret = 1;
}
else
{
if( WSAGetLastError() == WSAEINVAL )
{
} else {
if (WSAGetLastError() == WSAEINVAL) {
ret = -1;
}
}
@@ -89,16 +86,13 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
FD_ZERO(&ifds);
FD_ZERO(&ofds);
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;
if(fds[i].events & (POLLIN|POLLPRI))
{
if (fds[i].events & (POLLIN | POLLPRI)) {
ip = &ifds;
FD_SET(fds[i].fd, ip);
}
if(fds[i].events & POLLOUT)
{
if (fds[i].events & POLLOUT) {
op = &ofds;
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
if(timo < 0)
{
if (timo < 0) {
toptr = 0;
}
else
{
} else {
toptr = &timeout;
timeout.tv_sec = timo / 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);
#endif
if(rc <= 0)
if (rc <= 0)
return rc;
if(rc > 0)
{
for (i = 0; i < nfds; ++i)
{
if (rc > 0) {
for (i = 0; i < nfds; ++i) {
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;
if(fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
if (fds[i].events & POLLOUT && FD_ISSET(fd, &ofds))
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;
#ifdef DEBUG_POLL
printf("%d %d %d revent = %x\n",
FD_ISSET(fd, &ifds), FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
fds[i].revents
);
printf("%d %d %d revent = %x\n", FD_ISSET(fd, &ifds),
FD_ISSET(fd, &ofds), FD_ISSET(fd, &efds),
fds[i].revents);
#endif
}
}
@@ -152,13 +142,12 @@ int win32_poll(struct pollfd *fds, unsigned int nfds, int timo)
}
#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS)
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64
#else
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
#endif
struct timezone
{
struct timezone {
int tz_minuteswest; /* minutes W of Greenwich */
int tz_dsttime; /* type of dst correction */
};
@@ -169,8 +158,7 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
unsigned __int64 tmpres = 0;
static int tzflag;
if (NULL != tv)
{
if (NULL != tv) {
GetSystemTimeAsFileTime(&ft);
tmpres |= ft.dwHighDateTime;
@@ -184,10 +172,8 @@ int win32_gettimeofday(struct timeval *tv, struct timezone *tz)
tv->tv_usec = (long)(tmpres % 1000000UL);
}
if (NULL != tz)
{
if (!tzflag)
{
if (NULL != tz) {
if (!tzflag) {
_tzset();
tzflag++;
}