From 7ff43f0346c9bea1bbc63fc61c4cb8f2bd9941bb Mon Sep 17 00:00:00 2001 From: Aidan Hahn Date: Fri, 22 Jul 2022 09:52:52 -0700 Subject: [PATCH] fix include issues Signed-off-by: Aidan Hahn --- alog.c | 8 ++++++++ alog.h | 11 ++++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/alog.c b/alog.c index 95ae87b..4e9f7ae 100644 --- a/alog.c +++ b/alog.c @@ -25,6 +25,12 @@ #define TEST_ALOG_STATE() if (!ALOG_LOGGING_STATE) { _init_alog(); } +struct _global_logging_state *ALOG_LOGGING_STATE; +int _alog_num_out_fds; +int *_alog_out_fds; +int _alog_num_err_fds; +int *_alog_err_fds; + void _init_alog() { if (!ALOG_LOGGING_STATE) { ALOG_LOGGING_STATE = malloc(sizeof(struct _global_logging_state)); @@ -152,6 +158,7 @@ void alog ( int size; if (severity != PRINT) { // GET TIMESTAMP + // TODO: try to get this all into 1 call to sprintf time_t t = time(NULL); struct tm * p = localtime(&t); char *timestamp = malloc(strftime(NULL, 0, "[%c]", p) + 1); @@ -159,6 +166,7 @@ void alog ( char *msg_and_timestamp = malloc(sizeof(timestamp) + 1 + (strlen(message) + 1) + 2); sprintf(msg_and_timestamp, "%s %s\n", timestamp, message); free(timestamp); + // TODO: Why even use msg_and_timestamp if I am going to write it wholesale into buffer? size = snprintf(NULL, 0, msg_and_timestamp, fmt_list); buffer = malloc(size + 1); sprintf(buffer, msg_and_timestamp, fmt_list); diff --git a/alog.h b/alog.h index b7e8cfb..30d3093 100644 --- a/alog.h +++ b/alog.h @@ -30,7 +30,7 @@ struct _global_logging_state { * I am sticking with it here. * * Alloc'ed/Initialized by a call to init_alog()*/ -struct _global_logging_state *ALOG_LOGGING_STATE; +extern struct _global_logging_state *ALOG_LOGGING_STATE; /* alternative impl I didnt want to write * it would have required a bunch of getters and setters @@ -42,10 +42,10 @@ struct _global_logging_state *ALOG_LOGGING_STATE; #define LOG_DEBUG_MSGS_FIELD = 2; int flags = 0; */ -int _alog_num_out_fds; -int *_alog_out_fds; -int _alog_num_err_fds; -int *_alog_err_fds; +extern int _alog_num_out_fds; +extern int *_alog_out_fds; +extern int _alog_num_err_fds; +extern int *_alog_err_fds; typedef enum { // Not printed by default. Useful for debug info @@ -84,4 +84,5 @@ void alog(alog_sev, const char *, ...); #ifdef ALOG_HIJACK_PRINTF int printf(const char *format, ...); #endif // ALOG_HIJACK_PRINTF + #endif // ALOG_H