#define _XOPEN_SOURCE 700 #include #include #include #include #include #include #include #include #include "blog.h" static void insert_into(int blogdir, char *index_dir, const char *uri, const char *title) { char index_path[FILENAME_MAX] = { 0 }; snprintf(index_path, sizeof(index_path), "%s/index.html", index_dir); char new_path[FILENAME_MAX] = { 0 }; snprintf(new_path, sizeof(new_path), "%s.new", index_path); int new_index = openat(blogdir, new_path, O_WRONLY | O_CREAT, 0644); dprintf(new_index, HTML_HEAD, "index"); dprintf(new_index, "%s
", uri, title); /* add old entries */ int old_index = openat(blogdir, index_path, O_RDONLY); if (old_index != -1) { 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, "