Jelajahi Sumber

T20M5021 #comment libtoolkit 暂时编译通过

gifur 5 tahun lalu
induk
melakukan
bba894efe4

+ 19 - 2
libtoolkit/CMakeLists.txt

@@ -22,10 +22,27 @@ list(REMOVE_ITEM ${MODULE_PREFIX}_SRCS
     iconv.c
     iconv.h
     ioreactor.c
-    ioreactor.h)
+    ioreactor.h
+    ntservice.h
+    ntservice.c
+    rbtree.h
+    rbtree.c
+    regddx.h
+    regddx.c
+    stacktrace.c
+    stacktrace.h
+    stest.c # the test framework xlei customized.
+    stest.h
+    stm.c
+    stm.h
+    strptime.h # linux confilct and also no appied at windows
+    strptime.c
+    )
 if(NOT WIN32)
 list(REMOVE_ITEM ${MODULE_PREFIX}_SRCS 
-    gettimeofday.c)
+    gettimeofday.c shm.h shm.c
+    wavfile.c wavfile.h
+    )
 endif()
 #foreach(item ${${MODULE_PREFIX}_SRCS})
 #    message(STATUS ${item})

+ 5 - 0
libtoolkit/config.h

@@ -29,6 +29,11 @@
 #endif
 #endif
 
+//for linux compatibility. linux is unable to recognize __int64
+#ifdef _WIN32
+#define u__int64_t unsigned __int64
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif

+ 1 - 1
libtoolkit/jhash.h

@@ -1,7 +1,7 @@
 #ifndef _LINUX_JHASH_H
 #define _LINUX_JHASH_H
 
-#include "stdint.h"
+#include <stdint.h>
 
 /* jhash.h: Jenkins hash support.
  *

+ 2 - 0
libtoolkit/memutil.c

@@ -1,6 +1,7 @@
 #include "precompile.h"
 #include "memutil.h"
 #include "shm_mem.h"
+#include <winpr/locale.h>
 
 TOOLKIT_API void *buffer_resize(void* old, int elemsize, int oldcnt, int newcnt)
 {
@@ -105,6 +106,7 @@ TOOLKIT_API void debug_trace(const char *fmt, ...)
 
 TOOLKIT_API int GetSystemErrorDesc(int error_code, char *buf, int n)
 {
+	//TODO: implement or compatible
 	DWORD dwRet = FormatMessageA(
 		FORMAT_MESSAGE_IGNORE_INSERTS | FORMAT_MESSAGE_FROM_SYSTEM,
 		NULL,

+ 24 - 9
libtoolkit/osutil.c

@@ -1,8 +1,13 @@
 #include "precompile.h"
 #include "osutil.h"
+
+
+#ifdef _WIN32
+
+
 #include <TlHelp32.h>
 
-TOOLKIT_API int osutil_detect_unique_app(char **pNames, int nNum)
+TOOLKIT_API int osutil_detect_unique_app(char** pNames, int nNum)
 {
 	//const WCHAR *exe;
 	HANDLE hSnapshot;
@@ -19,15 +24,11 @@ TOOLKIT_API int osutil_detect_unique_app(char **pNames, int nNum)
 	if (hSnapshot) {
 		PROCESSENTRY32 pe;
 		pe.dwSize = sizeof(pe);
-		if (Process32First(hSnapshot, &pe)) 
-		{
-			do 
-			{
+		if (Process32First(hSnapshot, &pe)) {
+			do {
 				int i;
-				for (i = 0; i < nNum; i++)
-				{
-					if (stricmp(&pe.szExeFile[0], pNames[i]) == 0 && pe.th32ProcessID != dwCurProcID)
-					{
+				for (i = 0; i < nNum; i++) {
+					if (stricmp(&pe.szExeFile[0], pNames[i]) == 0 && pe.th32ProcessID != dwCurProcID) {
 						rc = FALSE;
 						break;
 					}
@@ -39,3 +40,17 @@ TOOLKIT_API int osutil_detect_unique_app(char **pNames, int nNum)
 
 	return rc;
 }
+
+
+#else
+
+TOOLKIT_API int osutil_detect_unique_app(char** pNames, int nNum)
+{
+	//TODO: implement it.
+	return -1;
+}
+
+#endif
+
+
+

+ 2 - 0
libtoolkit/process_monitor.c

@@ -4,6 +4,8 @@
 #include "spinlock.h"
 
 #include <assert.h>
+#include <winpr/synch.h>
+#include <winpr/thread.h>
 
 
 #define CMD_REMOVE	0

+ 2 - 0
libtoolkit/process_monitor.h

@@ -4,6 +4,8 @@
 #pragma once
 
 #include "config.h"
+#include <winpr/wtypes.h>
+
 
 #ifdef __cplusplus
 extern "C" {

+ 1 - 0
libtoolkit/q_malloc.c

@@ -36,6 +36,7 @@
 #include "precompile.h"
 
 #include "q_malloc.h"
+#include <winpr/wtypes.h>
 
 /*useful macros*/
 #define FRAG_END(f)  \

