From: Adam Dickmeiss Date: Fri, 30 May 2008 12:27:47 +0000 (+0200) Subject: Truncate yaz-client history if it exceeds certain size (16K). X-Git-Tag: v3.0.30~26 X-Git-Url: http://sru.miketaylor.org.uk/?a=commitdiff_plain;h=c81c923c94d47c16308d487de3431f5027059522;p=yaz-moved-to-github.git Truncate yaz-client history if it exceeds certain size (16K). --- 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))