summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-07-18 20:34:59 -0400
committerJakob Kaivo <jkk@ung.org>2019-07-18 20:34:59 -0400
commitb3568f55b0d8d2a9d12c53c8dbee00be66c32d1d (patch)
tree36946775bb266ed25ac5da40f220aac44bafa789
parente716d37c0688d1d14d59f6ad09a4b93b6600615d (diff)
properly inserting new links
-rw-r--r--index.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/index.c b/index.c
index bac0454..5bb7249 100644
--- a/index.c
+++ b/index.c
@@ -4,6 +4,8 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
#include <unistd.h>
#include "blog.h"
@@ -23,8 +25,15 @@ static void insert_into(int blogdir, char *index_dir, const char *uri, const cha
/* add old entries */
int old_index = openat(blogdir, index_path, O_RDONLY);
if (old_index != -1) {
- /* find exising entries */
- /* copy them to new_index */
+ struct stat st;
+ fstat(old_index, &st);
+ char *buf = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, old_index, 0);
+ if (buf != MAP_FAILED) {
+ char *a = strstr(buf, "<a");
+ char *add = strstr(a, "<address");
+ write(new_index, a, add - a);
+ munmap(buf, st.st_size);
+ }
close(old_index);
}