Fixes for compilation under Windows (specifically MSVC). Also added MSVC supported "_inline", and fixed some WIN32 specific warnings.

(cherry picked from commit 92ea719804)
This commit is contained in:
Iain Denniston 2011-03-18 12:35:19 +00:00 committed by Marcelo Roberto Jimenez
parent 7392697aec
commit 259bed7787
15 changed files with 59 additions and 28 deletions

View File

@ -255,6 +255,11 @@ Version 1.8.0
Version 1.6.14
*******************************************************************************
2011-03-18 Iain Denniston <iain.denniston(at)gmail.com>
Fixes for compilation under Windows (specifically MSVC). Also added
MSVC supported "_inline", and fixed some WIN32 specific warnings.
2011-03-08 Iain Denniston <iain.denniston(at)gmail.com>
Several fixes to correctly use SOCKET (and related) types instead of

View File

@ -922,7 +922,8 @@ static UPNP_INLINE int ithread_cleanup_thread(void) {
#endif
#if !defined(PTHREAD_MUTEX_RECURSIVE) && !defined(__DragonFly__)
#if !defined(PTHREAD_MUTEX_RECURSIVE) && !defined(__DragonFly__) && !defined(UPNP_USE_MSVCPP)
/* !defined(UPNP_USE_MSVCPP) should probably also have pthreads version check - but it's not clear if that is possible */
/* NK: Added for satisfying the gcc compiler */
EXPORT_SPEC int pthread_mutexattr_setkind_np(pthread_mutexattr_t *attr, int kind);
#endif

View File

@ -292,8 +292,8 @@ static int SetPriority(
/*! . */
ThreadPriority priority)
{
int retVal = 0;
#if defined(_POSIX_PRIORITY_SCHEDULING) && _POSIX_PRIORITY_SCHEDULING > 0
int retVal = 0;
int currentPolicy;
int minPriority = 0;
int maxPriority = 0;
@ -325,11 +325,12 @@ static int SetPriority(
sched_result = pthread_setschedparam(ithread_self(), currentPolicy, &newPriority);
retVal = (sched_result == 0 || errno == EPERM) ? 0 : sched_result;
#else
retVal = 0;
#endif
exit_function:
return retVal;
#else
return 0;
priority = priority;
#endif
}
/*!

View File

@ -40,7 +40,7 @@
*/
#ifdef UPNP_USE_MSVCPP
/* define some things the M$ VC++ doesn't know */
#define UPNP_INLINE
#define UPNP_INLINE _inline
typedef __int64 int64_t;
#define PRId64 "I64d"
#define PRIzd "ld"

View File

@ -15,8 +15,11 @@
#ifdef WIN32
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#ifndef UPNP_USE_MSVCPP
/* Removed: not required (and cause compilation issues) */
#include <winbase.h>
#include <windef.h>
#endif
#include <winsock2.h>
#include <iphlpapi.h>
#include <ws2tcpip.h>

View File

@ -1,11 +1,11 @@
#ifndef UPNPINTTYPES_H
#define UPNPINTTYPES_H
#if !defined(UPNP_USE_BCBPP) && !defined(UPNP_USE_MSVCPP)
#if !defined(UPNP_USE_BCBPP)
/* Printf format for integers. */
#include <inttypes.h>
#endif /* !defined(UPNP_USE_BCBPP) && !defined(UPNP_USE_MSVCPP) */
#endif /* !defined(UPNP_USE_BCBPP) */
#endif /* UPNPINTTYPES_H */

View File

@ -1,11 +1,20 @@
#ifndef UPNPSTDINT_H
#define UPNPSTDINT_H
#if !defined(UPNP_USE_BCBPP) && !defined(UPNP_USE_MSVCPP)
#if !defined(UPNP_USE_BCBPP)
/* Sized integer types. */
#include <stdint.h>
#endif /* !defined(UPNP_USE_BCBPP) && !defined(UPNP_USE_MSVCPP) */
#ifdef UPNP_USE_MSVCPP
/* no ssize_t defined for VC */
#ifdef _WIN64
typedef int64_t ssize_t;
#else
typedef int32_t ssize_t;
#endif
#endif
#endif /* !defined(UPNP_USE_BCBPP) */
#endif /* UPNPSTDINT_H */

View File

@ -51,6 +51,9 @@
*/
#ifdef WIN32
#include <time.h>
#ifdef UPNP_USE_MSVCPP
#include <sys/types.h> /* needed for off_t */
#endif
#elif (defined(BSD) && BSD >= 199306)
#include <time.h>
#else

View File

@ -28,16 +28,19 @@
/* Other systems have strncasecmp */
#endif
/* strnlen() is a GNU extension. */
#if HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t maxlen);
#else /* HAVE_STRNLEN */
static size_t strnlen(const char *s, size_t n)
{
const char *p = (const char *)memchr(s, 0, n);
return p ? p - s : n;
}
#endif /* HAVE_STRNLEN */
#ifndef UPNP_USE_MSVCPP
/* VC has strnlen which is already included but with (potentially) different linkage */
/* strnlen() is a GNU extension. */
#if HAVE_STRNLEN
extern size_t strnlen(const char *s, size_t maxlen);
#else /* HAVE_STRNLEN */
static size_t strnlen(const char *s, size_t n)
{
const char *p = (const char *)memchr(s, 0, n);
return p ? p - s : n;
}
#endif /* HAVE_STRNLEN */
#endif /* WIN32 */
/* strndup() is a GNU extension. */
#if HAVE_STRNDUP && !defined(WIN32)

View File

@ -118,6 +118,7 @@ int DebugAtThisLevel(Upnp_LogLevel DLevel, Dbg_Module Module)
(Module == DOM && DEBUG_DOM) || (Module == HTTP && DEBUG_HTTP);
return ret;
Module = Module; /* VC complains about this being unreferenced */
}
void UpnpPrintf(Upnp_LogLevel DLevel,

View File

@ -493,7 +493,8 @@ Cleanup_File:
num_written = (size_t)nw;
UpnpPrintf(UPNP_INFO, HTTP, __FILE__, __LINE__,
">>> (SENT) >>>\n"
"%.*s\nbuf_length=%zd, num_written=%zd\n""------------\n",
"%.*s\nbuf_length=%" PRIzd ", num_written=%" PRIzd "\n"
"------------\n",
(int)buf_length, buf, buf_length, num_written);
if (num_written != buf_length) {
RetVal = 0;

View File

@ -112,7 +112,8 @@ void linecopylen(
#define ERROR_BUFFER_LEN 256
/* C specific */
#ifndef __cplusplus
/* VC needs these in C++ mode too (do other compilers?) */
#if !defined(__cplusplus) || defined(UPNP_USE_MSVCPP)
#ifdef WIN32
#ifndef S_ISREG
#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG)
@ -130,7 +131,7 @@ void linecopylen(
#define max(a, b) (((a)>(b))? (a):(b))
#define min(a, b) (((a)<(b))? (a):(b))
#endif /* WIN32 */
#endif /* __cplusplus */
#endif /* !defined(__cplusplus) || defined(UPNP_USE_MSVCPP) */
#endif /* UTIL_H */

View File

@ -52,7 +52,10 @@
#include <time.h>
#ifdef WIN32
#include "inet_pton.h"
#ifndef UPNP_USE_MSVCPP
/* VC Winsocks2 includes these functions */
#include "inet_pton.h"
#endif
#else
#include <netdb.h> /* for struct addrinfo */
#endif

View File

@ -379,7 +379,7 @@ get_response_value( IN http_message_t * hmsg,
char *node_str = NULL;
const char *temp_str = NULL;
DOMString error_node_str = NULL;
int err_code = UPNP_E_BAD_RESPONSE; /* default error */ ;
int err_code = UPNP_E_BAD_RESPONSE; /* default error */
int done = FALSE;
const char *names[5];
const DOMString nodeValue;

View File

@ -106,7 +106,7 @@ void get_random_info(unsigned char seed[16])
GetComputerName( r.hostname, &r.l );
/* MD5 it */
MD5Init(&c);
MD5Update(&c, &r, sizeof r);
MD5Update(&c, (unsigned char *)(&r), sizeof r);
MD5Final(seed, &c);
};