summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordefault <nobody@localhost>2022-11-23 19:14:55 +0100
committerdefault <nobody@localhost>2022-11-23 19:14:55 +0100
commit0ff3b32e712a7750feef9e19dca3507641eb01ea (patch)
tree1c9e9910f137f0a20229a44ac7066d66c29df186
parentfc96f02b917d3c2af9284bbbcfc69456bbfba0c3 (diff)
New function list_del_md5().
-rw-r--r--data.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/data.c b/data.c
index 70d48db..bc01103 100644
--- a/data.c
+++ b/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));