aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlonkaars <loek@pipeframe.xyz>2021-05-30 10:20:30 +0200
committerlonkaars <loek@pipeframe.xyz>2021-05-30 10:20:30 +0200
commitbb6ba184d0091d77a0d4753b4bb62d543a20468a (patch)
treee54ef2b77f3a447fbaf830077f71b3881199773f
parent760a8fea16531d199f48b9ec84cad2a08970726b (diff)
exit w/ error function
-rw-r--r--musicopy.c20
1 files changed, 8 insertions, 12 deletions
diff --git a/musicopy.c b/musicopy.c
index 73271c6..f9a0c3c 100644
--- a/musicopy.c
+++ b/musicopy.c
@@ -5,22 +5,21 @@
#include <ini.h>
#include <cwalk.h>
+void exit_err(char* msg) {
+ printf("%s exiting...\n", msg);
+ exit(1);
+}
+
int main() {
char* home = getenv("HOME");
- if(!home) {
- printf("$HOME could not be read! exiting...\n");
- exit(1);
- }
+ if(!home) exit_err("$HOME could not be read!");
char* config_file_loc = ".config/musicopy/rc.ini";
size_t config_path_size = (strlen(home) + strlen(config_file_loc) + 4) * sizeof(char);
char* config_path = malloc(config_path_size);
cwk_path_join(home, config_file_loc, config_path, config_path_size);
- if( access(config_path, F_OK) != 0 ) {
- printf("Config file can't be read! exiting...\n");
- exit(1);
- }
+ if( access(config_path, F_OK) != 0 ) exit_err("Config file could not be read!");
FILE* config_file_handle = fopen(config_path, "rw");
long config_file_length;
char* config_file_buffer = 0;
@@ -29,10 +28,7 @@ int main() {
config_file_length = ftell(config_file_handle);
fseek(config_file_handle, 0, SEEK_SET);
config_file_buffer = malloc(config_file_length);
- if(!config_file_buffer) {
- printf("An error occured allocating memory for the config file! exiting...\n");
- exit(1);
- }
+ if(!config_file_buffer) exit_err("An error occured allocating memory for the config file!");
fread(config_file_buffer, 1, config_file_length, config_file_handle);
printf("%s\n", config_path);