From a6e64b01f81161cc614f238c37eb56f91cc4247f Mon Sep 17 00:00:00 2001 From: Rodrigo Arias Mallo Date: Thu, 28 Mar 2024 19:06:04 +0100 Subject: Handle .exe extension in Windows for dpis On Cygwin the binaries have the ".exe" extension, so the logic to detect dpi files has to take it into account when scanning the dpi_dir. The extension DPI_EXT is defined to ".dpi" or ".dpi.exe" depending on the platform extension discovered by autoconf. Similarly, the dpidrc configuration file is also configured to match the name of the DPI binaries. See: https://github.com/cygwinports-extras/dillo/blob/master/3.0.2-exeext.patch Fixes: https://github.com/dillo-browser/dillo/issues/105 --- dpid/dpid.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'dpid/dpid.c') diff --git a/dpid/dpid.c b/dpid/dpid.c index 21e33bf2..06ae86b7 100644 --- a/dpid/dpid.c +++ b/dpid/dpid.c @@ -36,6 +36,8 @@ #include "../dpip/dpip.h" +#define DPI_EXT (".dpi" EXEEXT) + #define QUEUE 5 volatile sig_atomic_t caught_sigchld = 0; @@ -140,16 +142,26 @@ void est_dpi_terminator() } } +static int ends_with(const char *str, const char *suffix) +{ + if (!str || !suffix) + return 0; + size_t lenstr = strlen(str); + size_t lensuffix = strlen(suffix); + if (lensuffix > lenstr) + return 0; + return strncmp(str + lenstr - lensuffix, suffix, lensuffix) == 0; +} + /*! Identify a given file * Currently there is only one file type associated with dpis. * More file types will be added as needed */ enum file_type get_file_type(char *file_name) { - char *dot = strrchr(file_name, '.'); - - if (dot && !strcmp(dot, ".dpi")) - return DPI_FILE; /* Any filename ending in ".dpi" */ + if (ends_with(file_name, DPI_EXT)) + /* Any filename ending in ".dpi" (or ".dpi.exe" on Windows) */ + return DPI_FILE; else { MSG_ERR("get_file_type: Unknown file type for %s\n", file_name); return UNKNOWN_FILE; -- cgit v1.2.3