diff options
author | Daniel Eklöf <daniel@ekloef.se> | 2020-10-01 20:03:23 +0200 |
---|---|---|
committer | Daniel Eklöf <daniel@ekloef.se> | 2020-10-01 20:03:23 +0200 |
commit | 1af2db7928029eb1ec7db3ee5b865815b22057de (patch) | |
tree | e0c3200114daa733eca16901a12a305d633d7250 /main.c | |
parent | d8f96450bc8bb70012b1db9f8bd44690e36ef048 (diff) | |
download | wbg-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.c | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -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; } |