From 9edc129c0d675b80aee9d2f382bd80ed9a43ddba Mon Sep 17 00:00:00 2001 From: mrb0nk500 Date: Tue, 26 Jul 2022 18:30:00 -0300 Subject: git: Add `create_file()` --- git.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/git.c b/git.c index 5408de9..4ba9f97 100644 --- a/git.c +++ b/git.c @@ -64,6 +64,17 @@ void cleanup_git(git_repository **repos) { git_libgit2_shutdown(); } +file *create_file(const char *root, const char *filename) { + const size_t path_len = format_len("%s/%s", root, filename); + char *path = calloc(path_len+1, sizeof(char)); + long buf_size = 0; + file *f = calloc(1, sizeof(file)); + sprintf(path, "%s/%s", root, filename); + f->name = (char *)filename; + f->buf = read_file(filename, &buf_size); + return f; +} + void free_file(file *file) { if (file->name != NULL) { free(file->name); -- cgit v1.2.3-13-gbd6f