mirror of https://github.com/nealey/irc-bot
append action
This commit is contained in:
parent
6fbd1feb67
commit
b993629d88
|
@ -108,7 +108,6 @@ cdbmake_finalize(struct cdbmake_ctx *ctx)
|
|||
free(buf);
|
||||
}
|
||||
|
||||
fclose(ctx->f);
|
||||
ctx->f = NULL;
|
||||
|
||||
for (idx = 0; idx < 256; idx += 1) {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
#include <string.h>
|
||||
|
||||
struct cdbmake_record {
|
||||
FILE *f;
|
||||
uint32_t hashval;
|
||||
uint32_t offset;
|
||||
};
|
||||
|
|
15
infobot.c
15
infobot.c
|
@ -122,19 +122,18 @@ add(char *filename, char *key, char *val)
|
|||
struct cdbmake_ctx outc;
|
||||
FILE *inf;
|
||||
FILE *outf;
|
||||
char tmpfn[8192];
|
||||
|
||||
// Open input file
|
||||
inf = fopen(filename, "rb");
|
||||
if (! inf) {
|
||||
perror("Opening database");
|
||||
return EX_NOINPUT;
|
||||
}
|
||||
|
||||
{
|
||||
char fn[4096];
|
||||
|
||||
snprintf(fn, sizeof(fn), "%s.%d", filename, getpid());
|
||||
outf = fopen(fn, "wb");
|
||||
}
|
||||
// Create temporary output file
|
||||
snprintf(tmpfn, sizeof(tmpfn), "%s.%d", filename, getpid());
|
||||
outf = fopen(tmpfn, "wb");
|
||||
if (! outf) {
|
||||
perror("Creating temporary database");
|
||||
return EX_CANTCREAT;
|
||||
|
@ -157,6 +156,10 @@ add(char *filename, char *key, char *val)
|
|||
cdbmake_add(&outc, key, strlen(key), val, strlen(val));
|
||||
cdbmake_finalize(&outc);
|
||||
|
||||
fclose(outf);
|
||||
fclose(inf);
|
||||
rename(tmpfn, filename);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue