diff options
author | 2024-11-26 18:27:20 +0100 | |
---|---|---|
committer | 2024-11-26 18:27:20 +0100 | |
commit | 2373fca9f98a718f3fb9d3cc0c109c21acf8ecf2 (patch) | |
tree | 340c964047ca5b2502f3f65dd650516c4a257356 | |
parent | 5140e4f2b9f85292954ada4662ac351935a179a4 (diff) | |
download | libimobiledevice-glue-2373fca9f98a718f3fb9d3cc0c109c21acf8ecf2.tar.gz libimobiledevice-glue-2373fca9f98a718f3fb9d3cc0c109c21acf8ecf2.tar.bz2 |
Change WIN32 to _WIN32 to check if running on Windows
-rw-r--r-- | include/libimobiledevice-glue/socket.h | 4 | ||||
-rw-r--r-- | include/libimobiledevice-glue/thread.h | 4 | ||||
-rw-r--r-- | src/glue.c | 2 | ||||
-rw-r--r-- | src/socket.c | 42 | ||||
-rw-r--r-- | src/termcolors.c | 22 | ||||
-rw-r--r-- | src/thread.c | 34 |
6 files changed, 54 insertions, 54 deletions
diff --git a/include/libimobiledevice-glue/socket.h b/include/libimobiledevice-glue/socket.h index 39391c6..500d382 100644 --- a/include/libimobiledevice-glue/socket.h +++ b/include/libimobiledevice-glue/socket.h @@ -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 @@ -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 diff --git a/include/libimobiledevice-glue/thread.h b/include/libimobiledevice-glue/thread.h index 76646b8..a29573c 100644 --- a/include/libimobiledevice-glue/thread.h +++ b/include/libimobiledevice-glue/thread.h @@ -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) @@ -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 @@ -22,7 +22,7 @@ #include <config.h> #endif -#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #endif diff --git a/src/socket.c b/src/socket.c index 1518954..b42d366 100644 --- a/src/socket.c +++ b/src/socket.c @@ -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> @@ -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) { @@ -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) { @@ -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; @@ -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) { @@ -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 */ @@ -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) { @@ -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); @@ -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) @@ -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; @@ -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; @@ -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) { @@ -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); @@ -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) @@ -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; @@ -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; @@ -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; @@ -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); @@ -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; @@ -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; @@ -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; diff --git a/src/termcolors.c b/src/termcolors.c index 5c436f2..798e47a 100644 --- a/src/termcolors.c +++ b/src/termcolors.c @@ -22,7 +22,7 @@ #include "config.h" #endif -#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #endif @@ -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; @@ -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); @@ -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; @@ -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; @@ -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; @@ -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 */ @@ -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) { @@ -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]; diff --git a/src/thread.c b/src/thread.c index 50639dd..0dd58a9 100644 --- a/src/thread.c +++ b/src/thread.c @@ -22,7 +22,7 @@ #ifdef HAVE_CONFIG_H #include <config.h> #endif -#ifdef WIN32 +#ifdef _WIN32 #include <windows.h> #endif #include "common.h" @@ -30,7 +30,7 @@ int thread_new(THREAD_T *thread, thread_func_t thread_func, void* data) { -#ifdef WIN32 +#ifdef _WIN32 HANDLE th = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)(void*)thread_func, data, 0, NULL); if (th == NULL) { return -1; @@ -45,7 +45,7 @@ int thread_new(THREAD_T *thread, thread_func_t thread_func, void* data) void thread_detach(THREAD_T thread) { -#ifdef WIN32 +#ifdef _WIN32 CloseHandle(thread); #else pthread_detach(thread); @@ -54,7 +54,7 @@ void thread_detach(THREAD_T thread) void thread_free(THREAD_T thread) { -#ifdef WIN32 +#ifdef _WIN32 CloseHandle(thread); #endif } @@ -62,7 +62,7 @@ void thread_free(THREAD_T thread) int thread_join(THREAD_T thread) { /* wait for thread to complete */ -#ifdef WIN32 +#ifdef _WIN32 return (int)WaitForSingleObject(thread, INFINITE); #else return pthread_join(thread, NULL); @@ -73,7 +73,7 @@ int thread_alive(THREAD_T thread) { if (!thread) return 0; -#ifdef WIN32 +#ifdef _WIN32 return WaitForSingleObject(thread, 0) == WAIT_TIMEOUT; #else return pthread_kill(thread, 0) == 0; @@ -82,7 +82,7 @@ int thread_alive(THREAD_T thread) int thread_cancel(THREAD_T thread) { -#ifdef WIN32 +#ifdef _WIN32 return -1; #else #ifdef HAVE_PTHREAD_CANCEL @@ -95,7 +95,7 @@ int thread_cancel(THREAD_T thread) void mutex_init(mutex_t* mutex) { -#ifdef WIN32 +#ifdef _WIN32 InitializeCriticalSection((LPCRITICAL_SECTION)mutex); #else pthread_mutex_init(mutex, NULL); @@ -104,7 +104,7 @@ void mutex_init(mutex_t* mutex) void mutex_destroy(mutex_t* mutex) { -#ifdef WIN32 +#ifdef _WIN32 DeleteCriticalSection((LPCRITICAL_SECTION)mutex); #else pthread_mutex_destroy(mutex); @@ -113,7 +113,7 @@ void mutex_destroy(mutex_t* mutex) void mutex_lock(mutex_t* mutex) { -#ifdef WIN32 +#ifdef _WIN32 EnterCriticalSection((LPCRITICAL_SECTION)mutex); #else pthread_mutex_lock(mutex); @@ -122,7 +122,7 @@ void mutex_lock(mutex_t* mutex) void mutex_unlock(mutex_t* mutex) { -#ifdef WIN32 +#ifdef _WIN32 LeaveCriticalSection((LPCRITICAL_SECTION)mutex); #else pthread_mutex_unlock(mutex); @@ -131,7 +131,7 @@ void mutex_unlock(mutex_t* mutex) void thread_once(thread_once_t *once_control, void (*init_routine)(void)) { -#ifdef WIN32 +#ifdef _WIN32 while (InterlockedExchange(&(once_control->lock), 1) != 0) { Sleep(1); } @@ -147,7 +147,7 @@ void thread_once(thread_once_t *once_control, void (*init_routine)(void)) void cond_init(cond_t* cond) { -#ifdef WIN32 +#ifdef _WIN32 cond->sem = CreateSemaphore(NULL, 0, 32767, NULL); #else pthread_cond_init(cond, NULL); @@ -156,7 +156,7 @@ void cond_init(cond_t* cond) void cond_destroy(cond_t* cond) { -#ifdef WIN32 +#ifdef _WIN32 CloseHandle(cond->sem); #else pthread_cond_destroy(cond); @@ -165,7 +165,7 @@ void cond_destroy(cond_t* cond) int cond_signal(cond_t* cond) { -#ifdef WIN32 +#ifdef _WIN32 int result = 0; if (!ReleaseSemaphore(cond->sem, 1, NULL)) { result = -1; @@ -178,7 +178,7 @@ int cond_signal(cond_t* cond) int cond_wait(cond_t* cond, mutex_t* mutex) { -#ifdef WIN32 +#ifdef _WIN32 mutex_unlock(mutex); DWORD res = WaitForSingleObject(cond->sem, INFINITE); switch (res) { @@ -194,7 +194,7 @@ int cond_wait(cond_t* cond, mutex_t* mutex) int cond_wait_timeout(cond_t* cond, mutex_t* mutex, unsigned int timeout_ms) { -#ifdef WIN32 +#ifdef _WIN32 mutex_unlock(mutex); DWORD res = WaitForSingleObject(cond->sem, timeout_ms); switch (res) { |