From facb67f8438aa8ef18ffacdccfd0a2d1c2730e5c Mon Sep 17 00:00:00 2001 From: Christian Hesse Date: Wed, 12 Jan 2022 09:53:15 +0100 Subject: global initialization for libmagic Add a global `magic_t magic` and initialize it just once. Also `feh_is_image()` now calls itself to check compressed files, saving some duplicate code. --- src/main.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 3d124fd..34b667a 100644 --- a/src/main.c +++ b/src/main.c @@ -69,6 +69,10 @@ int main(int argc, char **argv) #endif } +#ifdef HAVE_LIBMAGIC + init_magic(); +#endif + feh_event_init(); if (opt.index) @@ -262,6 +266,10 @@ void feh_clean_exit(void) if(disp) XCloseDisplay(disp); +#ifdef HAVE_LIBMAGIC + uninit_magic(); +#endif + /* * Only restore the old terminal settings if * - we changed them in the first place -- cgit v1.2.3 From 26cd770c8732a4467e57cf3e7a5d4c2518836275 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Thu, 10 Feb 2022 21:41:35 +0100 Subject: Run init_magic before init_parse_options init_parse_options calls feh_prepare_filelist, which in turn calls feh_file_info_preload if opt.preload is set. This function will load all images in the filelist to determine their attributes, so we need to initialize libmagic before calling init_parse_options. --- src/main.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 34b667a..85e0504 100644 --- a/src/main.c +++ b/src/main.c @@ -49,6 +49,11 @@ int main(int argc, char **argv) srandom(getpid() * time(NULL) % ((unsigned int) -1)); setup_signal_handlers(); + +#ifdef HAVE_LIBMAGIC + init_magic(); +#endif + init_parse_options(argc, argv); init_imlib_fonts(); @@ -69,10 +74,6 @@ int main(int argc, char **argv) #endif } -#ifdef HAVE_LIBMAGIC - init_magic(); -#endif - feh_event_init(); if (opt.index) -- cgit v1.2.3