Skip to content

Commit

Permalink
Change WIN32 to _WIN32 to check if running on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
mrexodia committed Nov 26, 2024
1 parent 5140e4f commit 2373fca
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions include/libimobiledevice-glue/socket.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ enum fd_mode {
};
typedef enum fd_mode fd_mode;

#ifdef WIN32
#ifdef _WIN32
#include <winsock2.h>
#define SHUT_RD SD_READ
#define SHUT_WR SD_WRITE
Expand All @@ -43,7 +43,7 @@ typedef enum fd_mode fd_mode;

#include <libimobiledevice-glue/glue.h>

#ifndef WIN32
#ifndef _WIN32
LIMD_GLUE_API int socket_create_unix(const char *filename);
LIMD_GLUE_API int socket_connect_unix(const char *filename);
#endif
Expand Down
4 changes: 2 additions & 2 deletions include/libimobiledevice-glue/thread.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#include <stddef.h>
#include <libimobiledevice-glue/glue.h>

#ifdef WIN32
#ifdef _WIN32
typedef void* HANDLE;
typedef HANDLE THREAD_T;
#pragma pack(push, 8)
Expand Down Expand Up @@ -76,7 +76,7 @@ LIMD_GLUE_API int thread_alive(THREAD_T thread);

LIMD_GLUE_API int thread_cancel(THREAD_T thread);

#ifdef WIN32
#ifdef _WIN32
#undef HAVE_THREAD_CLEANUP
#else
#ifdef HAVE_PTHREAD_CANCEL
Expand Down
2 changes: 1 addition & 1 deletion src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include <config.h>
#endif

#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#endif

Expand Down
42 changes: 21 additions & 21 deletions src/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
#include <errno.h>
#include <sys/time.h>
#include <sys/stat.h>
#ifdef WIN32
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <windows.h>
Expand Down Expand Up @@ -96,7 +96,7 @@ void socket_set_verbose(int level)

