Browse Source

T20M5021 #comment 移除框架中自带的stdint.h,该文件是用于兼容vs2010以前的编译器

gifur 5 years ago
parent
commit
cf2738c207

+ 5 - 1
libtoolkit/CMakeLists.txt

@@ -18,7 +18,11 @@ list(REMOVE_ITEM ${MODULE_PREFIX}_SRCS
     cputime.h 
     cputime.c
     iatpatch.h
-    iatpatch.c)
+    iatpatch.c
+    iconv.c
+    iconv.h
+    ioreactor.c
+    ioreactor.h)
 if(NOT WIN32)
 list(REMOVE_ITEM ${MODULE_PREFIX}_SRCS 
     gettimeofday.c)

+ 1 - 0
libtoolkit/fileutil.h

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

+ 22 - 12
libtoolkit/ioqueue.c

@@ -6,7 +6,13 @@
 #include "strutil.h"
 #include "sockutil.h"
 
+#ifdef _WIN32
 #include <MSWSock.h>
+#endif //_WIN32
+#include <winpr/file.h>
+#include <winpr/handle.h>
+#include <winpr/synch.h>
+#include <winpr/pipe.h>
 
 #ifndef SO_UPDATE_CONNECT_CONTEXT
 #define SO_UPDATE_CONNECT_CONTEXT 0x7010
@@ -54,25 +60,25 @@ typedef struct ioqueue_msg {
 	HANDLE evt; /* for send message */
 }ioqueue_msg;
 
-#define HANDLE_TYPE_ACCEPTOR		0x01
-#define HANDLE_TYPE_TCPSOCK			0x02
+#define HANDLE_TYPE_ACCEPTOR		    0x01
+#define HANDLE_TYPE_TCPSOCK			    0x02
 #define HANDLE_TYPE_UDPSOCK			0x03
-#define HANDLE_TYPE_FILE			0x04
+#define HANDLE_TYPE_FILE			            0x04
 #define HANDLE_TYPE_PIPEACCEPTOR	0x05
 
-#define OV_ACCEPT			0x01
-#define OV_CONNECT			0x02
+#define OV_ACCEPT			        0x01
+#define OV_CONNECT			    0x02
 #define OV_SENDSOME			0x03
-#define OV_SENDN			0x04
+#define OV_SENDN			        0x04
 #define OV_RECVSOME			0x05
-#define OV_RECVN			0x06
-#define OV_SENDTO			0x07
+#define OV_RECVN			        0x06
+#define OV_SENDTO			    0x07
 #define OV_RECVFROM			0x08
 #define OV_READFILESOME		0x09
 #define OV_WRITEFILESOME	0x0a
-#define OV_READFILEN		0x0b
-#define OV_WRITEFILEN		0x0c
-#define OV_RECVUNTIL		0x0d
+#define OV_READFILEN		    0x0b
+#define OV_WRITEFILEN		    0x0c
+#define OV_RECVUNTIL		    0x0d
 #define OV_CONNECTPIPE		0x0e
 
 typedef struct ioqueue_base_overlapped_t {
@@ -209,6 +215,7 @@ static int nonblock_sock(SOCKET sock)
 static int is_os_gte_xp() /* is os version greater and equal than xp */
 {
 	static int yes = -1;
+#ifdef _WIN32
 	if (yes == -1) {
 		OSVERSIONINFO ver;
 		ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
@@ -217,6 +224,7 @@ static int is_os_gte_xp() /* is os version greater and equal than xp */
 			yes = 1;
 		}
 	}
+#endif//_WIN32
 	return yes;
 }
 
