From c81c923c94d47c16308d487de3431f5027059522 Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Fri, 30 May 2008 14:27:47 +0200 Subject: [PATCH] Truncate yaz-client history if it exceeds certain size (16K). --- client/fhistory.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/client/fhistory.c b/client/fhistory.c index 21f9b6f..2025939 100644 --- a/client/fhistory.c +++ b/client/fhistory.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -67,6 +68,8 @@ int file_history_load(file_history_t fh) return ret; } +#define FILE_SAVE_HISTORY_MAX 16384 + int file_history_save(file_history_t fh) { FILE *f; @@ -87,7 +90,21 @@ int file_history_save(file_history_t fh) } else { - size_t w = fwrite(wrbuf_buf(fh->wr), 1, sz, f); + size_t w; + const char *start = wrbuf_buf(fh->wr); + if (sz > FILE_SAVE_HISTORY_MAX) + { + const char *nl = strchr( + wrbuf_buf(fh->wr) + sz - FILE_SAVE_HISTORY_MAX, + '\n'); + if (nl) + { + nl++; + sz = sz - (nl - start); + start = nl; + } + } + w = fwrite(start, 1, sz, f); if (w != sz) ret = -1; if (fclose(f)) -- 1.7.10.4