1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

log.c: Use gchar* instead of GString for mainlogfile

This commit is contained in:
Michael Vetter 2020-07-02 15:00:09 +02:00
parent f4159d8168
commit f8ff93234e

View File

@ -55,7 +55,7 @@
#define PROF "prof" #define PROF "prof"
static FILE *logp; static FILE *logp;
GString *mainlogfile = NULL; static gchar *mainlogfile = NULL;
static GTimeZone *tz; static GTimeZone *tz;
static GDateTime *dt; static GDateTime *dt;
@ -148,20 +148,19 @@ log_init(log_level_t filter, char *log_file)
{ {
level_filter = filter; level_filter = filter;
tz = g_time_zone_new_local(); tz = g_time_zone_new_local();
gchar *lf = files_get_log_file(log_file);
gchar *lf;
lf = files_get_log_file(log_file);
logp = fopen(lf, "a"); logp = fopen(lf, "a");
g_chmod(lf, S_IRUSR | S_IWUSR); g_chmod(lf, S_IRUSR | S_IWUSR);
mainlogfile = g_string_new(lf); mainlogfile = g_strdup(lf);
g_free(lf); g_free(lf);
} }
void void
log_reinit(void) log_reinit(void)
{ {
char *lf = strdup(mainlogfile->str); char *lf = strdup(mainlogfile);
char *start = strrchr(lf, '/') +1; char *start = strrchr(lf, '/') +1;
char *end = strstr(start, ".log"); char *end = strstr(start, ".log");
*end = '\0'; *end = '\0';
@ -175,7 +174,7 @@ log_reinit(void)
const char* const char*
get_log_file_location(void) get_log_file_location(void)
{ {
return mainlogfile->str; return mainlogfile;
} }
log_level_t log_level_t
@ -187,7 +186,7 @@ log_get_filter(void)
void void
log_close(void) log_close(void)
{ {
g_string_free(mainlogfile, TRUE); g_free(mainlogfile);
mainlogfile = NULL; mainlogfile = NULL;
g_time_zone_unref(tz); g_time_zone_unref(tz);
if (logp) { if (logp) {
@ -240,7 +239,7 @@ log_level_from_string(char *log_level)
static void static void
_rotate_log_file(void) _rotate_log_file(void)
{ {
gchar *log_file = strdup(mainlogfile->str); gchar *log_file = g_strdup(mainlogfile);
size_t len = strlen(log_file); size_t len = strlen(log_file);
gchar *log_file_new = malloc(len + 4); gchar *log_file_new = malloc(len + 4);
int i = 1; int i = 1;
@ -252,7 +251,7 @@ _rotate_log_file(void)
break; break;
} }
char *lf = strdup(mainlogfile->str); char *lf = strdup(mainlogfile);
char *start = strrchr(lf, '/') +1; char *start = strrchr(lf, '/') +1;
char *end = strstr(start, ".log"); char *end = strstr(start, ".log");
*end = '\0'; *end = '\0';