commit f8b82eaff11ef173d579cb61a5c7b04cf5553c54
parent f2808e50cd9e352d8a66990cea670b023b5445f4
Author: Dominik Schmidt <das1993@hotmail.com>
Date: Mon, 11 Jun 2018 01:28:42 +0000
Move the on_file writing function to an extra function to reduce code duplication
Also, introduce some error checking
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/src/laundrysorcery.c b/src/laundrysorcery.c
@@ -46,16 +46,21 @@ double running_mean;
char *on_file;
-void turn_on(void){
+void write_on_file(char *prefix){
FILE *f=fopen(on_file, "w");
- fprintf(f, "%lu\n", time(NULL));
+ if(!f){
+ perror("fopen of on_file");
+ }
+ fprintf(f, "%s%lu\n",prefix, time(NULL));
fclose(f);
}
+void turn_on(void){
+ write_on_file("");
+}
+
void turn_off(void){
- FILE *f=fopen(on_file, "w");
- fprintf(f,"-%lu\n",time(NULL));
- fclose(f);
+ write_on_file("-");
}
void toggle_on_off(void){