Skip to content

Commit

Permalink
Don't segfault if the brightness file can't be opened
Browse files Browse the repository at this point in the history
  • Loading branch information
Hendrikto committed Jul 29, 2018
1 parent 252b820 commit 89288f6
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion backlight_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,22 @@ void print_usage(char *name) {
);
}

FILE *open_file(char *name) {
FILE *file;
if (!(file = fopen(name, "r+"))) {
fprintf(stderr, "failed to open %s\n", name);
exit(EXIT_FAILURE);
}
return file;
}

int main(int argc, char **argv) {
if (argc != 2) {
print_usage(argv[0]);
return EXIT_FAILURE;
}
int value = strtol(argv[1], NULL, 10);
FILE *brightness = fopen(BACKLIGHT_DIR "brightness", "r+");
FILE *brightness = open_file(BACKLIGHT_DIR "brightness");
int brightness_value = MIN_BRIGHTNESS;
switch (argv[1][0]) {
case '+':
Expand Down

0 comments on commit 89288f6

Please sign in to comment.