mirror of
https://codeberg.org/grunfink/snac2.git
synced 2024-11-14 17:45:04 +00:00
New function list_del_md5().
This commit is contained in:
parent
fc96f02b91
commit
0ff3b32e71
1 changed files with 38 additions and 0 deletions
38
data.c
38
data.c
|
@ -314,6 +314,44 @@ int list_add_md5(const char *fn, const char *md5)
|
|||
}
|
||||
|
||||
|
||||
int list_del_md5(const char *fn, const char *md5)
|
||||
/* deletes an md5 from a list */
|
||||
{
|
||||
int status = 404;
|
||||
FILE *i, *o;
|
||||
|
||||
if ((i = fopen(fn, "r")) != NULL) {
|
||||
flock(fileno(i), LOCK_EX);
|
||||
|
||||
xs *nfn = xs_fmt("%s.new", fn);
|
||||
|
||||
if ((o = fopen(nfn, "w")) != NULL) {
|
||||
char line[32 + 1];
|
||||
|
||||
while (fgets(line, sizeof(line), i) != NULL) {
|
||||
if (memcmp(line, md5, 32) != 0)
|
||||
fwrite(line, sizeof(line), 1, o);
|
||||
}
|
||||
|
||||
fclose(o);
|
||||
|
||||
xs *ofn = xs_fmt("%s.old", fn);
|
||||
|
||||
link(fn, ofn);
|
||||
rename(nfn, fn);
|
||||
}
|
||||
else
|
||||
status = 500;
|
||||
|
||||
fclose(i);
|
||||
}
|
||||
else
|
||||
status = 500;
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
d_char *_follower_fn(snac *snac, char *actor)
|
||||
{
|
||||
xs *md5 = xs_md5_hex(actor, strlen(actor));
|
||||
|
|
Loading…
Reference in a new issue