projects
/
yaz-moved-to-github.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
ec7571c
)
Truncate yaz-client history if it exceeds certain size (16K).
author
Adam Dickmeiss
<adam@indexdata.dk>
Fri, 30 May 2008 12:27:47 +0000
(14:27 +0200)
committer
Adam Dickmeiss
<adam@indexdata.dk>
Fri, 30 May 2008 12:27:47 +0000
(14:27 +0200)
client/fhistory.c
patch
|
blob
|
history
diff --git
a/client/fhistory.c
b/client/fhistory.c
index
21f9b6f
..
2025939
100644
(file)
--- a/
client/fhistory.c
+++ b/
client/fhistory.c
@@
-7,6
+7,7
@@
*/
#include <stdio.h>
*/
#include <stdio.h>
+#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
#include <stdlib.h>
#include <assert.h>
#include <time.h>
@@
-67,6
+68,8
@@
int file_history_load(file_history_t fh)
return ret;
}
return ret;
}
+#define FILE_SAVE_HISTORY_MAX 16384
+
int file_history_save(file_history_t fh)
{
FILE *f;
int file_history_save(file_history_t fh)
{
FILE *f;
@@
-87,7
+90,21
@@
int file_history_save(file_history_t fh)
}
else
{
}
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))
if (w != sz)
ret = -1;
if (fclose(f))