aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorDaniel Eklöf <daniel@ekloef.se>2020-10-01 20:03:23 +0200
committerDaniel Eklöf <daniel@ekloef.se>2020-10-01 20:03:23 +0200
commit1af2db7928029eb1ec7db3ee5b865815b22057de (patch)
treee0c3200114daa733eca16901a12a305d633d7250 /main.c
parentd8f96450bc8bb70012b1db9f8bd44690e36ef048 (diff)
downloadwbg-1af2db7928029eb1ec7db3ee5b865815b22057de.tar.gz
main: open file once, in main, and log an error when we fail
Diffstat (limited to 'main.c')
-rw-r--r--main.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/main.c b/main.c
index f52b8a9..6777949 100644
--- a/main.c
+++ b/main.c
@@ -318,25 +318,32 @@ main(int argc, const char *const *argv)
return EXIT_FAILURE;
}
+ setlocale(LC_CTYPE, "");
+ log_init(LOG_COLORIZE_AUTO, false, LOG_FACILITY_DAEMON, LOG_CLASS_WARNING);
+
const char *image_path = argv[1];
image = NULL;
+ FILE *fp = fopen(image_path, "rb");
+ if (fp == NULL) {
+ LOG_ERRNO("%s: failed to open", image_path);
+ return EXIT_FAILURE;
+ }
+
#if defined(WBG_HAVE_JPG)
if (image == NULL)
- image = jpg_load(image_path);
+ image = jpg_load(fp, image_path);
#endif
#if defined(WBG_HAVE_PNG)
if (image == NULL)
- image = png_load(image_path);
+ image = png_load(fp, image_path);
#endif
if (image == NULL) {
fprintf(stderr, "error: %s: failed to load\n", image_path);
+ fclose(fp);
return EXIT_FAILURE;
}
- setlocale(LC_CTYPE, "");
- log_init(LOG_COLORIZE_AUTO, false, LOG_FACILITY_DAEMON, LOG_CLASS_WARNING);
-
display = wl_display_connect(NULL);
assert(display != NULL);
@@ -436,5 +443,6 @@ main(int argc, const char *const *argv)
pixman_image_unref(image);
}
log_deinit();
+ fclose(fp);
return exit_code;
}