clarify code: local variables in start of function
This commit is contained in:
+20
-6
@@ -1,3 +1,4 @@
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@@ -22,6 +23,9 @@ bool file_should_update(File file) {
|
||||
}
|
||||
|
||||
void file_update(File *file) {
|
||||
long length;
|
||||
FILE *file_pointer;
|
||||
|
||||
// free remaining data
|
||||
if (file->content != 0) {
|
||||
free(file->content);
|
||||
@@ -30,9 +34,9 @@ void file_update(File *file) {
|
||||
// init empty file
|
||||
file->content = 0;
|
||||
file->error = false;
|
||||
long length;
|
||||
|
||||
// open file
|
||||
FILE *file_pointer = fopen(file->path, "rb");
|
||||
file_pointer = fopen(file->path, "rb");
|
||||
if (file_pointer == NULL) {
|
||||
file->error = true;
|
||||
log_error("Cannot open file '%s'", file->path);
|
||||
@@ -61,18 +65,28 @@ void file_update(File *file) {
|
||||
}
|
||||
|
||||
File file_read(char *path) {
|
||||
File file = {path, 0, false, 0};
|
||||
File file;
|
||||
|
||||
file.path = path;
|
||||
file.content = NULL;
|
||||
file.error = false;
|
||||
file.last_write = 0;
|
||||
|
||||
file_update(&file);
|
||||
return file;
|
||||
}
|
||||
|
||||
void file_prepend(File *src, File extra) {
|
||||
char *old_src_content = src->content;
|
||||
char *old_src_content;
|
||||
|
||||
old_src_content = src->content;
|
||||
src->content = strings_concat(extra.content, src->content);
|
||||
free(old_src_content);
|
||||
}
|
||||
|
||||
void file_free(File *file) {
|
||||
void file_free(File *file, bool free_path) {
|
||||
free(file->content);
|
||||
free(file->path);
|
||||
if (free_path) {
|
||||
free(file->path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user