From b6f7898659df07d408a6c5bde08835aebc22c021 Mon Sep 17 00:00:00 2001 From: manojampalam Date: Sun, 6 Mar 2016 14:14:29 -0800 Subject: [PATCH] 3-6 C6 --- contrib/win32/win32compat/inc/signal.h | 5 +-- contrib/win32/win32compat/inc/sys/select.h | 4 +-- contrib/win32/win32compat/inc/sys/socket.h | 27 +++++++------- contrib/win32/win32compat/inc/unistd.h | 41 ++++++++++++++++------ contrib/win32/win32compat/inc/w32posix.h | 24 +++++++------ 5 files changed, 64 insertions(+), 37 deletions(-) diff --git a/contrib/win32/win32compat/inc/signal.h b/contrib/win32/win32compat/inc/signal.h index 9496e8e..7b2f6e7 100644 --- a/contrib/win32/win32compat/inc/signal.h +++ b/contrib/win32/win32compat/inc/signal.h @@ -3,6 +3,8 @@ * * POSIX header and needed function definitions */ +#ifndef COMPAT_SIGNAL_H +#define COMPAT_SIGNAL_H 1 #include "w32posix.h" @@ -23,7 +25,6 @@ #define SIGPIPE 27 #define SIGQUIT 3 - // Signal action codes #define SIG_DFL (0) // default signal action #define SIG_IGN (1) // ignore signal @@ -31,4 +32,4 @@ #define SIG_SGE (3) // signal gets error #define SIG_ACK (4) // acknowledge -#define signal w32_signal \ No newline at end of file +#endif \ No newline at end of file diff --git a/contrib/win32/win32compat/inc/sys/select.h b/contrib/win32/win32compat/inc/sys/select.h index 123b169..3776600 100644 --- a/contrib/win32/win32compat/inc/sys/select.h +++ b/contrib/win32/win32compat/inc/sys/select.h @@ -3,8 +3,8 @@ * * POSIX header and needed function definitions */ +#pragma once + #include "..\w32posix.h" -#define fd_set w32_fd_set -#define select w32_select diff --git a/contrib/win32/win32compat/inc/sys/socket.h b/contrib/win32/win32compat/inc/sys/socket.h index d8f5072..073b11a 100644 --- a/contrib/win32/win32compat/inc/sys/socket.h +++ b/contrib/win32/win32compat/inc/sys/socket.h @@ -3,19 +3,20 @@ * * POSIX header and needed function definitions */ +#pragma once #include "..\w32posix.h" -#define socket w32_socket -#define accept w32_accept -#define setsockopt w32_setsockopt -#define getsockopt w32_getsockopt -#define getsockname w32_getsockname -#define getpeername w32_getpeername -#define listen w32_listen -#define bind w32_bind -#define connect w32_connect -#define recv w32_recv -#define send w32_send -#define shutdown w32_shutdown -#define socketpair w32_socketpair +#define socket(a,b,c) w32_socket((a), (b), (c)) +#define accept(a,b,c) w32_accept((a), (b), (c)) +#define setsockopt(a,b,c,d,e) w32_setsockopt((a), (b), (c), (d), (e)) +#define getsockopt(a,b,c,d,e) w32_getsockopt((a), (b), (c), (d), (e)) +#define getsockname(a,b,c) w32_getsockname((a), (b), (c)) +#define getpeername(a,b,c) w32_getpeername((a), (b), (c)) +#define listen(a,b) w32_listen((a), (b)) +#define bind(a,b,c) w32_bind((a), (b), (c)) +#define connect(a,b,c) w32_connect((a), (b), (c)) +#define recv(a,b,c,d) w32_recv((a), (b), (c), (d)) +#define send(a,b,c,d) w32_send(((a), (b), (c), (d)) +#define shutdown(a,b) w32_shutdown((a), (b)) +#define socketpair(a,b,c) w32_socketpair((a), (b), (c)) diff --git a/contrib/win32/win32compat/inc/unistd.h b/contrib/win32/win32compat/inc/unistd.h index e70e965..ac292f9 100644 --- a/contrib/win32/win32compat/inc/unistd.h +++ b/contrib/win32/win32compat/inc/unistd.h @@ -3,17 +3,38 @@ * * POSIX header and needed function definitions */ +#ifndef COMPAT_UNISTD_H +#define COMPAT_UNISTD_H 1 #include "w32posix.h" -#define pipe w32_pipe -#define open w32_open -#define read w32_read -#define write w32_write -#define isatty w32_isatty -#define close w32_close -#define dup w32_dup -#define dup2 w32_dup2 +#define pipe(a) w32_pipe((a)) +#define open(a,b,...) w32_open((a), (b), __VA_ARGS__) +#define read(a,b,c) w32_read((a), (b), (c)) +#define write(a,b,c) w32_write((a), (b), (c)) +#define isatty(a) w32_isatty((a)) +#define close(a) w32_close((a)) +#define dup(a) w32_dup((a)) +#define dup2(a,b) w32_dup2((a), (b)) -#define sleep(sec) Sleep(1000 * sec) -#define alarm w32_alarm \ No newline at end of file +#define sleep(sec) Sleep(1000 * sec) +#define alarm(a) w32_alarm((a)) + +/* Compatibility header to avoid lots of #ifdefs in includes.h on Win32 */ + +#include +#include + +/* We can't put these in string.h since we can't easily override that header, so here they are */ +#if !defined(HAVE_STRCASECMP) && !defined(__MINGW32__) +size_t strcasecmp(const char *left, const char *right); +#endif + +#if !defined(HAVE_STRNCASECMP) && !defined(__MINGW32__) +size_t strncasecmp(const char *left, const char *right, size_t n); +#endif + +int gettimeofday(struct timeval *tv, void *tz); +/* End of prototypes in the wrong file */ + +#endif diff --git a/contrib/win32/win32compat/inc/w32posix.h b/contrib/win32/win32compat/inc/w32posix.h index c027d9f..a294c0d 100644 --- a/contrib/win32/win32compat/inc/w32posix.h +++ b/contrib/win32/win32compat/inc/w32posix.h @@ -17,6 +17,8 @@ typedef struct w32_fd_set_ { unsigned char bitmap[MAX_FDS >> 3]; }w32_fd_set; +#define fd_set w32_fd_set + void w32posix_initialize(); void w32posix_done(); @@ -36,8 +38,8 @@ int w32_shutdown(int fd, int how); int w32_socketpair(int domain, int type, int sv[2]); /*non-network (file) i/o*/ -#define fdopen w32_fdopen -#define fstat w32_fstat +#define fdopen(a,b) w32_fdopen((a), (b)) +#define fstat(a,b) w32_fstat((a), (b)) int w32_pipe(int *pfds); int w32_open(const char *pathname, int flags, ...); @@ -48,7 +50,8 @@ int w32_isatty(int fd); FILE* w32_fdopen(int fd, const char *mode); /*common i/o*/ -#define fcntl w32_fcntl +#define fcntl(a,b,...) w32_fcntl((a), (b), __VA_ARGS__) +#define select(a,b,c,d,e) w32_select((a), (b), (c), (d), (e)) int w32_close(int fd); int w32_select(int fds, w32_fd_set* readfds, w32_fd_set* writefds, w32_fd_set* exceptfds, const struct timeval *timeout); @@ -56,11 +59,12 @@ int w32_fcntl(int fd, int cmd, ... /* arg */); int w32_dup(int oldfd); int w32_dup2(int oldfd, int newfd); + /* misc */ unsigned int w32_alarm(unsigned int seconds); typedef void(*sighandler_t)(int); -#define signal w32_signal -#define mysignal w32_signal +#define signal(a,b) w32_signal((a), (b)) +#define mysignal(a,b) w32_signal((a), (b)) /* Shutdown constants */ @@ -102,9 +106,9 @@ HANDLE w32_fd_to_handle(int fd); int w32_allocate_fd_for_handle(HANDLE h); /* temporary definitions to aid in transition */ -#define WSHELPDelChildToWatch w32_temp_DelChildToWatch -#define WSHELPAddChildToWatch w32_temp_AddChildToWatch -#define sfd_to_handle w32_fd_to_handle -#define allocate_sfd w32_allocate_fd_for_handle -#define WSHELPwopen w32_open +#define WSHELPDelChildToWatch(a) w32_temp_DelChildToWatch((a)) +#define WSHELPAddChildToWatch(a) w32_temp_AddChildToWatch((a)) +#define sfd_to_handle(a) w32_fd_to_handle((a)) +#define allocate_sfd(a) w32_allocate_fd_for_handle((a)) +#define WSHELPwopen(a) w32_open((a))