diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | hugin.c | 20 | ||||
-rw-r--r-- | hugin.h | 6 | ||||
-rw-r--r-- | main_complete.c | 15 | ||||
-rw-r--r-- | main_simple.c | 19 |
5 files changed, 38 insertions, 24 deletions
@@ -6,5 +6,7 @@ hugin-mutex hugin-obj hugin-simple hugin-syslog +hugin-complete-disabled +hugin-simple-disabled hugin.o main_simple.o @@ -46,10 +46,6 @@ # ifdef WIN32 # include <windows.h> typedef HANDLE mutex_t; - -// see http://stackoverflow.com/questions/558223/va-copy-porting-to-visual-c -//#define va_copy(dest, src) (dest = src) - # else # include <pthread.h> typedef pthread_mutex_t mutex_t; @@ -385,9 +381,9 @@ static int scprintf(const char *fmt, ...) #define HDR_ARGS debug_class_str[(unsigned)cl], ch, func, line -int __debug(const char *func, const int line, - const enum __debug_class cl, - const char *ch, const char *fmt, ...) +int __hugin__debug(const char *func, const int line, + const enum __debug_class cl, + const char *ch, const char *fmt, ...) { int result = 0; int sz; @@ -409,13 +405,13 @@ int __debug(const char *func, const int line, // // Generate message // - va_list va; - va_start(va, fmt); { + va_list va; + va_start(va, fmt); hdr_bufsz = scprintf(hdr_fmt, HDR_ARGS); msg_bufsz = vscprintf(fmt, va); if(hdr_bufsz < 0 || msg_bufsz < 0) return 1; // Bad format? - // va_end(va); + va_end(va); } buf = (char*)malloc(hdr_bufsz + msg_bufsz + 1); @@ -425,8 +421,8 @@ int __debug(const char *func, const int line, if(sz < 0) return 1; // Unknown error { - //va_list va; - //va_start(va, fmt); + va_list va; + va_start(va, fmt); sz = vsprintf(buf + sz, fmt, va); if(sz < 0) return 1; // Unknown error va_end(va); @@ -179,12 +179,12 @@ enum __debug_class __class_debug = 4 }; -int __debug(const char *func, const int line, enum __debug_class cl, - const char *ch, const char *fmt, ...) +int __hugin__debug(const char *func, const int line, enum __debug_class cl, + const char *ch, const char *fmt, ...) __attribute__((format (printf,5,6))); #define __DEBUG_PRINT(cl, ch, fmt...) \ - do { __debug(__func__, __LINE__, cl, ch, fmt); } while(0) + do { __hugin__debug(__func__, __LINE__, cl, ch, fmt); } while(0) #define __DEBUG(cl, ch, fmt...) \ __DEBUG_PRINT(__class##cl, #ch, fmt) diff --git a/main_complete.c b/main_complete.c index a79dbc5..8eb4b7e 100644 --- a/main_complete.c +++ b/main_complete.c @@ -30,13 +30,17 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> - +#include <errno.h> #include <stdio.h> +#include <string.h> +#include <unistd.h> int main(int argc, char *argv[]) { - int fd = open("/tmp/my.log", O_CREAT | O_RDWR, 0777); + const char *mylog = "/tmp/my.log"; + int fd = open(mylog, O_CREAT | O_RDWR, 0777); if(fd == -1) { + printf("Could not open '%s' for writing: %s", mylog, strerror(errno)); return 1; } hug_status_t status = hug_init(HUG_FLAG_USE_MUTEX | @@ -63,10 +67,13 @@ int main(int argc, char *argv[]) INFO(example, "We are up and running"); DEBUG(example, "Or are we %d?", 42); - int a = 0; - DEBUG(foo, "Or are we %d?", 1/a); + + DEBUG(foo, "Or are we %d?", 42); hug_close(); + unlink(mylog); + unlink("/tmp/my.log2"); + return 0; } diff --git a/main_simple.c b/main_simple.c index 07b577d..84753c9 100644 --- a/main_simple.c +++ b/main_simple.c @@ -30,13 +30,17 @@ #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> - +#include <unistd.h> #include <stdio.h> +#include <string.h> +#include <errno.h> int main(int argc, char *argv[]) { - int fd = open("/tmp/my.log", O_CREAT | O_RDWR, 0777); + const char *mylog = "/tmp/my.log"; + int fd = open(mylog, O_CREAT | O_RDWR, 0777); if(fd == -1) { + printf("Could not open '%s' for writing: %s", mylog, strerror(errno)); return 1; } @@ -46,7 +50,7 @@ int main(int argc, char *argv[]) HUG_FLAG_OUTPUT_TO_STDERR | 0, HUG_OPTION_FD, fd, - HUG_OPTION_FILENAME, "/tmp/my2.log", + HUG_OPTION_FILENAME, "/tmp/my.log2", HUG_OPTION_STDOUT_NO_DATE, 0, HUG_OPTION_END); @@ -57,11 +61,16 @@ int main(int argc, char *argv[]) INFO(example, "We are up and running"); - DEBUG(example, "Or are we %d?", 42); + DEBUG(example, "Or are we %d %s?", 42, "hello"); - DEBUG(foo, "Or are we %d?", 42); + const char bar[] = "bar"; + (void)bar; // Ignore if compiled with hugin disabled. + DEBUG(foo, "Or are we %d %s?", 42, bar); hug_close(); + unlink(mylog); + unlink("/tmp/my.log2"); + return 0; } |