diff --git a/lib/Makefile.am b/lib/Makefile.am index 961a1436bf..2179521da7 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -4,12 +4,12 @@ include $(top_srcdir)/Makefile.incl #if HAVE_NSL -nslprogs=boinc_cmd +nslprogs=boinc_cmd$(EXEEXT) #endif -bin_PROGRAMS = crypt_prog $(nslprogs) +bin_PROGRAMS = crypt_prog$(EXEEXT) $(nslprogs) -EXTRA_PROGRAMS = md5_test shmem_test msg_test +EXTRA_PROGRAMS = md5_test$(EXEEXT) shmem_test$(EXEEXT) msg_test$(EXEEXT) all-local: client-bin @@ -22,7 +22,7 @@ boinc_cmd_SOURCES = \ boinc_cmd_LDADD = $(lib_LIBRARIES) $(PTHREAD_LIBS) # make a hard link to the client name. -@CLIENT_CMD_BIN_FILENAME@: boinc_cmd +@CLIENT_CMD_BIN_FILENAME@: boinc_cmd$(EXEEXT) rm -f $@ rm -f $@.unmodified cp $? $@.unmodified diff --git a/lib/boinc_cmd.C b/lib/boinc_cmd.C index 6e62f8cd4a..c358c9bfcc 100644 --- a/lib/boinc_cmd.C +++ b/lib/boinc_cmd.C @@ -147,7 +147,7 @@ int main(int argc, char** argv) { strcpy(passwd_buf, ""); read_password_from_file(passwd_buf); -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) WSADATA wsdata; retval = WSAStartup( MAKEWORD( 1, 1 ), &wsdata); if (retval) { @@ -429,7 +429,7 @@ int main(int argc, char** argv) { show_error(retval); } -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) WSACleanup(); #endif return 0; diff --git a/lib/boinc_win.h b/lib/boinc_win.h index 2e58b808cb..cd556b3127 100644 --- a/lib/boinc_win.h +++ b/lib/boinc_win.h @@ -24,6 +24,11 @@ #ifndef _BOINC_WIN_ #define _BOINC_WIN_ +// Under CYGWIN we need to include config.h first. +#ifdef __CYGWIN32__ +#include "config.h" +#endif + // Windows System Libraries // @@ -58,26 +63,52 @@ #define WIN32_EXTRA_LEAN // Trims even farther. #include + +#if !defined(__CYGWIN32__) || defined(USE_WINSOCK) +/* If we're not running under CYGWIN use windows networking */ +#undef USE_WINSOCK +#define USE_WINSOCK 1 #include #include + +#else +/* Under cygwin, curl was probably compiled to use */ +#include +#include +#include +#include +#include +#include +#include +#define _WINSOCK_H +#define _WINSOCKAPI_ +#define _WINSOCK2_H +#define _WININET_H +#define _WININETAPI_ +#endif + #include -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(__CYGWIN32__) #include #endif #include #include #include +#if !defined(__CYGWIN32__) #include +#endif #include -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(__CYGWIN32__) #include #endif +#if !defined(__CYGWIN32__) #include -#ifndef __MINGW32__ +#endif +#if !defined(__MINGW32__) && !defined(__CYGWIN32__) #include #endif -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(__CYGWIN32__) #include #endif // All projects should be using std::min and std::max instead of the Windows @@ -136,9 +167,11 @@ #include #endif - +#ifndef __CYGWIN32__ #define vsnprintf _vsnprintf #define snprintf _snprintf +#define stprintf _stprintf +#define stricmp _stricmp #define fdopen _fdopen #define dup _dup #define unlink _unlink @@ -147,7 +180,7 @@ #define stat _stat #define finite _finite #define chdir _chdir - +#endif // On the Win32 platform include file and line number information for each // memory allocation/deallocation diff --git a/lib/diagnostics.C b/lib/diagnostics.C index e313214fe4..2d440ebcc9 100644 --- a/lib/diagnostics.C +++ b/lib/diagnostics.C @@ -36,7 +36,7 @@ #include "config.h" #endif -#if defined(_WIN32) && !defined(__MINGW32__) +#if defined(_WIN32) && !defined(__MINGW32__) && !defined(__CYGWIN32__) #include "stackwalker_win.h" #endif @@ -392,7 +392,7 @@ LONG CALLBACK boinc_catch_signal(EXCEPTION_POINTERS *pExPtrs) { } fflush( stderr ); -#ifndef __MINGW32__ +#if !defined(__MINGW32__) && !defined(__CYGWIN32__) // Unwind the stack and spew it to stderr if (flags & BOINC_DIAG_DUMPCALLSTACKENABLED ) StackwalkFilter( pExPtrs, EXCEPTION_EXECUTE_HANDLER, NULL ); @@ -469,7 +469,7 @@ void boinc_trace(const char *pszFormat, ...) { va_list ptr; va_start(ptr, pszFormat); - _vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); + vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); va_end(ptr); @@ -489,7 +489,7 @@ void boinc_info_debug(const char *pszFormat, ...){ va_list ptr; va_start(ptr, pszFormat); - _vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); + vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); va_end(ptr); @@ -511,7 +511,7 @@ void boinc_info_release(const char *pszFormat, ...){ va_list ptr; va_start(ptr, pszFormat); - _vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); + vsnprintf(szBuffer, sizeof(szBuffer), pszFormat, ptr); va_end(ptr); diff --git a/lib/diagnostics.h b/lib/diagnostics.h index 1e3ff6fa90..9bfcfcaebb 100644 --- a/lib/diagnostics.h +++ b/lib/diagnostics.h @@ -129,7 +129,7 @@ extern void boinc_info_release(const char *pszFormat, ...); #else // _DEBUG -#ifdef __MINGW32__ +#if defined(__MINGW32__) || defined(__CYGWIN32__) #define BOINCASSERT(expr) #define BOINCTRACE(...) #define BOINCINFO boinc_info_release diff --git a/lib/filesys.C b/lib/filesys.C index 6b908443dd..44f4db0fa5 100755 --- a/lib/filesys.C +++ b/lib/filesys.C @@ -21,7 +21,7 @@ #include "boinc_win.h" #endif -#ifndef _WIN32 +#if !defined(_WIN32) || defined(__CYGWIN32__) #include "config.h" #include #include @@ -100,8 +100,7 @@ DIRREF dir_open(const char* p) { #ifdef HAVE_DIRENT_H dirp = opendir(p); if (!dirp) return NULL; -#endif -#ifdef _WIN32 +#elif defined(_WIN32) if (!is_dir(p)) return NULL; dirp = (DIR_DESC*) calloc(sizeof(DIR_DESC), 1); dirp->first = true; @@ -127,8 +126,7 @@ int dir_scan(char* p, DIRREF dirp, int p_len) { return ERR_READDIR; } } -#endif -#ifdef _WIN32 +#elif defined(_WIN32) WIN32_FIND_DATA data; while (1) { if (dirp->first) { @@ -167,8 +165,7 @@ void dir_close(DIRREF dirp) { if (dirp) { closedir(dirp); } -#endif -#ifdef _WIN32 +#elif defined(_WIN32) if (dirp->handle != INVALID_HANDLE_VALUE) { FindClose(dirp->handle); dirp->handle = INVALID_HANDLE_VALUE; @@ -180,9 +177,7 @@ void dir_close(DIRREF dirp) { DirScanner::DirScanner(string const& path) { #ifdef HAVE_DIRENT_H dirp = opendir(path.c_str()); -#endif - -#ifdef _WIN32 +#elif defined(_WIN32) first = true; handle = INVALID_HANDLE_VALUE; if (!is_dir((char*)path.c_str())) { @@ -208,8 +203,7 @@ bool DirScanner::scan(string& s) { return false; } } -#endif -#ifdef _WIN32 +#elif defined(_WIN32) WIN32_FIND_DATA data; while (1) { if (first) { @@ -243,8 +237,7 @@ DirScanner::~DirScanner() { if (dirp) { closedir(dirp); } -#endif -#ifdef _WIN32 +#elif defined(_WIN32) if (handle != INVALID_HANDLE_VALUE) { FindClose(handle); } @@ -488,7 +481,7 @@ int boinc_make_dirs(const char* dirpath, const char* filepath) { int FILE_LOCK::lock(const char* filename) { int retval=0; -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) handle = CreateFile( filename, GENERIC_WRITE, 0, 0, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, 0 @@ -513,7 +506,7 @@ int FILE_LOCK::lock(const char* filename) { } int FILE_LOCK::unlock(const char* filename) { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) if (!CloseHandle(handle)) { perror("FILE_LOCK::unlock(): close failed."); } @@ -529,7 +522,7 @@ int FILE_LOCK::unlock(const char* filename) { } void relative_to_absolute(const char* relname, char* path) { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) _getcwd(path, 256); #else getcwd(path, 256); diff --git a/lib/filesys.h b/lib/filesys.h index 48a89d5d38..93cc0a86b2 100755 --- a/lib/filesys.h +++ b/lib/filesys.h @@ -31,7 +31,7 @@ #endif /* defined(_MSC_VER) && (_MSC_VER > 1020) */ #endif /* (!defined __cplusplus) && (!defined bool) */ -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) typedef struct _DIR_DESC { char path[256]; @@ -97,7 +97,7 @@ extern void dir_close(DIRREF); class DirScanner { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) std::string dir; bool first; void* handle; @@ -111,7 +111,7 @@ public: }; struct FILE_LOCK { -#ifdef _WIN32 +#if defined(_WIN32) && !defined(__CYGWIN32__) HANDLE handle; #else int fd; diff --git a/lib/gui_rpc_client.C b/lib/gui_rpc_client.C index 4944e72126..fe1d179bfd 100644 --- a/lib/gui_rpc_client.C +++ b/lib/gui_rpc_client.C @@ -20,7 +20,7 @@ // This file is the underlying mechanism of GUI RPC client // (not the actual RPCs) -#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_) +#if defined(_WIN32) && !defined(__STDWX_H__) && !defined(_BOINC_WIN_) && !defined(_AFX_STDAFX_H_) #include "boinc_win.h" #endif @@ -79,7 +79,7 @@ void RPC_CLIENT::close() { int RPC_CLIENT::init(const char* host, int port) { double client_time = 0.0; int retval; - memset(&addr, 0, sizeof(addr)); + memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; if (port) { addr.sin_port = htons(port); diff --git a/lib/gui_rpc_client.h b/lib/gui_rpc_client.h index ee97317f5b..258e4b9dd9 100644 --- a/lib/gui_rpc_client.h +++ b/lib/gui_rpc_client.h @@ -19,7 +19,7 @@ // a C++ interface to BOINC GUI RPC -#ifndef _WIN32 +#if !defined(_WIN32) || defined (__CYGWIN__) #include #include #include diff --git a/lib/network.C b/lib/network.C index 53d8203c5c..a42a605057 100644 --- a/lib/network.C +++ b/lib/network.C @@ -31,6 +31,7 @@ #include #include #include +#include #endif #include "error_numbers.h" @@ -38,7 +39,7 @@ const char* socket_error_str() { static char buf[80]; -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) int e = WSAGetLastError(); switch (e) { case WSANOTINITIALISED: @@ -74,6 +75,11 @@ const char* socket_error_str() { return "a nonrecoverable error occurred"; case TRY_AGAIN: return "host not found or server failure"; +#ifdef NETDB_INTERNAL + case NETDB_INTERNAL: + sprintf(buf,"network internal error %d",errno); + return buf; +#endif } sprintf(buf, "error %d", h_errno); return buf; @@ -113,7 +119,7 @@ int boinc_socket(int& fd) { int boinc_socket_asynch(int fd, bool asynch) { if (asynch) { -#ifdef WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) unsigned long one = 1; ioctlsocket(fd, FIONBIO, &one); #else @@ -127,7 +133,7 @@ int boinc_socket_asynch(int fd, bool asynch) { } #endif } else { -#ifdef WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) unsigned long zero = 0; ioctlsocket(fd, FIONBIO, &zero); #else @@ -145,7 +151,7 @@ int boinc_socket_asynch(int fd, bool asynch) { } void boinc_close_socket(int sock) { -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) closesocket(sock); #else close(sock); @@ -155,7 +161,7 @@ void boinc_close_socket(int sock) { int get_socket_error(int fd) { boinc_socklen_t intsize = sizeof(int); int n; -#ifdef WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) getsockopt(fd, SOL_SOCKET, SO_ERROR, (char *)&n, &intsize); #elif defined(__APPLE__) getsockopt(fd, SOL_SOCKET, SO_ERROR, &n, (int *)&intsize); @@ -170,7 +176,7 @@ int get_socket_error(int fd) { return n; } -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) typedef BOOL (WINAPI *GetStateProc)( OUT LPDWORD lpdwFlags, IN DWORD dwReserved); diff --git a/lib/network.h b/lib/network.h index 3a82f97f79..6a66626bd1 100644 --- a/lib/network.h +++ b/lib/network.h @@ -24,6 +24,8 @@ #ifndef _WIN32 #include #include "config.h" +#else +#include "boinc_win.h" #endif struct FDSET_GROUP { @@ -47,7 +49,7 @@ extern void boinc_close_socket(int sock); extern int get_socket_error(int fd); extern const char* socket_error_str(); -#if defined(_WIN32) +#if defined(_WIN32) && defined(USE_WINSOCK) typedef int boinc_socklen_t; #define SHUT_WR SD_SEND #elif defined( __APPLE__) @@ -62,7 +64,7 @@ typedef BOINC_SOCKLEN_T boinc_socklen_t; extern int get_connected_state(); -#ifdef _WIN32 +#if defined(_WIN32) && defined(USE_WINSOCK) extern int WinsockInitialize(); extern int WinsockCleanup(); #endif diff --git a/lib/parse.h b/lib/parse.h index db431df7df..9acd88fe74 100644 --- a/lib/parse.h +++ b/lib/parse.h @@ -24,6 +24,8 @@ #include #include #include +#else +#include "boinc_win.h" #endif extern bool parse(char* , char* ); diff --git a/lib/util.C b/lib/util.C index a6a2d348af..bf7096100f 100755 --- a/lib/util.C +++ b/lib/util.C @@ -21,7 +21,7 @@ #include "boinc_win.h" #endif -#ifdef _WIN32 +#ifndef M_LN2 #define M_LN2 0.693147180559945309417 #endif