2008-08-06 18:36:30 +00:00
|
|
|
// This file is part of BOINC.
|
2005-01-20 23:22:22 +00:00
|
|
|
// http://boinc.berkeley.edu
|
2008-08-06 18:36:30 +00:00
|
|
|
// Copyright (C) 2008 University of California
|
2004-11-14 08:29:32 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is free software; you can redistribute it and/or modify it
|
|
|
|
// under the terms of the GNU Lesser General Public License
|
|
|
|
// as published by the Free Software Foundation,
|
|
|
|
// either version 3 of the License, or (at your option) any later version.
|
2004-07-13 13:54:09 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// BOINC is distributed in the hope that it will be useful,
|
2005-01-20 23:22:22 +00:00
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
// See the GNU Lesser General Public License for more details.
|
2004-06-10 07:49:50 +00:00
|
|
|
//
|
2008-08-06 18:36:30 +00:00
|
|
|
// You should have received a copy of the GNU Lesser General Public License
|
|
|
|
// along with BOINC. If not, see <http://www.gnu.org/licenses/>.
|
2004-06-10 07:49:50 +00:00
|
|
|
|
2004-06-17 00:05:18 +00:00
|
|
|
// boinc_win.h : include file for standard system include files,
|
2004-03-04 11:41:43 +00:00
|
|
|
// or project specific include files that are used frequently,
|
|
|
|
// but are changed infrequently
|
|
|
|
|
2004-06-17 00:05:18 +00:00
|
|
|
#ifndef _BOINC_WIN_
|
|
|
|
#define _BOINC_WIN_
|
2004-03-04 11:41:43 +00:00
|
|
|
|
2014-04-29 14:50:33 +00:00
|
|
|
#ifndef HAVE_CONFIG_H
|
2010-03-16 18:53:55 +00:00
|
|
|
|
|
|
|
// Windows C Runtime Library
|
|
|
|
|
|
|
|
#ifndef HAVE_STD_MAX
|
|
|
|
#define HAVE_STD_MAX 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STD_MIN
|
|
|
|
#define HAVE_STD_MIN 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_STD_TRANSFORM
|
|
|
|
#define HAVE_STD_TRANSFORM 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAVE_ALLOCA
|
|
|
|
#define HAVE_ALLOCA 1
|
|
|
|
#endif
|
|
|
|
|
2011-06-02 16:25:30 +00:00
|
|
|
#ifdef __MINGW32__
|
|
|
|
#define HAVE_STRCASECMP 1
|
|
|
|
#endif
|
|
|
|
|
2010-03-16 18:53:55 +00:00
|
|
|
#else
|
|
|
|
|
2014-04-29 14:50:33 +00:00
|
|
|
// Under any system that can run configure we need to include config.h first.
|
2005-12-16 03:35:15 +00:00
|
|
|
#include "config.h"
|
2010-03-16 18:53:55 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#endif
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
// Windows System Libraries
|
|
|
|
//
|
|
|
|
|
2005-07-06 09:14:43 +00:00
|
|
|
// Visual Studio 2005 has extended the C Run-Time Library by including "secure"
|
|
|
|
// runtime functions and deprecating the previous function prototypes. Since
|
|
|
|
// we need to use the previous prototypes to maintain compatibility with other
|
|
|
|
// platforms we are going to disable the deprecation warnings if we are compiling
|
|
|
|
// on Visual Studio 2005
|
|
|
|
#if _MSC_VER >= 1400
|
2010-03-16 18:53:55 +00:00
|
|
|
|
2006-04-18 04:26:56 +00:00
|
|
|
#ifndef _CRT_SECURE_NO_DEPRECATE
|
2006-04-13 03:53:16 +00:00
|
|
|
#define _CRT_SECURE_NO_DEPRECATE
|
2005-07-06 09:14:43 +00:00
|
|
|
#endif
|
2010-03-16 18:53:55 +00:00
|
|
|
|
|
|
|
#ifndef _CRT_SECURE_NO_WARNINGS
|
|
|
|
#define _CRT_SECURE_NO_WARNINGS
|
|
|
|
#endif
|
|
|
|
|
2006-04-18 04:26:56 +00:00
|
|
|
#endif
|
2005-07-06 09:14:43 +00:00
|
|
|
|
2014-03-06 23:27:54 +00:00
|
|
|
// Target Windows XP or better with Internet Explorer 5.01 or better
|
2009-07-29 23:50:00 +00:00
|
|
|
#ifndef WINVER
|
2014-03-06 23:27:54 +00:00
|
|
|
#define WINVER 0x0501
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2009-07-29 23:50:00 +00:00
|
|
|
#ifndef _WIN32_WINNT
|
2014-03-06 23:27:54 +00:00
|
|
|
#define _WIN32_WINNT 0x0501
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2009-07-29 23:50:00 +00:00
|
|
|
#ifndef _WIN32_WINDOWS
|
2014-03-06 23:27:54 +00:00
|
|
|
#define _WIN32_WINDOWS 0x0501
|
2004-03-04 11:41:43 +00:00
|
|
|
#endif
|
2009-07-29 23:50:00 +00:00
|
|
|
#ifndef _WIN32_IE
|
2009-11-13 21:23:15 +00:00
|
|
|
#define _WIN32_IE 0x0501
|
2006-06-09 19:57:36 +00:00
|
|
|
#endif
|
2013-11-15 04:26:06 +00:00
|
|
|
#ifndef SECURITY_WIN32
|
|
|
|
#define SECURITY_WIN32
|
|
|
|
#endif
|
2004-03-04 11:41:43 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
|
|
|
|
#if !defined(__CYGWIN32__) || defined(USE_WINSOCK)
|
2006-04-14 03:09:24 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
/* If we're not running under CYGWIN use windows networking */
|
|
|
|
#undef USE_WINSOCK
|
|
|
|
#define USE_WINSOCK 1
|
2014-04-29 14:50:33 +00:00
|
|
|
#ifdef HAVE_WINSOCK2_H
|
|
|
|
#include <winsock2.h>
|
|
|
|
#else
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <winsock.h>
|
2014-04-29 14:50:33 +00:00
|
|
|
#endif
|
2014-03-06 23:27:54 +00:00
|
|
|
#include <winhttp.h>
|
2005-12-16 03:35:15 +00:00
|
|
|
|
2007-11-13 17:25:23 +00:00
|
|
|
typedef size_t socklen_t;
|
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#else
|
2006-04-14 03:09:24 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
/* 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_
|
2006-04-14 03:09:24 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#endif
|
|
|
|
|
2014-04-29 14:50:33 +00:00
|
|
|
#include <windows.h>
|
|
|
|
#include <winternl.h>
|
|
|
|
#include <share.h>
|
|
|
|
#include <shlobj.h>
|
|
|
|
#include <userenv.h>
|
|
|
|
#include <aclapi.h>
|
|
|
|
#include <psapi.h>
|
|
|
|
#include <iphlpapi.h>
|
|
|
|
#include <wtsapi32.h>
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <process.h>
|
2005-12-16 03:35:15 +00:00
|
|
|
#if defined(__MINGW32__) || defined(__CYGWIN32__)
|
2005-12-01 00:25:21 +00:00
|
|
|
#include <pbt.h>
|
|
|
|
#endif
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <commctrl.h>
|
|
|
|
#include <raserror.h>
|
2010-05-14 16:22:57 +00:00
|
|
|
#if defined(__MINGW32__)
|
2009-11-16 13:13:42 +00:00
|
|
|
#include <stdint.h>
|
2009-10-07 19:17:52 +00:00
|
|
|
#include <imagehlp.h>
|
|
|
|
#else
|
2014-01-31 07:15:03 +00:00
|
|
|
#include <security.h>
|
2006-05-01 21:36:38 +00:00
|
|
|
#include <dbghelp.h>
|
2009-10-07 19:17:52 +00:00
|
|
|
#endif
|
2006-05-01 21:36:38 +00:00
|
|
|
#include <tlhelp32.h>
|
|
|
|
|
2006-05-17 07:44:54 +00:00
|
|
|
#include <io.h>
|
2005-12-16 03:35:15 +00:00
|
|
|
#if !defined(__CYGWIN32__)
|
2004-03-08 18:54:55 +00:00
|
|
|
#include <direct.h>
|
2005-12-16 03:35:15 +00:00
|
|
|
#endif
|
2006-04-14 03:09:24 +00:00
|
|
|
|
2005-12-16 03:35:15 +00:00
|
|
|
#if !defined(__CYGWIN32__)
|
2004-03-08 18:54:55 +00:00
|
|
|
#include <tchar.h>
|
2006-04-14 03:09:24 +00:00
|
|
|
#else
|
|
|
|
#ifndef _TCHAR_DEFINED
|
|
|
|
typedef char TCHAR, *PTCHAR;
|
|
|
|
typedef unsigned char TBYTE , *PTBYTE ;
|
|
|
|
#define _TCHAR_DEFINED
|
|
|
|
#endif /* !_TCHAR_DEFINED */
|
|
|
|
typedef LPSTR LPTCH, PTCH;
|
|
|
|
typedef LPSTR PTSTR, LPTSTR, PUTSTR, LPUTSTR;
|
|
|
|
typedef LPCSTR PCTSTR, LPCTSTR, PCUTSTR, LPCUTSTR;
|
|
|
|
#define __TEXT(quote) quote
|
2005-12-01 00:25:21 +00:00
|
|
|
#endif
|
2006-05-01 21:36:38 +00:00
|
|
|
|
2004-12-06 23:02:47 +00:00
|
|
|
// All projects should be using std::min and std::max instead of the Windows
|
|
|
|
// version of the symbols.
|
|
|
|
#undef min
|
|
|
|
#undef max
|
|
|
|
|
2004-03-04 11:41:43 +00:00
|
|
|
// Standard Libraries
|
|
|
|
//
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
// C headers
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <sys/types.h>
|
2010-05-14 16:22:57 +00:00
|
|
|
#if !defined(__MINGW32__)
|
2004-12-07 23:04:12 +00:00
|
|
|
#include <fcntl.h>
|
2009-10-07 19:17:52 +00:00
|
|
|
#endif
|
2006-05-11 23:19:04 +00:00
|
|
|
#include <malloc.h>
|
2004-12-07 23:04:12 +00:00
|
|
|
|
2006-05-17 07:44:54 +00:00
|
|
|
#if !defined(__MINGW32__) && !defined(__CYGWIN32__)
|
|
|
|
#include <crtdbg.h>
|
|
|
|
#include <delayimp.h>
|
|
|
|
#endif
|
|
|
|
|
2004-12-08 07:53:30 +00:00
|
|
|
#ifdef __cplusplus
|
2010-05-11 19:10:29 +00:00
|
|
|
#include <algorithm>
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <cassert>
|
|
|
|
#include <cctype>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cerrno>
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <cmath>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <csetjmp>
|
2006-05-11 23:19:04 +00:00
|
|
|
#include <csignal>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <cstdarg>
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <cstdlib>
|
2005-12-01 00:25:21 +00:00
|
|
|
#include <cstdio>
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <cstring>
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <ctime>
|
2005-07-09 05:23:40 +00:00
|
|
|
#include <cfloat>
|
2005-02-04 10:14:03 +00:00
|
|
|
#include <locale>
|
2004-12-07 23:04:12 +00:00
|
|
|
#else
|
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <setjmp.h>
|
2006-05-11 23:19:04 +00:00
|
|
|
#include <signal.h>
|
2004-12-07 23:04:12 +00:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
2005-07-09 05:23:40 +00:00
|
|
|
#include <float.h>
|
2005-02-04 10:14:03 +00:00
|
|
|
#include <locale.h>
|
2004-12-07 23:04:12 +00:00
|
|
|
#endif
|
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
// C++ headers
|
2004-12-08 07:38:22 +00:00
|
|
|
//
|
2004-12-08 07:53:30 +00:00
|
|
|
#ifdef __cplusplus
|
2004-07-13 13:54:09 +00:00
|
|
|
#include <algorithm>
|
2004-03-04 11:41:43 +00:00
|
|
|
#include <string>
|
|
|
|
#include <iostream>
|
|
|
|
#include <fstream>
|
|
|
|
#include <sstream>
|
|
|
|
#include <vector>
|
2004-09-30 21:41:09 +00:00
|
|
|
#include <deque>
|
2004-06-17 04:49:34 +00:00
|
|
|
#include <list>
|
2005-04-13 18:38:55 +00:00
|
|
|
#include <map>
|
|
|
|
#include <set>
|
2009-11-11 20:33:12 +00:00
|
|
|
#include <stdexcept>
|
2004-12-07 23:04:12 +00:00
|
|
|
#endif
|
2004-03-04 11:41:43 +00:00
|
|
|
|
2009-04-23 03:40:49 +00:00
|
|
|
// Define a generic string type that can be a Unicode string on
|
|
|
|
// Unicode builds and an ANSI string on ANSI builds
|
|
|
|
//
|
|
|
|
#ifdef _UNICODE
|
|
|
|
#define tstring std::wstring
|
|
|
|
#else
|
|
|
|
#define tstring std::string
|
|
|
|
#endif
|
2006-05-11 23:19:04 +00:00
|
|
|
|
|
|
|
#ifndef SIGRTMAX
|
|
|
|
#if defined(_SIGRTMAX)
|
|
|
|
#define SIGRTMAX _SIGRTMAX
|
|
|
|
#elif defined(NSIG)
|
|
|
|
#define SIGRTMAX (NSIG-1)
|
|
|
|
#else
|
|
|
|
#define SIGRTMAX 32
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2007-03-20 01:42:36 +00:00
|
|
|
#ifndef __GNUC__
|
|
|
|
#define __attribute__(x)
|
2005-12-16 03:35:15 +00:00
|
|
|
#endif
|
2004-03-08 18:54:55 +00:00
|
|
|
|
2011-10-24 23:38:19 +00:00
|
|
|
#if defined(__MINGW32__)
|
2011-06-02 16:25:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2014-04-29 14:50:33 +00:00
|
|
|
#ifndef __MINGW_NOTHROW
|
|
|
|
#define __MINGW_NOTHROW
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE__FPRESET
|
|
|
|
void __cdecl __MINGW_NOTHROW _fpreset (void);
|
|
|
|
#endif
|
|
|
|
#ifndef HAVE_FPRESET
|
|
|
|
void __cdecl __MINGW_NOTHROW fpreset (void);
|
|
|
|
#endif
|
2011-06-02 16:25:30 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif //cplusplus
|
2011-10-24 23:38:19 +00:00
|
|
|
#endif //MINGW32
|
|
|
|
|
|
|
|
#if defined(__MINGW32__) && (__GNUC__ < 4)
|
|
|
|
// breaks build on MinGW gcc-4
|
2008-01-31 18:34:51 +00:00
|
|
|
#define SetClassLongPtr SetClassLong
|
|
|
|
#define GCLP_HICON GCL_HICON
|
|
|
|
#define GCLP_HICONSM GCL_HICONSM
|
2011-03-26 02:19:21 +00:00
|
|
|
#endif //MINGW32 && GNUC < 4
|
2006-05-15 17:14:15 +00:00
|
|
|
|
2004-03-23 07:34:34 +00:00
|
|
|
// On the Win32 platform include file and line number information for each
|
|
|
|
// memory allocation/deallocation
|
|
|
|
#ifdef _DEBUG
|
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
|
|
|
|
#define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
|
|
|
|
#define realloc(p, s) _realloc_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
|
|
|
|
#define _expand(p, s) _expand_dbg(p, s, _NORMAL_BLOCK, __FILE__, __LINE__)
|
|
|
|
#define free(p) _free_dbg(p, _NORMAL_BLOCK)
|
|
|
|
#define _msize(p) _msize_dbg(p, _NORMAL_BLOCK)
|
|
|
|
#define _aligned_malloc(s, a) _aligned_malloc_dbg(s, a, __FILE__, __LINE__)
|
|
|
|
#define _aligned_realloc(p, s, a) _aligned_realloc_dbg(p, s, a, __FILE__, __LINE__)
|
|
|
|
#define _aligned_offset_malloc(s, a, o) _aligned_offset_malloc_dbg(s, a, o, __FILE__, __LINE__)
|
|
|
|
#define _aligned_offset_realloc(p, s, a, o) _aligned_offset_realloc_dbg(p, s, a, o, __FILE__, __LINE__)
|
|
|
|
#define _aligned_free(p) _aligned_free_dbg(p)
|
2004-03-23 07:34:34 +00:00
|
|
|
|
2004-12-06 23:02:47 +00:00
|
|
|
#ifndef DEBUG_NEW
|
2004-03-24 07:39:24 +00:00
|
|
|
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
|
2004-12-06 23:02:47 +00:00
|
|
|
#endif
|
2004-03-23 07:34:34 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
// The following macros set and clear, respectively, given bits
|
|
|
|
// of the C runtime library debug flag, as specified by a bitmask.
|
|
|
|
#define SET_CRT_DEBUG_FIELD(a) _CrtSetDbgFlag((a) | _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
|
|
|
|
#define CLEAR_CRT_DEBUG_FIELD(a) _CrtSetDbgFlag(~(a) & _CrtSetDbgFlag(_CRTDBG_REPORT_FLAG))
|
2004-03-23 07:34:34 +00:00
|
|
|
|
2004-03-24 07:39:24 +00:00
|
|
|
#else //_DEBUG
|
2004-03-23 07:34:34 +00:00
|
|
|
|
2004-12-06 23:02:47 +00:00
|
|
|
#ifndef DEBUG_NEW
|
2004-03-24 07:39:24 +00:00
|
|
|
#define DEBUG_NEW new
|
2004-12-06 23:02:47 +00:00
|
|
|
#endif
|
2004-03-23 07:34:34 +00:00
|
|
|
|
2004-07-13 13:54:09 +00:00
|
|
|
#define SET_CRT_DEBUG_FIELD(a) ((void) 0)
|
|
|
|
#define CLEAR_CRT_DEBUG_FIELD(a) ((void) 0)
|
2004-03-23 07:34:34 +00:00
|
|
|
|
|
|
|
#endif //_DEBUG
|
|
|
|
|
|
|
|
#define new DEBUG_NEW
|
|
|
|
|
2004-06-30 18:17:21 +00:00
|
|
|
#endif //_BOINC_WIN_
|