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