From 48cf4ebf02f395b116662ba9662b768f7aed768b Mon Sep 17 00:00:00 2001 From: Jfreegman Date: Tue, 23 Sep 2014 21:32:05 -0400 Subject: [PATCH] fix for issue #254 --- src/autocomplete.h | 2 +- src/log.c | 12 +++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/autocomplete.h b/src/autocomplete.h index 40b7099..981cd8f 100644 --- a/src/autocomplete.h +++ b/src/autocomplete.h @@ -39,4 +39,4 @@ int complete_line(ToxWindow *self, const void *list, int n_items, int size); return diff between old len and new len of ctx->line, -1 if no matches or > 1 match */ int dir_match(ToxWindow *self, Tox *m, const wchar_t *line); -#endif /* #define AUTOCOMPLETE_H */ \ No newline at end of file +#endif /* #define AUTOCOMPLETE_H */ diff --git a/src/log.c b/src/log.c index c133d72..5c1a3af 100644 --- a/src/log.c +++ b/src/log.c @@ -89,8 +89,8 @@ static int init_logging_session(char *name, const char *selfkey, const char *oth snprintf(log_path, sizeof(log_path), "%s%s%s-%s%s%s.log", user_config_dir, LOGDIR, self_id, name, namedash, other_id); free(user_config_dir); - log->file = fopen(log_path, "a+"); + snprintf(log->path, sizeof(log->path), "%s", log_path); if (log->file == NULL) @@ -160,7 +160,7 @@ void load_chat_history(ToxWindow *self, struct chatlog *log) struct stat st; if (stat(log->path, &st) == -1) { - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Failed to stat log file"); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to stat log file"); return; } @@ -174,9 +174,15 @@ void load_chat_history(ToxWindow *self, struct chatlog *log) if (hstbuf == NULL) exit_toxic_err("failed in load_chat_history", FATALERR_MEMORY); + if (fseek(log->file, 0L, SEEK_SET) == -1) { + free(hstbuf); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to read log file"); + return; + } + if (fread(hstbuf, sz, 1, log->file) != 1) { free(hstbuf); - line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, "* Failed to read log file"); + line_info_add(self, NULL, NULL, NULL, SYS_MSG, 0, RED, " * Failed to read log file"); return; }