[Pkg-voip-commits] [bctoolbox] 14/60: Fix build on Windows + Respect bctoolbox conventions for type names.

Bernhard Schmidt berni at moszumanska.debian.org
Sun Oct 15 22:42:23 UTC 2017


This is an automated email from the git hooks/post-receive script.

berni pushed a commit to branch debian/sid
in repository bctoolbox.

commit c5d46b6901fced278774e138d90d243bcf832e83
Author: Ghislain MARY <ghislain.mary at belledonne-communications.com>
Date:   Fri Mar 31 17:04:19 2017 +0200

    Fix build on Windows + Respect bctoolbox conventions for type names.
---
 include/bctoolbox/logging.h | 30 ++++++++---------
 src/logging/logging.c       | 79 +++++++++++++++++++++++++--------------------
 tester/bctoolbox_tester.c   | 13 ++++----
 tester/port.c               | 19 +++++------
 4 files changed, 75 insertions(+), 66 deletions(-)

diff --git a/include/bctoolbox/logging.h b/include/bctoolbox/logging.h
index dcf8380..63a9332 100644
--- a/include/bctoolbox/logging.h
+++ b/include/bctoolbox/logging.h
@@ -48,11 +48,11 @@ typedef enum {
 	BCTBX_LOG_LOGLEV_END=1<<6
 } BctbxLogLevel;
 
-typedef struct _BctoolboxLogHandler BctoolboxLogHandler;
+typedef struct _bctbx_log_handler_t bctbx_log_handler_t;
 
-typedef void (*BctoolboxLogFunc)(const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
-typedef void (*BctoolboxLogHandlerFunc)(void *info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
-typedef void (*BctoolboxLogHandlerDestroyFunc)(BctoolboxLogHandler* handler);
+typedef void (*BctbxLogFunc)(const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
+typedef void (*BctbxLogHandlerFunc)(void *info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args);
+typedef void (*BctbxLogHandlerDestroyFunc)(bctbx_log_handler_t *handler);
 
 /*
  initialise logging functions, add default log handler for stdout output.
@@ -65,19 +65,19 @@ BCTBX_PUBLIC void bctbx_uninit_logger(void);
 
 /* 
  Default functions to free log handlers
- @param[in] BctoolboxLogHandler* handler : the handler to free
+ @param[in] bctbx_log_handler_t* handler : the handler to free
 */
-BCTBX_PUBLIC void bctbx_logv_out_destroy(BctoolboxLogHandler* handler);
-BCTBX_PUBLIC void bctbx_logv_file_destroy(BctoolboxLogHandler* handler);
+BCTBX_PUBLIC void bctbx_logv_out_destroy(bctbx_log_handler_t *handler);
+BCTBX_PUBLIC void bctbx_logv_file_destroy(bctbx_log_handler_t *handler);
 
 /* 
  Function to create a log handler
- @param[in] BctoolboxLogHandlerFunc func : the function to call to handle a new line of log
- @param[in] BctoolboxLogHandlerDestroyFunc destroy : the function to call to free this handler particuler its user_info field
+ @param[in] BctbxLogHandlerFunc func : the function to call to handle a new line of log
+ @param[in] BctbxLogHandlerDestroyFunc destroy : the function to call to free this handler particuler its user_info field
  @param[in] void* user_info : complementary information to handle the logs if needed
- @return a new BctoolboxLogHandler
+ @return a new bctbx_log_handler_t
 */
-BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFunc func, BctoolboxLogHandlerDestroyFunc destroy, void* user_info);
+BCTBX_PUBLIC bctbx_log_handler_t* bctbx_create_log_handler(BctbxLogHandlerFunc func, BctbxLogHandlerDestroyFunc destroy, void* user_info);
 
 /* 
  Function to create a file log handler
@@ -85,12 +85,12 @@ BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFu
  @param[in] const char* path : the path where to put the log files
  @param[in] const char* name : the name of the log files
  @param[in] FILE* f : the file where to write the logs
- @return a new BctoolboxLogHandler
+ @return a new bctbx_log_handler_t
 */
-BCTBX_PUBLIC BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f);
+BCTBX_PUBLIC bctbx_log_handler_t* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f);
 