@@ -249,7 +257,9 @@ static __inline void del_handler_list(ioqueue_handle_context *handle_ctx, ioqueu
 
 static void ioqueue_handle_context_free(ioqueue_handle_context *handle_ctx)
 {
-	if (handle_ctx->type == HANDLE_TYPE_UDPSOCK || handle_ctx->type == HANDLE_TYPE_TCPSOCK || handle_ctx->type == HANDLE_TYPE_ACCEPTOR) {
+	if (handle_ctx->type == HANDLE_TYPE_UDPSOCK 
+		|| handle_ctx->type == HANDLE_TYPE_TCPSOCK 
+		|| handle_ctx->type == HANDLE_TYPE_ACCEPTOR) {
 		if (handle_ctx->u.sock != INVALID_SOCKET) {
 			closesocket(handle_ctx->u.sock);
 			handle_ctx->u.sock = INVALID_SOCKET;

+ 6 - 3
libtoolkit/log.c

@@ -115,8 +115,8 @@ TOOLKIT_API int xlog_init2(const char *file, const char *sections)
 			p = strtok(NULL, delimers);
 		}
 	}
-
-	logmgr_create(&((logmgr_t *)(toolkit_getResource()->g_mgr)));
+	logmgr_t* log_mgr = (logmgr_t*)(toolkit_getResource()->g_mgr);
+	logmgr_create(&log_mgr);
 	singlefilefactory_create(&fac);
 	logmgr_register_factory((logmgr_t *)(toolkit_getResource()->g_mgr), fac);
 	periodicfilefactory_create(&fac);
@@ -188,8 +188,11 @@ TOOLKIT_API int xlog_init2(const char *file, const char *sections)
 	if (arr_section)
 		array_free(arr_section);
 	if (rc < 0) {
+		//TODO: to confirm the correctness
+		logmgr_t* log_mgr = (logmgr_t*)(toolkit_getResource()->g_mgr);
+		logmgr_t** p_log_mgr = &log_mgr;
 		logmgr_destroy((logmgr_t *)(toolkit_getResource()->g_mgr));
-		(logmgr_t *)(toolkit_getResource()->g_mgr) = NULL;
+		*p_log_mgr = NULL;
 	}
 
 	return rc;

+ 1 - 0
libtoolkit/log_udpclient.c

@@ -5,6 +5,7 @@
 #include "log_base.h"
 #include "log.h"
 #include "spinlock.h"
+#include <winpr/winsock.h>
 
 typedef struct udplogfactory_t udplogfactory_t;
 

+ 2 - 0
libtoolkit/log_udpdaemon.c

@@ -4,6 +4,8 @@
 #include "log_hdr.h"
 #include "log_base.h"
 #include "log.h"
+#include <winpr/winsock.h>
+#include <winpr/synch.h>
 
 typedef struct udplogdaemonfactory_t udplogdaemonfactory_t;
 

+ 1 - 1
libtoolkit/md5.c

@@ -1,5 +1,5 @@
 #include "precompile.h"
-#include "stdint.h"
+//#include "stdint.h"
 #include "md5.h"
 
 

+ 1 - 1
libtoolkit/md5.h

@@ -10,7 +10,7 @@ extern "C" {
 #endif
 
 #include <stdlib.h>
-#include "stdint.h"
+#include <stdint.h>
 
 #define MD5_DIGESTSIZE 16
 

+ 5 - 0
libtoolkit/stdint.h → libtoolkit/stdint_compact.h

@@ -19,6 +19,9 @@
 
 #ifndef _STDINT_H
 #define _STDINT_H
+
+#ifdef _WIN32
+
 #define __need_wint_t
 #define __need_wchar_t
 #include <stddef.h>
@@ -185,4 +188,6 @@ typedef unsigned __int64   uintmax_t;
 
 #endif  /* !defined ( __cplusplus) || defined __STDC_CONSTANT_MACROS */
 
+#endif //_WIN32
+
 #endif

+ 3 - 0
libtoolkit/strutil.c

@@ -479,6 +479,7 @@ TOOLKIT_API char *strdupa(const char * s)
 	return p;
 }
 
+#ifdef _WIN32
 
 TOOLKIT_API char *strndup(const char *str, int n)
 {
@@ -494,6 +495,8 @@ TOOLKIT_API char *strndup(const char *str, int n)
 	return new_str;
 }
 
+#endif //_WIN32
+
 TOOLKIT_API char* strnfill(int length, int fill_char)
 {
 	char *str;

+ 6 - 0
libtoolkit/strutil.h

@@ -87,11 +87,17 @@ TOOLKIT_API void *memdupa(const void *buf, int len);
 
 TOOLKIT_API char *strdupa(const char *str);
 
+
+#ifdef _WIN32
+
 /**
  * Duplicates the first @n bytes of a string, returning a newly-allocated
+ * conflict with /usr/include/string.h
  */
 TOOLKIT_API char *strndup(const char *str, int n);
 
+#endif //_WIN32
+
 /**
  * Creates a new string @length bytes long filled with @fill_char.
  * Creates a new string @length bytes long filled with @fill_char.

+ 1 - 1
libtoolkit/wavfile.h

@@ -9,7 +9,7 @@
 extern "C" {
 #endif
 
-#include "stdint.h"
+#include <stdint.h>
 
 typedef struct wavfile_t wavfile_t;