const char *socket_addr_to_string(struct sockaddr *addr, char *addr_out, size_t addr_out_size)
{
#ifdef WIN32
#ifdef _WIN32
WSADATA wsa_data;
if (!wsa_init) {
if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
Expand Down Expand Up @@ -154,7 +154,7 @@ enum poll_status
poll_status_error
};

#ifdef WIN32
#ifdef _WIN32
static inline __attribute__((always_inline)) int WSAError_to_errno(int wsaerr)
{
switch (wsaerr) {
Expand Down Expand Up @@ -325,7 +325,7 @@ static inline __attribute__((always_inline)) enum poll_status poll_wrapper(int f
#endif
}

#ifndef WIN32
#ifndef _WIN32
int socket_create_unix(const char *filename)
{
struct sockaddr_un name;
Expand Down Expand Up @@ -472,7 +472,7 @@ int socket_create(const char* addr, uint16_t port)
struct addrinfo *result, *rp;
char portstr[8];
int res;
#ifdef WIN32
#ifdef _WIN32
WSADATA wsa_data;
if (!wsa_init) {
if (WSAStartup(MAKEWORD(2,2), &wsa_data) != ERROR_SUCCESS) {
Expand Down Expand Up @@ -579,7 +579,7 @@ static uint32_t _in6_addr_scope(struct in6_addr* addr)
}

#ifndef HAVE_GETIFADDRS
#ifdef WIN32
#ifdef _WIN32

struct ifaddrs {
struct ifaddrs *ifa_next; /* Next item in list */
Expand Down Expand Up @@ -1028,7 +1028,7 @@ int socket_connect_addr(struct sockaddr* addr, uint16_t port)
int yes = 1;
int bufsize = 0x20000;
int addrlen = 0;
#ifdef WIN32
#ifdef _WIN32
u_long l_yes = 1;
WSADATA wsa_data;
if (!wsa_init) {
Expand Down Expand Up @@ -1089,7 +1089,7 @@ int socket_connect_addr(struct sockaddr* addr, uint16_t port)
return -1;
}

#ifdef WIN32
#ifdef _WIN32
ioctlsocket(sfd, FIONBIO, &l_yes);
#else
int flags = fcntl(sfd, F_GETFL, 0);
Expand All @@ -1100,7 +1100,7 @@ int socket_connect_addr(struct sockaddr* addr, uint16_t port)
if (connect(sfd, addr, addrlen) != -1) {
break;
}
#ifdef WIN32
#ifdef _WIN32
if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
if (errno == EINPROGRESS)
Expand All @@ -1114,7 +1114,7 @@ int socket_connect_addr(struct sockaddr* addr, uint16_t port)
errno = 0;
break;
}
#ifdef WIN32
#ifdef _WIN32
so_error = WSAError_to_errno(so_error);
#endif
errno = so_error;
Expand All @@ -1123,7 +1123,7 @@ int socket_connect_addr(struct sockaddr* addr, uint16_t port)
socklen_t len = sizeof(so_error);
getsockopt(sfd, SOL_SOCKET, SO_ERROR, (void*)&so_error, &len);
if (so_error != 0) {
#ifdef WIN32
#ifdef _WIN32
so_error = WSAError_to_errno(so_error);
#endif
errno = so_error;
Expand Down Expand Up @@ -1167,7 +1167,7 @@ int socket_connect(const char *addr, uint16_t port)
struct addrinfo *result, *rp;
char portstr[8];
int res;
#ifdef WIN32
#ifdef _WIN32
u_long l_yes = 1;
WSADATA wsa_data;
if (!wsa_init) {
Expand Down Expand Up @@ -1215,7 +1215,7 @@ int socket_connect(const char *addr, uint16_t port)
continue;
}

#ifdef WIN32
#ifdef _WIN32
ioctlsocket(sfd, FIONBIO, &l_yes);
#else
flags = fcntl(sfd, F_GETFL, 0);
Expand All @@ -1225,7 +1225,7 @@ int socket_connect(const char *addr, uint16_t port)
if (connect(sfd, rp->ai_addr, rp->ai_addrlen) != -1) {
break;
}
#ifdef WIN32
#ifdef _WIN32
if (WSAGetLastError() == WSAEWOULDBLOCK)
#else
if (errno == EINPROGRESS)
Expand All @@ -1239,7 +1239,7 @@ int socket_connect(const char *addr, uint16_t port)
errno = 0;
break;
}
#ifdef WIN32
#ifdef _WIN32
so_error = WSAError_to_errno(so_error);
#endif
errno = so_error;
Expand All @@ -1248,7 +1248,7 @@ int socket_connect(const char *addr, uint16_t port)
socklen_t len = sizeof(so_error);
getsockopt(sfd, SOL_SOCKET, SO_ERROR, (void*)&so_error, &len);
if (so_error != 0) {
#ifdef WIN32
#ifdef _WIN32
so_error = WSAError_to_errno(so_error);
#endif
errno = so_error;
Expand Down Expand Up @@ -1315,7 +1315,7 @@ int socket_check_fd(int fd, fd_mode fdm, unsigned int timeout)

int socket_accept(int fd, uint16_t port)
{
#ifdef WIN32
#ifdef _WIN32
int addr_len;
#else
socklen_t addr_len;
Expand All @@ -1335,7 +1335,7 @@ int socket_shutdown(int fd, int how)
}

int socket_close(int fd) {
#ifdef WIN32
#ifdef _WIN32
return closesocket(fd);
#else
return close(fd);
Expand Down Expand Up @@ -1371,7 +1371,7 @@ int socket_receive_timeout(int fd, void *data, size_t length, int flags, unsigne
return -ECONNRESET;
}
if (result < 0) {
#ifdef WIN32
#ifdef _WIN32
errno = WSAError_to_errno(WSAGetLastError());
#endif
return -errno;
Expand All @@ -1391,7 +1391,7 @@ int socket_send(int fd, void *data, size_t length)
#endif
int s = (int)send(fd, data, length, flags);
if (s < 0) {
#ifdef WIN32
#ifdef _WIN32
errno = WSAError_to_errno(WSAGetLastError());
#endif
return -errno;
Expand All @@ -1401,7 +1401,7 @@ int socket_send(int fd, void *data, size_t length)

int socket_get_socket_port(int fd, uint16_t *port)
{
#ifdef WIN32
#ifdef _WIN32
int addr_len;
#else
socklen_t addr_len;
Expand Down
22 changes: 11 additions & 11 deletions src/termcolors.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#include "config.h"
#endif

#ifdef WIN32
#ifdef _WIN32
#include <windows.h>
#endif

Expand All @@ -37,7 +37,7 @@

static int use_colors = 0;

#ifdef WIN32
#ifdef _WIN32
static int WIN32_LEGACY_MODE = 1;
static WORD COLOR_RESET_ATTR = 0;
static WORD DEFAULT_FG_ATTR = 0;
Expand Down Expand Up @@ -94,7 +94,7 @@ static int WIN32_LEGACY_MODE = 0;

void term_colors_init()
{
#ifdef WIN32
#ifdef _WIN32
DWORD conmode = 0;
h_stdout = GetStdHandle(STD_OUTPUT_HANDLE);
GetConsoleMode(h_stdout, &conmode);
Expand Down Expand Up @@ -135,7 +135,7 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
{
int res = 0;
int colorize = use_colors;
#ifdef WIN32
#ifdef _WIN32
struct esc_item {
int pos;
WORD attr;
Expand All @@ -162,7 +162,7 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
va_end(vargs_copy);

// then, we need to remove the escape sequences, if any
#ifdef WIN32
#ifdef _WIN32
// if colorize is on, we need to keep their positions for later
struct esc_item* esc_items = NULL;
int attr = 0;
Expand All @@ -183,7 +183,7 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
if (*p == '\e' && end-p > 2 && *(p+1) == '[') {
p+=2;
if (*p == 'm') {
#ifdef WIN32
#ifdef _WIN32
attr = COLOR_RESET_ATTR;
#endif
int move_by = (p+1)-cur;
Expand All @@ -197,13 +197,13 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
long lval = strtol(p, &endp, 10);
if (!endp || (*endp != ';' && *endp != 'm')) {
fprintf(stderr, "\n*** %s: Invalid escape sequence in format string, expected ';' or 'm' ***\n", __func__);
#ifdef WIN32
#ifdef _WIN32
free(esc_items);
#endif
free(newbuf);
return -1;
}
#ifdef WIN32
#ifdef _WIN32
if (colorize) {
if (lval >= 0 && lval <= 8) {
/* style attributes */
Expand Down Expand Up @@ -249,7 +249,7 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
end -= move_by;
p = cur;
}
#ifdef WIN32
#ifdef _WIN32
if (colorize) {
esc_items[num_esc].pos = p-start;
if (attr & STYLE_DIM) {
Expand All @@ -268,12 +268,12 @@ int cvfprintf(FILE* stream, const char* fmt, va_list vargs)
if (num_esc == 0) {
res = fputs(newbuf, stream);
free(newbuf);
#ifdef WIN32
#ifdef _WIN32
free(esc_items);
#endif
return res;
}
#ifdef WIN32
#ifdef _WIN32
else {
p = &newbuf[0];
char* lastp = &newbuf[0];
Expand Down
Loading

0 comments on commit 2373fca

Please sign in to comment.