-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBINLOG.CPP
More file actions
71 lines (50 loc) · 1.59 KB
/
BINLOG.CPP
File metadata and controls
71 lines (50 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include "proboard.hpp"
#include <string.h>
const int BINLOG_BUF = 10;
bool
BinLog::append()
{
File f(FN_BINLOG_PB,fmode_rw | fmode_copen | fmode_denywr);
if(!f.opened()) return FALSE;
if(f.len() >= sizeof(BinLog))
{
Date today(TODAY);
BinLog *log = new BinLog[ BINLOG_BUF ];
f.seek(0);
f.read(log,sizeof(BinLog));
if(cfg.binlogdays && (today - log->date) > cfg.binlogdays)
{
f.seek(0);
for(long rec = 0;;rec++)
{
if(f.read(log,sizeof(BinLog)) != sizeof(BinLog)) break;
if((today - log->date) <= cfg.binlogdays)
{
long dest_rec = 0;
for(;;)
{
f.seek(rec * sizeof(BinLog));
word n = f.read(log,sizeof(BinLog) * BINLOG_BUF);
if(n < sizeof(BinLog)) break;
n /= sizeof(BinLog);
f.seek(dest_rec * sizeof(BinLog));
f.write(log,n * sizeof(BinLog));
dest_rec += n;
rec += n;
}
f.seek(dest_rec * sizeof(BinLog));
f.cut();
break;
}
}
}
delete [] log;
}
f.seek(f.len() / sizeof(BinLog) * sizeof(BinLog));
f.write(this,sizeof(*this));
return TRUE;
}
BinLog::BinLog()
{
memset(this,0,sizeof(*this));
}