-BCTBX_PUBLIC void bctbx_add_log_handler(BctoolboxLogHandler* handler);
-BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_handler(BctoolboxLogFunc func);
+BCTBX_PUBLIC void bctbx_add_log_handler(bctbx_log_handler_t* handler);
+BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_handler(BctbxLogFunc func);
 BCTBX_PUBLIC BCTBX_DEPRECATED void bctbx_set_log_file(FILE* f);
 BCTBX_PUBLIC bctbx_list_t* bctbx_get_log_handlers(void);
 
diff --git a/src/logging/logging.c b/src/logging/logging.c
index 6de30e8..4fdfbfb 100644
--- a/src/logging/logging.c
+++ b/src/logging/logging.c
@@ -28,6 +28,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 #include <sys/stat.h>
 #include <sys/types.h>
 
+#ifdef _MSC_VER
+#ifndef access
+#define access _access
+#endif
+#ifndef fileno
+#define fileno _fileno
+#endif
+#endif
+
 
 typedef struct{
 	char *domain;
@@ -39,7 +48,7 @@ static void bctbx_log_domain_destroy(BctoolboxLogDomain *obj){
 	bctbx_free(obj);
 }
 
-typedef struct _BctoolboxLogger{
+typedef struct _bctbx_logger_t {
 	bctbx_list_t *logv_outs;
 	unsigned int log_mask; /*the default log mask, if no per-domain settings are found*/
 	unsigned long log_thread_id;
@@ -47,27 +56,27 @@ typedef struct _BctoolboxLogger{
 	bctbx_list_t *log_domains;
 	bctbx_mutex_t log_stored_messages_mutex;
 	bctbx_mutex_t domains_mutex;
-}BctoolboxLogger;
+} bctbx_logger_t;
 
-struct _BctoolboxLogHandler{
-	BctoolboxLogHandlerFunc func;
-	BctoolboxLogHandlerDestroyFunc destroy;
+struct _bctbx_log_handler_t {
+	BctbxLogHandlerFunc func;
+	BctbxLogHandlerDestroyFunc destroy;
 	void* user_info;
 };
 
-typedef struct _BctoolboxFileLogHandler{
+typedef struct _bctbx_file_log_handler_t {
 	char* path;
 	char* name;
 	uint64_t max_size;
 	uint64_t size;
 	FILE* file;
-}BctoolboxFileLogHandler;
+} bctbx_file_log_handler_t;
 
-static BctoolboxLogger __bctbx_logger = { NULL, BCTBX_LOG_WARNING|BCTBX_LOG_ERROR|BCTBX_LOG_FATAL, 0};
+static bctbx_logger_t __bctbx_logger = { NULL, BCTBX_LOG_WARNING|BCTBX_LOG_ERROR|BCTBX_LOG_FATAL, 0};
 
 static unsigned int bctbx_init_logger_refcount = 0;
 void bctbx_init_logger(void){
-	BctoolboxLogHandler* handler;
+	bctbx_log_handler_t* handler;
 	if (bctbx_init_logger_refcount++ > 0) return; /*already initialized*/
 	
 	bctbx_mutex_init(&__bctbx_logger.domains_mutex, NULL);
@@ -78,7 +87,7 @@ void bctbx_init_logger(void){
 void bctbx_log_handlers_free(void) {
 	bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
 	while (loggers) {
-		BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
+		bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
 		handler->destroy(handler);
 		loggers = loggers->next;
 	}
@@ -94,17 +103,17 @@ void bctbx_uninit_logger(void){
 	}
 }
 
-BctoolboxLogHandler* bctbx_create_log_handler(BctoolboxLogHandlerFunc func, BctoolboxLogHandlerDestroyFunc destroy, void* user_info) {
-	BctoolboxLogHandler* handler = (BctoolboxLogHandler*)bctbx_malloc(sizeof(BctoolboxLogHandler));
+bctbx_log_handler_t* bctbx_create_log_handler(BctbxLogHandlerFunc func, BctbxLogHandlerDestroyFunc destroy, void* user_info) {
+	bctbx_log_handler_t* handler = (bctbx_log_handler_t*)bctbx_malloc(sizeof(bctbx_log_handler_t));
 	handler->func = func;
 	handler->destroy = destroy;
 	handler->user_info = user_info;
 	return handler;
 }
 
-BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f) {
-	BctoolboxLogHandler* handler = (BctoolboxLogHandler*)bctbx_malloc0(sizeof(BctoolboxLogHandler));
-	BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler*)bctbx_malloc(sizeof(BctoolboxFileLogHandler));
+bctbx_log_handler_t* bctbx_create_file_log_handler(uint64_t max_size, const char* path, const char* name, FILE* f) {
+	bctbx_log_handler_t* handler = (bctbx_log_handler_t*)bctbx_malloc0(sizeof(bctbx_log_handler_t));
+	bctbx_file_log_handler_t* filehandler = (bctbx_file_log_handler_t*)bctbx_malloc(sizeof(bctbx_file_log_handler_t));
 	handler->func=bctbx_logv_file;
 	handler->destroy=bctbx_logv_file_destroy;
 	filehandler->max_size = max_size;
@@ -122,30 +131,30 @@ BctoolboxLogHandler* bctbx_create_file_log_handler(uint64_t max_size, const char
 *@param func: your logging function, compatible with the BctoolboxLogFunc prototype.
 *
 **/
-void bctbx_add_log_handler(BctoolboxLogHandler* handler){
+void bctbx_add_log_handler(bctbx_log_handler_t* handler){
 	if (!bctbx_list_find(__bctbx_logger.logv_outs, handler))
 		__bctbx_logger.logv_outs = bctbx_list_append(__bctbx_logger.logv_outs, (void*)handler);
 	/*else, already in*/
 }
 
 static void wrapper(void* info,const char *domain, BctbxLogLevel lev, const char *fmt, va_list args) {
-	BctoolboxLogFunc func = (BctoolboxLogFunc)info;
+	BctbxLogFunc func = (BctbxLogFunc)info;
 	func(domain, lev, fmt,  args);
 }
 
-void bctbx_set_log_handler(BctoolboxLogFunc func){
-	static BctoolboxLogHandler handler;
+void bctbx_set_log_handler(BctbxLogFunc func){
+	static bctbx_log_handler_t handler;
 	handler.func=wrapper;
-	handler.destroy=(BctoolboxLogHandlerDestroyFunc)bctbx_logv_out_destroy;
+	handler.destroy=(BctbxLogHandlerDestroyFunc)bctbx_logv_out_destroy;
 	handler.user_info=(void*)func;
 	bctbx_add_log_handler(&handler);
 }
 
 void bctbx_set_log_file(FILE* f){
-	static BctoolboxFileLogHandler filehandler;
-	static BctoolboxLogHandler handler;
+	static bctbx_file_log_handler_t filehandler;
+	static bctbx_log_handler_t handler;
 	handler.func=bctbx_logv_file;
-	handler.destroy=(BctoolboxLogHandlerDestroyFunc)bctbx_logv_file_destroy;
+	handler.destroy=(BctbxLogHandlerDestroyFunc)bctbx_logv_file_destroy;
 	filehandler.max_size = -1;
 	filehandler.file = f;
 	handler.user_info=(void*) &filehandler;
@@ -338,7 +347,7 @@ void _bctbx_logv_flush(int dummy, ...) {
 		bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
 #ifdef _WIN32
 		while (loggers) {
-			BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
+			bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
 			va_list cap;
 			va_copy(cap, empty_va_list);
 			handler->func(handler->user_info, l->domain, l->level, l->msg, cap);
@@ -348,7 +357,7 @@ void _bctbx_logv_flush(int dummy, ...) {
 #else
 		
 		while (loggers) {
-			BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
+			bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
 			va_list cap;
 			va_copy(cap, empty_va_list);
 			handler->func(handler->user_info, l->domain, l->level, l->msg, cap);
@@ -374,7 +383,7 @@ void bctbx_logv(const char *domain, BctbxLogLevel level, const char *fmt, va_lis
 		if (__bctbx_logger.log_thread_id == 0) {
 			bctbx_list_t *loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
 			while (loggers) {
-				BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
+				bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
 				va_list tmp;
 				va_copy(tmp, args);
 				handler->func(handler->user_info, domain, level, fmt, tmp);
@@ -386,7 +395,7 @@ void bctbx_logv(const char *domain, BctbxLogLevel level, const char *fmt, va_lis
 			bctbx_logv_flush();
 			loggers = bctbx_list_first_elem(__bctbx_logger.logv_outs);
 			while (loggers) {
-				BctoolboxLogHandler* handler = (BctoolboxLogHandler*)loggers->data;
+				bctbx_log_handler_t* handler = (bctbx_log_handler_t*)loggers->data;
 				va_list tmp;
 				va_copy(tmp, args);
 				handler->func(handler->user_info, domain, level, fmt, tmp);
@@ -476,11 +485,11 @@ void bctbx_logv_out(void* user_info, const char *domain, BctbxLogLevel lev, cons
 	bctbx_free(msg);
 }
 
-void bctbx_logv_out_destroy(BctoolboxLogHandler* handler) {
+void bctbx_logv_out_destroy(bctbx_log_handler_t* handler) {
 	handler->user_info=NULL;
 }
 
-static int _try_open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
+static int _try_open_log_collection_file(bctbx_file_log_handler_t *filehandler) {
 	struct stat statbuf;
 	char *log_filename;
 
@@ -501,7 +510,7 @@ static int _try_open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
 	return 0;
 }
 
-static void _rotate_log_collection_files(BctoolboxFileLogHandler* filehandler) {
+static void _rotate_log_collection_files(bctbx_file_log_handler_t *filehandler) {
 	char *log_filename;
 	char *log_filename2;
 	int n = 1;
@@ -543,14 +552,14 @@ static void _rotate_log_collection_files(BctoolboxFileLogHandler* filehandler) {
 	bctbx_free(log_filename2);
 }
 
-static void _open_log_collection_file(BctoolboxFileLogHandler* filehandler) {
+static void _open_log_collection_file(bctbx_file_log_handler_t *filehandler) {
 	if (_try_open_log_collection_file(filehandler) < 0) {
 		_rotate_log_collection_files(filehandler);
 		_try_open_log_collection_file(filehandler);
 	}
 }
 
-static void _close_log_collection_file(BctoolboxFileLogHandler* filehandler) {
+static void _close_log_collection_file(bctbx_file_log_handler_t *filehandler) {
 	if (filehandler->file) {
 		fclose(filehandler->file);
 		filehandler->file = NULL;
@@ -568,7 +577,7 @@ void bctbx_logv_file(void* user_info, const char *domain, BctbxLogLevel lev, con
 #endif
 	time_t tt;
 	int ret = -1;
-	BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler *) user_info;
+	bctbx_file_log_handler_t *filehandler = (bctbx_file_log_handler_t *) user_info;
 	FILE *f = filehandler->file;
 	bctbx_gettimeofday(&tp,NULL);
 	tt = (time_t)tp.tv_sec;
@@ -633,8 +642,8 @@ void bctbx_logv_file(void* user_info, const char *domain, BctbxLogLevel lev, con
 	bctbx_free(msg);
 }
 
-void bctbx_logv_file_destroy(BctoolboxLogHandler* handler) {
-	BctoolboxFileLogHandler* filehandler = (BctoolboxFileLogHandler *) handler->user_info;
+void bctbx_logv_file_destroy(bctbx_log_handler_t* handler) {
+	bctbx_file_log_handler_t *filehandler = (bctbx_file_log_handler_t *) handler->user_info;
 	fclose(filehandler->file);
 	bctbx_free(filehandler->path);
 	bctbx_free(filehandler->name);
diff --git a/tester/bctoolbox_tester.c b/tester/bctoolbox_tester.c
index 93a8609..61cb52f 100644
--- a/tester/bctoolbox_tester.c
+++ b/tester/bctoolbox_tester.c
@@ -20,7 +20,6 @@
 #endif
 #include "bctoolbox/logging.h"
 #include "bctoolbox_tester.h"
-#include <libgen.h>
 
 static FILE * log_file = NULL;
 static const char *log_domain = "bctoolbox-tester";
@@ -57,7 +56,7 @@ void bctoolbox_tester_before_each() {
 }
 
 int bctoolbox_tester_set_log_file(const char *filename) {
-	BctoolboxLogHandler* filehandler;
+	bctbx_log_handler_t* filehandler;
 	char* dir;
 	char* base;
 	if (log_file) {
@@ -68,13 +67,13 @@ int bctoolbox_tester_set_log_file(const char *filename) {
 		bctbx_error("Cannot open file [%s] for writing logs because [%s]", filename, strerror(errno));
 		return -1;
 	}
-	dir = bctbx_strdup(filename);
-	base = bctbx_strdup(filename);
+	dir = bctbx_dirname(filename);
+	base = bctbx_basename(filename);
 	bctbx_message("Redirecting traces to file [%s]", filename);
-	filehandler = bctbx_create_file_log_handler(0, dirname(dir), basename(base), log_file);
+	filehandler = bctbx_create_file_log_handler(0, dir, base, log_file);
 	bctbx_add_log_handler(filehandler);
-	bctbx_free(dir);
-	bctbx_free(base);
+	if (dir) bctbx_free(dir);
+	if (base) bctbx_free(base);
 	return 0;
 }
 
diff --git a/tester/port.c b/tester/port.c
index 2904772..e99bb6b 100644
--- a/tester/port.c
+++ b/tester/port.c
@@ -18,6 +18,7 @@
 */
 
 #include <stdio.h>
+#include <inttypes.h>
 #include "bctoolbox_tester.h"
 #include "bctoolbox/port.h"
 
@@ -77,9 +78,9 @@ static void bytesToFromHexaStrings(void) {
 	bctbx_uint64ToStr(outputString, 0xfedcba9876543210);
 	BC_ASSERT_NSTRING_EQUAL(outputString, "fedcba9876543210", 16);
 
-	BC_ASSERT_EQUAL(bctbx_strToUint64("fa5c37643cde8de0"), 0xfa5c37643cde8de0, uint64_t, "0x%016lx");
-	BC_ASSERT_EQUAL(bctbx_strToUint64("0123456789abcdef"), 0x0123456789abcdef, uint64_t, "0x%016lx");
-	BC_ASSERT_EQUAL(bctbx_strToUint64("fedcba9876543210"), 0xfedcba9876543210, uint64_t, "0x%016lx");
+	BC_ASSERT_EQUAL(bctbx_strToUint64("fa5c37643cde8de0"), 0xfa5c37643cde8de0, uint64_t, "0x%" PRIx64);
+	BC_ASSERT_EQUAL(bctbx_strToUint64("0123456789abcdef"), 0x0123456789abcdef, uint64_t, "0x%" PRIx64);
+	BC_ASSERT_EQUAL(bctbx_strToUint64("fedcba9876543210"), 0xfedcba9876543210, uint64_t, "0x%" PRIx64);
 }
 
 static void timeFunctions(void) {
@@ -93,20 +94,20 @@ static void timeFunctions(void) {
 	memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
 	BC_ASSERT_EQUAL(bctbx_timespec_compare(&y2k, &testTs), 0, int, "%d");
 	bctbx_timespec_add(&testTs, 604800);
-	BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec+604800, int64_t, "%ld");
-	BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%ld");
+	BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec+604800, int64_t, "%" PRIi64);
+	BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%" PRIi64);
 	BC_ASSERT_TRUE(bctbx_timespec_compare(&y2k, &testTs)<0);
 
 	memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
 	bctbx_timespec_add(&testTs, -604800);
-	BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec-604800, int64_t, "%ld");
-	BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%ld");
+	BC_ASSERT_EQUAL(testTs.tv_sec, y2k.tv_sec-604800, int64_t, "%" PRIi64);
+	BC_ASSERT_EQUAL(testTs.tv_nsec, y2k.tv_nsec, int64_t, "%" PRIi64);
 	BC_ASSERT_TRUE(bctbx_timespec_compare(&y2k, &testTs)>0);
 
 	memcpy(&testTs, &y2k, sizeof(bctoolboxTimeSpec));
 	bctbx_timespec_add(&testTs, -946684801);
-	BC_ASSERT_EQUAL(testTs.tv_sec, 0, int64_t, "%ld");
-	BC_ASSERT_EQUAL(testTs.tv_nsec, 0, int64_t, "%ld");
+	BC_ASSERT_EQUAL(testTs.tv_sec, 0, int64_t, "%" PRIi64);
+	BC_ASSERT_EQUAL(testTs.tv_nsec, 0, int64_t, "%" PRIi64);
 
 	/* test the get utc time function
 	 * there is no easy way to ensure we get the correct time, just check it is at least not the time from last boot,

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-voip/bctoolbox.git



More information about the Pkg-voip-commits mailing list