u/file: Add u_file_read_content_from_path

Useful for Simula builder and North Star builder which both read straight from a path
This commit is contained in:
Moses Turner 2022-09-18 08:02:43 -05:00
parent a285294d7f
commit d04139bedd
2 changed files with 19 additions and 0 deletions

View file

@ -154,3 +154,19 @@ u_file_read_content(FILE *file)
return buffer;
}
char *
u_file_read_content_from_path(const char *path)
{
FILE *file = fopen(path, "r");
if (file == NULL) {
return NULL;
}
char *file_content = u_file_read_content(file);
int ret = fclose(file);
// We don't care about the return value since we're just reading
(void)ret;
// Either valid non-null or null
return file_content;
}

View file

@ -34,6 +34,9 @@ u_file_get_runtime_dir(char *out_path, size_t out_path_size);
char *
u_file_read_content(FILE *file);
char *
u_file_read_content_from_path(const char *path);
ssize_t
u_file_get_path_in_runtime_dir(const char *suffix, char *out_path, size_t out_path_size);