From 5726af195680a95bbeb27acf8d6da963d35725c0 Mon Sep 17 00:00:00 2001 From: Eshan Kelkar Date: Tue, 4 Jul 2023 19:41:11 +0530 Subject: [PATCH] priv.h : Add compatibility code for Windows Compatibility code for mapping open, read, write, close and unlink to _open, _read, _write, _close and _unlink respectively on Windows was repeated in a lot of .c files. This commit adds that compatibility code to include/libssh/priv.h and removes it from the .c files (while ensuring that those .c files include priv.h) so that the compatibility code stays in one place, can be maintained easily and can be added easily to another source file by including priv.h in that file. Signed-off-by: Eshan Kelkar Reviewed-by: Andreas Schneider Reviewed-by: Jakub Jelen --- include/libssh/priv.h | 14 ++++++++++++++ src/connect.c | 5 ----- src/connector.c | 14 +------------- src/pki.c | 14 -------------- src/socket.c | 11 ----------- tests/torture.c | 5 ----- tests/torture_pki.c | 7 +------ 7 files changed, 16 insertions(+), 54 deletions(-) diff --git a/include/libssh/priv.h b/include/libssh/priv.h index 47af57f4..4ec3b2a7 100644 --- a/include/libssh/priv.h +++ b/include/libssh/priv.h @@ -162,6 +162,20 @@ int ssh_gettimeofday(struct timeval *__p, void *__t); #define _XCLOSESOCKET closesocket +# ifdef HAVE_IO_H +# include +# undef open +# define open _open +# undef close +# define close _close +# undef read +# define read _read +# undef write +# define write _write +# undef unlink +# define unlink _unlink +# endif /* HAVE_IO_H */ + #else /* _WIN32 */ #include diff --git a/src/connect.c b/src/connect.c index 2d69bd35..fd54c511 100644 --- a/src/connect.c +++ b/src/connect.c @@ -54,11 +54,6 @@ #define NTDDI_VERSION 0x05010000 /* NTDDI_WINXP */ #endif -#if _MSC_VER >= 1400 -#include -#undef close -#define close _close -#endif /* _MSC_VER */ #include #include diff --git a/src/connector.c b/src/connector.c index 56716749..21c4d79b 100644 --- a/src/connector.c +++ b/src/connector.c @@ -34,19 +34,7 @@ #define CHUNKSIZE 4096 #endif -#ifdef _WIN32 -# ifdef HAVE_IO_H -# include -# undef open -# define open _open -# undef close -# define close _close -# undef read -# define read _read -# undef unlink -# define unlink _unlink -# endif /* HAVE_IO_H */ -#else +#ifndef _WIN32 # include # include #endif diff --git a/src/pki.c b/src/pki.c index 3886514c..6863c90c 100644 --- a/src/pki.c +++ b/src/pki.c @@ -43,20 +43,6 @@ #include #include -#ifdef _WIN32 -# ifdef HAVE_IO_H -# include -# undef open -# define open _open -# undef close -# define close _close -# undef read -# define read _read -# undef unlink -# define unlink _unlink -# endif /* HAVE_IO_H */ -#endif /* _WIN32 */ - #include "libssh/libssh.h" #include "libssh/session.h" #include "libssh/priv.h" diff --git a/src/socket.c b/src/socket.c index 6682492c..9dc4cbdd 100644 --- a/src/socket.c +++ b/src/socket.c @@ -37,17 +37,6 @@ struct sockaddr_un { char sun_path[UNIX_PATH_MAX]; }; #endif -#if _MSC_VER >= 1400 -#include -#undef open -#define open _open -#undef close -#define close _close -#undef read -#define read _read -#undef write -#define write _write -#endif /* _MSC_VER */ #else /* _WIN32 */ #include #include diff --git a/tests/torture.c b/tests/torture.c index 695df25d..2641b2bf 100644 --- a/tests/torture.c +++ b/tests/torture.c @@ -40,11 +40,6 @@ #include #elif (defined _WIN32) || (defined _WIN64) #include -#include -#define read _read -#define open _open -#define write _write -#define close _close #define chdir _chdir #endif diff --git a/tests/torture_pki.c b/tests/torture_pki.c index cbf64951..f5420946 100644 --- a/tests/torture_pki.c +++ b/tests/torture_pki.c @@ -9,15 +9,10 @@ #ifdef HAVE_UNISTD_H #include -#elif (defined _WIN32) || (defined _WIN64) -#include -#define read _read -#define open _open -#define write _write -#define close _close #endif #include "torture_pki.h" +#include char *torture_pki_read_file(const char *filename) {