comparison mrjunejune/create_html_from_md.c @ 255:5ec271d612ae

[dowa] Enforce arena ownership Co-authored-by: Copilot <[email protected]>
author MrJuneJune <me@mrjunejune.com>
date Tue, 04 Aug 2026 15:12:18 -0700
parents 295ac2e5ec00
children
comparison
equal deleted inserted replaced
254:2b6e732087ff 255:5ec271d612ae
124 fread(md_file, 1, file_length, file); 124 fread(md_file, 1, file_length, file);
125 125
126 Blog_Metadata meta = Parse_Blog_Frontmatter(md_file); 126 Blog_Metadata meta = Parse_Blog_Frontmatter(md_file);
127 char *md = markdown_to_html(meta.content); 127 char *md = markdown_to_html(meta.content);
128 char *ssr_body = Dowa_Arena_Allocate(arena, buffer_sizes); 128 char *ssr_body = Dowa_Arena_Allocate(arena, buffer_sizes);
129 char *final_body = Dowa_Arena_Allocate(arena, buffer_sizes);
130 snprintf(ssr_body, buffer_sizes, BLOG_HTML, meta.description, meta.title, md); 129 snprintf(ssr_body, buffer_sizes, BLOG_HTML, meta.description, meta.title, md);
130 markdown_free(md);
131 131
132 int open_flags = O_RDWR | O_CREAT | O_EXCL;
133 size_t md_file_path_length = strlen(md_file_path); 132 size_t md_file_path_length = strlen(md_file_path);
134 md_file_path_length -= 3; // html 133 md_file_path_length -= 3; // html
135 char *new_file_path = Dowa_Arena_Allocate(arena, 1024); 134 char *new_file_path = Dowa_Arena_Allocate(arena, 1024);
136 snprintf(new_file_path, 1024, "%.*s.html", (int)md_file_path_length, md_file_path); 135 snprintf(new_file_path, 1024, "%.*s.html", (int)md_file_path_length, md_file_path);
137 136
138 FILE *new_file_fd = fopen(new_file_path, "w+"); 137 FILE *new_file_fd = fopen(new_file_path, "w+");
139 if (!new_file_fd) 138 if (!new_file_fd)
140 return; 139 {
140 Dowa_Arena_Free(arena);
141 return 1;
142 }
141 printf("Saving to %s...\n", new_file_path); 143 printf("Saving to %s...\n", new_file_path);
142 fwrite(ssr_body, 1, buffer_sizes, new_file_fd); 144 fwrite(ssr_body, 1, buffer_sizes, new_file_fd);
143 fclose(new_file_fd); 145 fclose(new_file_fd);
144 } 146 }
147 Dowa_Arena_Free(arena);
145 return 0; 148 return 0;
146 } 149 }
147