Small snake game in C
Commit 145e952393a8
tarball3 files changed+27-13
@@ -197,3 +197,19 @@ direction read_direction(char *string, bool wasd_enabled) {
197197
break;198198
}199199
}200
+201
+uint8_t make_folder(char *path, char *append, bool create_folder) {202
+ 203
+ char tmp[PATH_LEN];204
+ strncpy(tmp, path, PATH_LEN);205
+206
+ snprintf(path, PATH_LEN, "%s/%s", tmp, append);207
+208
+ if (create_folder) {209
+ errno = 0;210
+ if (mkdir(path, 0755) && errno != EEXIST) {211
+ return 0;212
+ }213
+ }214
+ return 1;215
+}@@ -43,24 +43,21 @@ int main(int argc, char *args[]) {
4343
printf("are you ok?\n");4444
return 1;4545
}46
- 47
- errno = 0;48
- snprintf(file_path, sizeof(file_path), "%s/.local", env);49
- if (mkdir(file_path, 0755) && errno != EEXIST) {50
- printf("couldn't create folder");51
- return 1;52
- }5346
54
- errno = 0;55
- snprintf(file_path, sizeof(file_path), "%s/.local/share", env);56
- if (mkdir(file_path, 0755) && errno != EEXIST) {57
- printf("couldn't create folder");47
+ if (48
+ !make_folder(file_path, ".local", true) ||49
+ !make_folder(file_path, "share", true)50
+ ) {51
+ printf("Couldn't create folder\n");5852
return 1;5953
}54
+ 55
+ make_folder(file_path, SETTING_FILE , false);56
+ 57
+ } else {58
+ snprintf(file_path, sizeof(file_path), "%s/%s", env, SETTING_FILE);6059
}6160
62
- snprintf(file_path, sizeof(file_path), "%s/%s", env, SETTING_FILE);63
-6461
{6562
FILE* setting_file = fopen(file_path, "r");6663
@@ -95,5 +95,6 @@ char *give_state(board_state square);
9595
9696
direction read_direction(char *string, bool wasd_enabled);9797
98
+uint8_t make_folder(char *path, char *append, bool create_folder);9899
99100
#endif