Move the check for directory into load_activities functions.
This commit is contained in:
22
main.c
22
main.c
@@ -211,8 +211,15 @@ char *get_file(char *dir, struct tm *t)
|
|||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *load_activities(char *file_path, activity *activities, U32 *current_activity)
|
FILE *load_activities(char *dir_path, char *file_path, activity *activities, U32 *current_activity)
|
||||||
{
|
{
|
||||||
|
if(!is_directory(dir_path)) {
|
||||||
|
if(mkdir(dir_path, 0700) == -1) {
|
||||||
|
fprintf(stderr, "mkdir(%s) failed: %s\n", dir_path, strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
FILE *f = fopen(file_path, "a+");
|
FILE *f = fopen(file_path, "a+");
|
||||||
if(!f) {
|
if(!f) {
|
||||||
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
fprintf(stderr, "fopen(%s) failed: %s\n", file_path, strerror(errno));
|
||||||
@@ -295,19 +302,10 @@ int main(int argc, char *argv[])
|
|||||||
struct tm *t = today();
|
struct tm *t = today();
|
||||||
U64 ts = start_of_day_seconds(t);
|
U64 ts = start_of_day_seconds(t);
|
||||||
|
|
||||||
|
// NOTE: Not sure this is great, but that is what we'll go with for now.
|
||||||
char *dir_path = get_dir();
|
char *dir_path = get_dir();
|
||||||
char *file_path = get_file(dir_path, t);
|
char *file_path = get_file(dir_path, t);
|
||||||
|
FILE *f = load_activities(dir_path, file_path, activities, ¤t_activity);
|
||||||
// TODO: Move into load_activities.
|
|
||||||
if(!is_directory(dir_path)) {
|
|
||||||
if(mkdir(dir_path, 0700) == -1) {
|
|
||||||
fprintf(stderr, "mkdir(%s) failed: %s\n", dir_path, strerror(errno));
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// NOTE: Not sure this is great, but that is what we'll go with for now.
|
|
||||||
FILE *f = load_activities(file_path, activities, ¤t_activity);
|
|
||||||
|
|
||||||
U64 last_save = 0;
|
U64 last_save = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user