X-Git-Url: http://git.indexdata.com/?a=blobdiff_plain;f=client%2Ffhistory.c;h=202593958a170d5da6b42f240918e6c9efef18c7;hb=7a050afbba1b2daf9a1ab6d6c4bbae9ba674a705;hp=0094fd09c126b3c9a54e7bd1642d53248852d90e;hpb=fe507b6b15788a3a8e58063d9dae52532a5229a5;p=yaz-moved-to-github.git diff --git a/client/fhistory.c b/client/fhistory.c index 0094fd0..2025939 100644 --- a/client/fhistory.c +++ b/client/fhistory.c @@ -1,14 +1,13 @@ -/* - * Copyright (C) 1995-2007, Index Data ApS +/* This file is part of the YAZ toolkit. + * Copyright (C) 1995-2008 Index Data * See the file LICENSE for details. - * - * $Id: fhistory.c,v 1.4 2007-05-06 20:12:19 adam Exp $ */ /** \file fhistory.c * \brief file history implementation */ #include +#include #include #include #include @@ -69,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; @@ -89,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))