+ 1 - 0
libtoolkit/refcnt.h

@@ -2,6 +2,7 @@
 #define REF_COUNT_H
 
 #pragma once
+#include <winpr/wtypes.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 24 - 19
libtoolkit/rtp.c

@@ -81,13 +81,15 @@ static void get_base_time(void)
 	st.wDay=1;
 	SystemTimeToFileTime(&st, &ft);
 
-	toolkit_getResource()->base_time.LowPart = ft.dwLowDateTime;
-	toolkit_getResource()->base_time.HighPart = ft.dwHighDateTime;
+	/*for linux compatibility*/
+	toolkit_getResource()->base_time.u.LowPart = ft.dwLowDateTime;
+	toolkit_getResource()->base_time.u.HighPart = ft.dwHighDateTime;
 	toolkit_getResource()->base_time.QuadPart /= SECS_TO_FT_MULT;
 }
 
-static void gettimeofday(struct timeval *tv)
+static void conflict_gettimeofday(struct timeval *tv)
 {
+#ifdef _WIN32
 	SYSTEMTIME st;
 	FILETIME ft;
 	LARGE_INTEGER li;
@@ -98,13 +100,16 @@ static void gettimeofday(struct timeval *tv)
 	if (toolkit_getResource()->base_time.QuadPart == 0)
 		get_base_time();
 
-	li.LowPart = ft.dwLowDateTime;
-	li.HighPart = ft.dwHighDateTime;
+	li.u.LowPart = ft.dwLowDateTime;
+	li.u.HighPart = ft.dwHighDateTime;
 	li.QuadPart /= SECS_TO_FT_MULT;
 	li.QuadPart -= toolkit_getResource()->base_time.QuadPart;
 
-	tv->tv_sec = li.LowPart;
+	tv->tv_sec = li.u.LowPart;
 	tv->tv_usec = st.wMilliseconds * 1000;
+#else
+	gettimeofday(tv, NULL);
+#endif
 }
 
 static char *copymsg(char *msg, int len)
@@ -160,7 +165,7 @@ static rtcp_fb_tmmbr_fci_t * rtcp_rtpfb_tmmbr_get_fci(const char *msg) {
 	return (rtcp_fb_tmmbr_fci_t *)(msg + size - sizeof(rtcp_fb_tmmbr_fci_t));
 }
 
