Added #ifdefs and explicit inclusion of "boinc_win.h" to files to help those

trying to compile under windows with alternate compilers.

svn path=/trunk/boinc/; revision=9077
This commit is contained in:
Eric J. Korpela 2005-12-16 03:35:15 +00:00
parent bb5862d6fe
commit 6e30e66599
13 changed files with 86 additions and 50 deletions

View File

@ -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

View File

@ -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;

View File

@ -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 <windows.h>
#if !defined(__CYGWIN32__) || defined(USE_WINSOCK)
/* If we're not running under CYGWIN use windows networking */
#undef USE_WINSOCK
#define USE_WINSOCK 1
#include <winsock.h>
#include <wininet.h>
#else
/* Under cygwin, curl was probably compiled to use <sys/socket.h> */
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#define _WINSOCK_H
#define _WINSOCKAPI_
#define _WINSOCK2_H
#define _WININET_H
#define _WININETAPI_
#endif
#include <process.h>
#ifdef __MINGW32__
#if defined(__MINGW32__) || defined(__CYGWIN32__)
#include <pbt.h>
#endif
#include <commctrl.h>
#include <raserror.h>
#include <mmsystem.h>
#if !defined(__CYGWIN32__)
#include <direct.h>
#endif
#include <io.h>
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
#include <crtdbg.h>
#endif
#if !defined(__CYGWIN32__)
#include <tchar.h>
#ifndef __MINGW32__
#endif
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
#include <crtdbg.h>
#endif
#ifndef __MINGW32__
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
#include <delayimp.h>
#endif
// All projects should be using std::min and std::max instead of the Windows
@ -136,9 +167,11 @@
#include <set>
#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

View File

@ -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);

View File

@ -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

View File

@ -21,7 +21,7 @@
#include "boinc_win.h"
#endif
#ifndef _WIN32
#if !defined(_WIN32) || defined(__CYGWIN32__)
#include "config.h"
#include <cstdio>
#include <fcntl.h>
@ -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);

View File

@ -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;

View File

@ -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);

View File

@ -19,7 +19,7 @@
// a C++ interface to BOINC GUI RPC
#ifndef _WIN32
#if !defined(_WIN32) || defined (__CYGWIN__)
#include <stdio.h>
#include <string>
#include <vector>

View File

@ -31,6 +31,7 @@
#include <arpa/inet.h>
#include <netdb.h>
#include <fcntl.h>
#include <errno.h>
#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);

View File

@ -24,6 +24,8 @@
#ifndef _WIN32
#include <unistd.h>
#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

View File

@ -24,6 +24,8 @@
#include <cstdio>
#include <cstdlib>
#include <string>
#else
#include "boinc_win.h"
#endif
extern bool parse(char* , char* );

View File

@ -21,7 +21,7 @@
#include "boinc_win.h"
#endif
#ifdef _WIN32
#ifndef M_LN2
#define M_LN2 0.693147180559945309417
#endif