diff options
Diffstat (limited to 'config.c')
| -rw-r--r-- | config.c | 28 | 
1 files changed, 18 insertions, 10 deletions
| @@ -38,7 +38,7 @@ struct hcalc_config {  };  char *home_dir = NULL; -char config_path[MAX_HOME]; /* ludicrous size */ +char config_path[MAX_HOME];		/* ludicrous size */  size_t filesize(FILE *f) {  	struct stat st; @@ -52,8 +52,9 @@ size_t filesize(FILE *f) {  }  void set_home_dir(void) { -	home_dir = getenv("HOME"); /* could be fancier (getpwent()) */ -	if(!home_dir) return; +	home_dir = getenv("HOME");	/* could be fancier (getpwent()) */ +	if(!home_dir) +		return;  	if(strlen(home_dir) > (MAX_HOME - 100))  		home_dir = NULL;  } @@ -71,19 +72,23 @@ void load_config(void) {  /* 	printf("load_config() called\n"); */  	set_home_dir();  	if(!home_dir) { -		fprintf(stderr, "HOME not set or too long, not loading/saving config file.\n"); +		fprintf(stderr, +				"HOME not set or too long, not loading/saving config file.\n");  		return;  	}  	set_config_path();  	f = fopen(config_path, "rb");  	if(!f) { -		if(errno != ENOENT) perror(config_path); +		if(errno != ENOENT) +			perror(config_path);  		return;  	}  	if(filesize(f) != sizeof(conf)) { -		fprintf(stderr, "%s: wrong size (should be %ld bytes), ignoring.\n", config_path, sizeof(conf)); +		fprintf(stderr, +				"%s: wrong size (should be %ld bytes), ignoring.\n", +				config_path, sizeof(conf));  		fclose(f);  		return;  	} @@ -98,12 +103,14 @@ void load_config(void) {  	}  	if(memcmp(conf.signature, SIGNATURE, SIGLEN) != 0) { -		fprintf(stderr, "%s: Bad config file signature, ignoring\n", config_path); +		fprintf(stderr, "%s: Bad config file signature, ignoring\n", +				config_path);  		return;  	}  	if(conf.doublesize != sizeof(double) || conf.trailer != TRAILER) { -		fprintf(stderr, "%s: Bad config file architecture, ignoring\n", config_path); +		fprintf(stderr, "%s: Bad config file architecture, ignoring\n", +				config_path);  		return;  	} @@ -123,10 +130,11 @@ void save_config(void) {  /* 	printf("save_config() called\n"); */  	set_home_dir(); -	if(!home_dir) return; +	if(!home_dir) +		return;  	set_config_path(); -	unlink(config_path); /* avoid symlink weirdness */ +	unlink(config_path);		/* avoid symlink weirdness */  	f = fopen(config_path, "wb");  	if(!f) { | 