-static unsigned __int64 rtcp_rtpfb_tmmbr_get_max_bitrate(const char *msg) {
+static u__int64_t rtcp_rtpfb_tmmbr_get_max_bitrate(const char *msg) {
 	rtcp_fb_tmmbr_fci_t *fci = rtcp_rtpfb_tmmbr_get_fci(msg);
 	return rtcp_fb_tmmbr_fci_get_mxtbr_mantissa(fci) * (1 << rtcp_fb_tmmbr_fci_get_mxtbr_exp(fci));
 }
@@ -245,23 +250,23 @@ TOOLKIT_API int rtp_state_set_rtcp_sdes_string(rtp_state *rs,
 	return rs->sdes_str[type] ? 0 : -1;
 }
 
-static unsigned __int64 rtp_timeval_to_ntp(const struct timeval *tv){
-   unsigned __int64 msw;
-   unsigned __int64 lsw;
+static u__int64_t rtp_timeval_to_ntp(const struct timeval *tv){
+   u__int64_t msw;
+   u__int64_t lsw;
    msw=tv->tv_sec + 0x83AA7E80; /* 0x83AA7E80 is the number of seconds from 1900 to 1970 */
-   lsw=(unsigned int)((double)tv->tv_usec*(double)(((unsigned __int64)1)<<32)*1.0e-6);
+   lsw=(unsigned int)((double)tv->tv_usec*(double)(((u__int64_t)1)<<32)*1.0e-6);
    return msw<<32 | lsw;
 }
 
 TOOLKIT_API int rtp_state_fill_rtcp_sender_info(rtp_state *rs, rtcp_sender_info_t *info)
 {
 	struct timeval tv;
-	unsigned __int64 ntp;
+	u__int64_t ntp;
 
 	if (!rs)
 		return -1;
 	info->ssrc = rs->ssrc; /* sender's own ssrc */
-	gettimeofday(&tv);
+	conflict_gettimeofday(&tv);
 	ntp=rtp_timeval_to_ntp(&tv);
 	info->ntp_sec = htonl(ntp >>32);//(unsigned int)htonl(tv.tv_sec + JAN_1970);
 	info->ntp_frac = htonl(ntp & 0xFFFFFFFF);//(unsigned int)htonl((unsigned long)(tv.tv_usec*4294.967296));
@@ -297,7 +302,7 @@ TOOLKIT_API int rtp_state_fill_rtcp_reception_report(rtp_state *rs, rtcp_rr_t *r
 	if (rs->s.lsr_tm.tv_sec != 0) {
 		struct timeval now;
 		double delay;
-		gettimeofday(&now);
+		conflict_gettimeofday(&now);
 		delay= (now.tv_sec-rs->s.lsr_tm.tv_sec)+ ((now.tv_usec-rs->s.lsr_tm.tv_usec)*1e-6);
 		delay= (delay*65536);
 		delay_since_lsr=(unsigned int) delay;
@@ -598,7 +603,7 @@ TOOLKIT_API int rtp_state_rtcp_make_h261_nack(rtp_state *rs, char *buf, size_t b
 }
 
 
-TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbr(rtp_state *rs, char *buf, size_t buflen, unsigned __int64 mxtbr, unsigned short measured_overhead) {
+TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbr(rtp_state *rs, char *buf, size_t buflen, u__int64_t mxtbr, unsigned short measured_overhead) {
 	rtcp_common_t *ch;
 	rtcp_fb_header_t *fbh;
 	rtcp_fb_tmmbr_fci_t *fci;
@@ -673,7 +678,7 @@ TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbn(rtp_state *rs, char *buf, size
 }
 
 
-int rtp_state_get_tmmbr_wait_send_maxbitrate(rtp_state *rs, unsigned __int64 *mxtbr){
+int rtp_state_get_tmmbr_wait_send_maxbitrate(rtp_state *rs, u__int64_t *mxtbr){
 	if (rs->tmmbr_info.sent) {
 		*mxtbr = rtcp_rtpfb_tmmbr_get_max_bitrate(rs->tmmbr_info.sent);
 		return 0;
@@ -722,7 +727,7 @@ static void compute_rtt_from_report_block(rtp_state *rs, const struct timeval *n
 	unsigned int last_sr_time;
 	unsigned int sr_delay;
 	
-	unsigned __int64 curntp;
+	u__int64_t curntp;
 	unsigned int approx_ntp;
 
 	last_sr_time = ntohl(rr->lsr);
@@ -763,12 +768,12 @@ TOOLKIT_API int rtp_state_on_recv_rtcp(rtp_state *rs, const void *buf, int len)
 				rtcp_sender_info_t *si;
 				si = (rtcp_sender_info_t *)((const char*)buf + n);
 				rs->s.lsr = ( ntohl( si->ntp_sec ) << 16 ) | ( ntohl( si->ntp_frac ) >> 16 );
-				gettimeofday(&rs->s.lsr_tm);
+				conflict_gettimeofday(&rs->s.lsr_tm);
 			}
 			if ((common->pt == RTCP_SR || common->pt == RTCP_RR) && common->count) {
 				rtcp_rr_t *rr;
 				struct timeval now;
-				gettimeofday(&now);
+				conflict_gettimeofday(&now);
 				
 				if (common->pt == RTCP_SR)
 					rr = rtcp_SR_get_report_block((const char*)buf);

+ 7 - 3
libtoolkit/rtp.h

@@ -4,6 +4,10 @@
 #pragma once
 
 #include "config.h"
+#include <winpr/wtypes.h>
+#ifndef _WIN32
+#include <sys/time.h>
+#endif
 
 #ifdef __cplusplus
 extern "C" {
@@ -270,7 +274,7 @@ typedef struct {
 	unsigned int report_block_last_seq;
 	int report_block_last_number_of_packets;
 	
-	unsigned __int64 tmmbr_max_bitrate;
+	u__int64_t tmmbr_max_bitrate;
 }rtcp_statistics;
 
 #pragma pack(1)
@@ -295,7 +299,7 @@ typedef struct rtp_dtmf_event rtp_dtmf_event;
 
 typedef struct rtp_state rtp_state;
 
-int rtp_state_get_tmmbr_wait_send_maxbitrate(rtp_state *rs, unsigned __int64 *mxtbr);
+int rtp_state_get_tmmbr_wait_send_maxbitrate(rtp_state *rs, u__int64_t *mxtbr);
 
 TOOLKIT_API int rtp_state_fill_rtp(rtp_state *rs, void *hdr, unsigned int pt, unsigned int mark, unsigned int delta_ts);
 TOOLKIT_API int rtp_state_advance_timestamp(rtp_state *rs, unsigned int delta_ts);
@@ -309,7 +313,7 @@ TOOLKIT_API int rtp_state_rtcp_make_h261_fir(rtp_state *rs, char *buf, size_t bu
 
 
 TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbn(rtp_state *rs, char *buf, size_t buflen, unsigned int ssrc);
-TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbr(rtp_state *rs, char *buf, size_t buflen, unsigned __int64 mxtbr, unsigned short measured_overhead);
+TOOLKIT_API int rtp_state_rtcp_make_rtcp_fb_tmmbr(rtp_state *rs, char *buf, size_t buflen, u__int64_t mxtbr, unsigned short measured_overhead);
 
 /**
  * called when receive a peer's rtp data packet

+ 4 - 3
libtoolkit/rtpsession.c

@@ -1,5 +1,6 @@
 #include "precompile.h"
 #include "rtpsession.h"
+#include <winpr/winsock.h>
 
 #define MAX_RTCP_BUF 1500
 
@@ -510,7 +511,7 @@ TOOLKIT_API int rtp_session_send_hook2(rtp_session_t *sess,
 	if (!(sess->flags & RTP_SESSION_FLAG_NO_RTCP)) {
 		if (rtp_state_need_send_rtcp(sess->rtpstat, TRUE) && sess->remote_rtcp_addr.sin_port != 0) {
 			char tmp[MAX_RTCP_BUF];
-			unsigned __int64 mxtbr;
+			u__int64_t mxtbr;
 			ret = rtp_state_rtcp_make_sr(sess->rtpstat, tmp, sizeof(tmp));
 			udp_block_send(sess->rtcp_fd, (struct sockaddr*)&sess->remote_rtcp_addr, 
 				sizeof(struct sockaddr_in), tmp, ret);
@@ -548,7 +549,7 @@ TOOLKIT_API int rtp_session_send_raw(rtp_session_t *sess,
 	if (!(sess->flags & RTP_SESSION_FLAG_NO_RTCP)) {
 		if (rtp_state_need_send_rtcp(sess->rtpstat, TRUE) && sess->remote_rtcp_addr.sin_port != 0) {
 			char tmp[MAX_RTCP_BUF];
-			unsigned __int64 mxtbr;
+			u__int64_t mxtbr;
 			ret = rtp_state_rtcp_make_sr(sess->rtpstat, tmp, sizeof(tmp));
 			udp_block_send(sess->rtcp_fd, (struct sockaddr*)&sess->remote_rtcp_addr, 
 				sizeof(struct sockaddr_in), tmp, ret);
@@ -576,7 +577,7 @@ TOOLKIT_API int rtp_session_send_rtcp_h261_fir(rtp_session_t *sess)
 }
 
 
-TOOLKIT_API int rtp_session_send_rtcp_fb_tmmbr(rtp_session_t *sess, unsigned __int64 mxtbr) {
+TOOLKIT_API int rtp_session_send_rtcp_fb_tmmbr(rtp_session_t *sess, u__int64_t mxtbr) {
 	if (sess && !(sess->flags & RTP_SESSION_FLAG_NO_RTCP)) {
 		char tmp[MAX_RTCP_BUF];
 		int n;

+ 1 - 1
libtoolkit/rtpsession.h

@@ -70,7 +70,7 @@ TOOLKIT_API int rtp_session_send_raw(rtp_session_t *sess,
 // huawei openeye need this
 TOOLKIT_API int rtp_session_send_rtcp_h261_fir(rtp_session_t *sess);
 // bitrate control
-TOOLKIT_API int rtp_session_send_rtcp_fb_tmmbr(rtp_session_t *sess, unsigned __int64 mxtbr);
+TOOLKIT_API int rtp_session_send_rtcp_fb_tmmbr(rtp_session_t *sess, u__int64_t mxtbr);
 
 #define RTP_SESSION_HAS_SDES	0x01
 #define	RTP_SESSION_HAS_FIR		0x02

+ 1 - 0
libtoolkit/shm_table.c

@@ -5,6 +5,7 @@
 #include "shm_mem.h"
 #include "list.h"
 #include "hash.h"
+#include <winpr/synch.h>
 
 #define HTABLE_SLOT_NUM	1023
 

+ 26 - 5
libtoolkit/spinlock.c

@@ -5,11 +5,22 @@
 
 static __inline void backoff(unsigned int nloop)
 {
+	//and d, s              d <- d & s
+	//if ZF d, s 
+#ifdef _WIN32
 	__asm {
-		and ecx, nloop  ;
-		cmovz ecx, nloop ;
-		rep nop         ;
+		and ecx, nloop;
+		cmovz ecx, nloop;
+		rep nop;
 	}
+#else
+	//TODO: need to confirm its correctness.
+	__asm__ __volatile__ ("and %edi, %ecx;"
+									"cmovz %edi, %ecx;"
+									"rep;"
+									"nop");
+#endif
+
 }
 
 
@@ -120,11 +131,16 @@ TOOLKIT_API void fastlock_enter( lock_t l )
 		for (spin_count = i + 10000; i < spin_count; ++i) {
 			if (*l == 0)
 				break;
+#ifdef _WIN32
 #if _MSC_VER < 1400
 			__asm { rep nop }
 #else
-			YieldProcessor();		//关闭sphost时,调试在这里停止,且无法通过taskkill关闭sphost
+			/*TODO: the debug point locate here and cannot be kill by cmd 'taskkill' when close SpHost in debug env*/
+			YieldProcessor();
 #endif
+#else
+			__asm__ __volatile__("rep; nop");  /* a.k.a. PAUSE */
+#endif //_WIN32
 		}
 		backoffs++;
 		if (backoffs % BACKOFF_LIMIT == 0) {
@@ -143,11 +159,16 @@ int fastlock_tryenter(lock_t l)
 		for (spin_count = i + 10000; i < spin_count; ++i) {
 			if (*l == 0)
 				break;
+#ifdef _WIN32
 #if _MSC_VER < 1400
 			__asm { rep nop }
 #else
-			YieldProcessor();		//关闭sphost时,调试在这里停止,且无法通过taskkill关闭sphost
+			/*TODO: the debug point locate here and cannot be kill by cmd 'taskkill' when close SpHost in debug env*/
+			YieldProcessor();
 #endif
+#else
+			__asm__ __volatile__("rep; nop");  /* a.k.a. PAUSE */
+#endif //_WIN32
 		}
 		backoffs++;
 		if (backoffs % BACKOFF_LIMIT == 0) {

+ 3 - 1
libtoolkit/spinlock.h

@@ -39,7 +39,9 @@ static __inline void fastlock_term(lock_t l)
 	assert(l[0] == 0);
 }
 
-/* spin lock, note: reentrance!!! */
+/* spin lock, note: reentrance!!! 
+ * 11 1111 1111
+ */
 
 #define DEFAULT_SPIN_COUNT	0x3ff
 

+ 22 - 10
libtoolkit/strutil.c

@@ -7,6 +7,7 @@
 #include <malloc.h>
 
 #include "strutil.h"
+#include <winpr/wtypes.h>
 
 #pragma warning(disable : 4311)
 
@@ -374,7 +375,7 @@ TOOLKIT_API char *strright(char *dest, char *src, size_t len)
 	return strcpy(dest, src);
 }
 
-static char * __cdecl __strallocv(int stack, const char *arg1, va_list arg_list)
+static char * TOOLKIT_CC __strallocv(int stack, const char *arg1, va_list arg_list)
 {
 	size_t len;
 	const char *arg;
@@ -385,7 +386,13 @@ static char * __cdecl __strallocv(int stack, const char *arg1, va_list arg_list)
 	/* compute length of result string */
 	len = 1;
 	bad = 0;
+	//TODO: need to test its validity
+#ifdef _WIN32
+	/*gcc compile error: assignment to expression with array type*/
 	ap = arg_list;
+#else
+	va_copy(ap, arg_list);
+#endif
 	for (arg = arg1; arg != (char *)0; arg = va_arg(ap, char *)) {
 		size_t arglen = strlen(arg);
 		len += arglen;
@@ -407,7 +414,12 @@ static char * __cdecl __strallocv(int stack, const char *arg1, va_list arg_list)
 	if(ret != NULL) {
 		end = ret;
 		*end = '\0';
+#ifdef _WIN32
+		/*gcc compile error: assignment to expression with array type*/
 		ap = arg_list;
+#else
+		va_copy(ap, arg_list);
+#endif
 		for (arg = arg1; arg != (char *)0; arg = va_arg(ap, char *))
 			end = stpcpy(end, arg);
 	}
@@ -415,7 +427,7 @@ static char * __cdecl __strallocv(int stack, const char *arg1, va_list arg_list)
 	return ret;
 }
 
-TOOLKIT_API char * __cdecl stralloc(const char *arg1, ...)
+TOOLKIT_API char * TOOLKIT_CC stralloc(const char *arg1, ...)
 {
 	char *r;
 	va_list ap;
@@ -425,7 +437,7 @@ TOOLKIT_API char * __cdecl stralloc(const char *arg1, ...)
 	return r;
 }
 
-TOOLKIT_API char * __cdecl stralloca(const char *arg1, ...)
+TOOLKIT_API char * TOOLKIT_CC stralloca(const char *arg1, ...)
 {
 	char *r;
 	va_list ap;
@@ -517,7 +529,7 @@ TOOLKIT_API int strcmp0 (const char *str1,const char *str2)
 	return strcmp (str1, str2);
 }
 
-TOOLKIT_API char* __cdecl strdup_printf(const char *format, ...)
+TOOLKIT_API char* TOOLKIT_CC strdup_printf(const char *format, ...)
 {
 	char *buffer;
 	va_list args;
@@ -531,7 +543,7 @@ TOOLKIT_API char* __cdecl strdup_printf(const char *format, ...)
 
 static char *vasnprintf (char *resultbuf, size_t *lengthp, const char *format, va_list args);
 
-TOOLKIT_API char* __cdecl strdup_vprintf(const char *format, va_list args)
+TOOLKIT_API char* TOOLKIT_CC strdup_vprintf(const char *format, va_list args)
 {
 	size_t length;
 	return vasnprintf (NULL, &length, format, args);
@@ -623,7 +635,7 @@ TOOLKIT_API char* strjoinv (const char  *separator,char **str_array)
   return string;
 }
 
-TOOLKIT_API char* __cdecl strjoin (const char  *separator, ...)
+TOOLKIT_API char* TOOLKIT_CC strjoin (const char  *separator, ...)
 {
   char *string, *s;
   va_list args;
@@ -797,7 +809,7 @@ typedef struct
     long long int		a_longlongint;
     unsigned long long int	a_ulonglongint;
     __int64                     a_int64;
-    unsigned __int64            a_uint64;
+	u__int64_t            a_uint64;
     float			a_float;
     double			a_double;
     long double			a_longdouble;
@@ -1267,7 +1279,7 @@ static int printf_fetchargs (va_list args, arguments *a)
 	ap->a.a_int64 = va_arg (args, __int64);
 	break;
       case TYPE_UINT64:
-	ap->a.a_uint64 = va_arg (args, unsigned __int64);
+	ap->a.a_uint64 = va_arg (args, u__int64_t);
 	break;
       case TYPE_DOUBLE:
 	ap->a.a_double = va_arg (args, double);
@@ -1718,7 +1730,7 @@ static char *vasnprintf (char *resultbuf, size_t *lengthp, const char *format, v
 		      else
 		      if (type == TYPE_INT64 || type == TYPE_UINT64)
 			tmp_length =
-			  (unsigned int) (sizeof (unsigned __int64) * CHAR_BIT
+			  (unsigned int) (sizeof (u__int64_t) * CHAR_BIT
 					  * 0.25 /* binary -> hexadecimal */
 					  )
 			  + 1 /* turn floor into ceil */
@@ -1970,7 +1982,7 @@ static char *vasnprintf (char *resultbuf, size_t *lengthp, const char *format, v
 			break;
 		      case TYPE_UINT64:
 			{
-			  unsigned __int64 arg = a.arg[dp->arg_index].a.a_uint64;
+			  u__int64_t arg = a.arg[dp->arg_index].a.a_uint64;
 			  SNPRINTF_BUF (arg);
 			}
 			break;			

+ 5 - 5
libtoolkit/strutil.h

@@ -76,8 +76,8 @@ TOOLKIT_API char *strright(char *dest,char *src, size_t len);
 /**
  * allocate a concatenation of strings, Use (char*)0, not NULL, to end the list of parameters. 
  */
-TOOLKIT_API char * __cdecl stralloc(const char *arg1, ...);
-TOOLKIT_API char * __cdecl stralloca(const char *arg1, ...);
+TOOLKIT_API char * TOOLKIT_CC stralloc(const char *arg1, ...);
+TOOLKIT_API char * TOOLKIT_CC stralloca(const char *arg1, ...);
 
 /**
  * duplicate a memory buffer
@@ -112,8 +112,8 @@ TOOLKIT_API int strcmp0 (const char *str1,const char *str2);
 /**
  * create a string from format list
  */
-TOOLKIT_API char* __cdecl strdup_printf(const char *format, ...);
-TOOLKIT_API char* __cdecl strdup_vprintf(const char *format, va_list args);
+TOOLKIT_API char* TOOLKIT_CC strdup_printf(const char *format, ...);
+TOOLKIT_API char* TOOLKIT_CC strdup_vprintf(const char *format, va_list args);
 
 /** 
  * Copies src to dest; 
@@ -140,7 +140,7 @@ TOOLKIT_API char** strdupv (char **str_array);
  * @return a newly-allocated string containing all of the strings joined together, with separator between them. 
  */
 TOOLKIT_API char* strjoinv (const char  *separator,char **str_array);
-TOOLKIT_API char* __cdecl strjoin (const char  *separator, ...);
+TOOLKIT_API char* TOOLKIT_CC strjoin (const char  *separator, ...);
 
 /**
  * Looks whether the string str ends with suffix.

+ 5 - 0
libtoolkit/threadpool.c

@@ -4,6 +4,11 @@
 #include "spinlock.h"
 #include "refcnt.h"
 #include "modCheck.h"
+#include <winpr/synch.h>
+#include <winpr/thread.h>
+#ifndef _WIN32
+#include <errno.h> /*for errno compactility*/
+#endif
 
 struct strand_task_entry {
 	struct list_head entry;

+ 1 - 1
libtoolkit/url.c

@@ -1,5 +1,5 @@
 #include "precompile.h"
-#include "Url.h"
+#include "url.h"
 
 #include <stdlib.h>
 #include <string.h>

+ 1 - 0
libtoolkit/waitresult.c

@@ -3,6 +3,7 @@
 #include "refcnt.h"
 
 #include <stdlib.h>
+#include <winpr/synch.h>
 
 struct waitresult_t
 {

+ 1 - 0
libtoolkit/waitresult.h

@@ -4,6 +4,7 @@
 #pragma once
 
 #include "config.h"
+#include <winpr/wtypes.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 3 - 0
libtoolkit/wavfile.c

@@ -1,5 +1,8 @@
 #include "precompile.h"
+#ifdef _WIN32
+/*this header is used by windows multi-media*/
 #include <mmreg.h>
+#endif 
 #include "wavfile.h"
 #include "memutil.h"
 

+ 6 - 0
libtoolkit/wavfile.h

@@ -1,3 +1,9 @@
+/*
+ * Description: to text.
+ * TODO: media component, which need to be strip.
+ *
+ */
+
 #ifndef __WAVFILE_H__
 #define __WAVFILE_H__
 

+ 32 - 3
libtoolkit/y2k_time.c

@@ -1,29 +1,50 @@
 #include "precompile.h"
 #include "y2k_time.h"
+#ifndef _WIN32
+#include <time.h>
+#endif
 
 #define __reference_point 946656000LL // _mktime64 2000-01-01 00:00:00
 
 TOOLKIT_API y2k_time_t y2k_time_now()
 {
+#ifdef _WIN32
 	__time64_t now;
 	struct tm t;
 	_time64(&now);
 	_localtime64_s(&t, &now);
 	return (y2k_time_t)(now - __reference_point);
+#else
+	time_t now;
+	struct tm t;
+	time(&now);
+	localtime_r(&now, &t);
+	return (y2k_time_t)(now - __reference_point);
+#endif //_WIN32
 }
 
-TOOLKIT_API int y2k_time_is_today(y2k_time_t time)
+TOOLKIT_API int y2k_time_is_today(y2k_time_t time_value)
 {
+#ifdef _WIN32
 	__time64_t now;
 	struct tm tm1;
 	struct tm tm2;
-	
+
 	_time64(&now);
 	memset(&tm1, 0, sizeof(tm1));
 	_localtime64_s(&tm1, &now);
+#else
+	time_t now;
+	struct tm tm1;
+	struct tm tm2;
+
+	time(&now);
+	memset(&tm1, 0, sizeof(tm1));
+	localtime_r(&now, &tm1);
+#endif //_WIN32
 
 	memset(&tm2, 0, sizeof(tm2));
-	y2k_to_localtime_tm(time, &tm2);
+	y2k_to_localtime_tm(time_value, &tm2);
 
 	return tm1.tm_year == tm2.tm_year && tm1.tm_mon == tm2.tm_mon && tm1.tm_mday == tm2.tm_mday;
 }
@@ -61,13 +82,21 @@ TOOLKIT_API y2k_time_t y2k_from_ymdhms(int year, int month, int day, int hour, i
 	tm.tm_hour = hour;
 	tm.tm_min = second;
 	tm.tm_sec = second;
+#ifdef _WIN32
 	return (unsigned int)(_mktime64(&tm) - __reference_point);
+#else
+	return (unsigned int)(mktime(&tm) - __reference_point);
+#endif
 }
 
 TOOLKIT_API int y2k_to_localtime_tm(y2k_time_t t, struct tm *tm)
 {
 	__time64_t tt = __reference_point + (unsigned int)t;
+#ifdef _WIN32
 	_localtime64_s(tm, &tt);
+#else
+	localtime_r(&tt, tm);
+#endif
 	return 0;
 }
 

+ 1 - 0
libtoolkit/y2k_time.h

@@ -4,6 +4,7 @@
 #pragma once
 
 #include "config.h"
+#include <winpr/wtypes.h>
 
 #ifdef __cplusplus
 extern "C" {

+ 8 - 0
winpr/include/winpr/locale.h

@@ -479,6 +479,14 @@
 
 #define LOCALE_INVARIANT (MAKELCID(MAKELANGID(LANG_INVARIANT, SUBLANG_NEUTRAL), SORT_DEFAULT))
 
+#define FORMAT_MESSAGE_ALLOCATE_BUFFER 0x00000100
+#define FORMAT_MESSAGE_IGNORE_INSERTS  0x00000200
+#define FORMAT_MESSAGE_FROM_STRING     0x00000400
+#define FORMAT_MESSAGE_FROM_HMODULE    0x00000800
+#define FORMAT_MESSAGE_FROM_SYSTEM     0x00001000
+#define FORMAT_MESSAGE_ARGUMENT_ARRAY  0x00002000
+#define FORMAT_MESSAGE_MAX_WIDTH_MASK  0x000000FF
+
 #ifdef __cplusplus
 extern "C"
 {

+ 6 - 0
winpr/include/winpr/wtypes.h.in

@@ -139,6 +139,8 @@ typedef unsigned long long      __uint64;
 #if defined(__ILP64__) || defined(__LP64__)
 #define __int3264 int64_t
 #define __uint3264 uint64_t
+/*for linux compatibility. linux is unable to recognize __int64*/
+#define u__int64_t uint64_t
 #else
 #define __int3264 int32_t
 #define __uint3264 uint32_t
@@ -153,6 +155,10 @@ typedef unsigned long long      __uint64;
 #endif
 #endif /* WINPR_HAVE_STDINT_H */
 
+#ifndef _TIME64_T_DEFINED
+typedef __int64 __time64_t;     /* 64-bit time value Gifur@200228 */
+#define _TIME64_T_DEFINED
+#endif
 
 typedef void* PVOID, *LPVOID, *PVOID64, *LPVOID64;