From e07891617859ba951f309cdc3ff4fe696f37d17e Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 27 Oct 2023 10:37:48 +0200 Subject: [PATCH 1/2] pathtools: some cleanup * Merge msys2_relocate into pathtools, so there is only one header for everything * Stop exposing unused split_path_list, strip_n_prefix_folders, pathlist_relocation, pathlist_relocation_lib, sanitise_path, malloc_copy_string * Make the header usable with cpp --- mingw-w64-pathtools/main.c | 7 ++- mingw-w64-pathtools/meson.build | 2 +- mingw-w64-pathtools/msys2_relocate.c | 67 --------------------- mingw-w64-pathtools/msys2_relocate.h | 26 --------- mingw-w64-pathtools/pathtools-private.h | 20 +++++++ mingw-w64-pathtools/pathtools.c | 77 +++++++++++++++---------- mingw-w64-pathtools/pathtools.h | 49 ++++++++-------- 7 files changed, 97 insertions(+), 151 deletions(-) delete mode 100644 mingw-w64-pathtools/msys2_relocate.c delete mode 100644 mingw-w64-pathtools/msys2_relocate.h create mode 100644 mingw-w64-pathtools/pathtools-private.h diff --git a/mingw-w64-pathtools/main.c b/mingw-w64-pathtools/main.c index 693ef17d7dbf2..a186494918340 100644 --- a/mingw-w64-pathtools/main.c +++ b/mingw-w64-pathtools/main.c @@ -5,9 +5,12 @@ */ #include +#include +#include +#include #include "pathtools.h" -#include "msys2_relocate.h" +#include "pathtools-private.h" void sanitise_path_debug(char const * path, char const * expected) @@ -31,7 +34,7 @@ sanitise_path_debug(char const * path, char const * expected) void simplify_path_debug (const char * input, const char * expected) { - char * input_copy = malloc_copy_string (input); + char * input_copy = _strdup (input); if ( input_copy == NULL ) { _exit(1); diff --git a/mingw-w64-pathtools/meson.build b/mingw-w64-pathtools/meson.build index 5e7047f318a4c..ffb50447ae55a 100644 --- a/mingw-w64-pathtools/meson.build +++ b/mingw-w64-pathtools/meson.build @@ -6,4 +6,4 @@ project('msys2-pathtools', 'c', 'cpp', ] ) -test('main', executable('main', 'main.c', 'msys2_relocate.c', 'pathtools.c')) +test('main', executable('main', 'main.c', 'pathtools.c')) diff --git a/mingw-w64-pathtools/msys2_relocate.c b/mingw-w64-pathtools/msys2_relocate.c deleted file mode 100644 index 184e6fc14b895..0000000000000 --- a/mingw-w64-pathtools/msys2_relocate.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - .Some useful path tools. - Written by Ray Donnelly in 2014. - Licensed under CC0. No warranty. - */ - -#include "pathtools.h" -#if defined(_WIN32) -/* All this just for MAX_PATH */ -#define WIN32_MEAN_AND_LEAN -#include -#else -#include -#endif - -char const * -msys2_get_relocated_single_path(char const * unix_path) -{ - char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); - char win_part[MAX_PATH]; - get_executable_path (NULL, &win_part[0], MAX_PATH); - strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ - char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); - strcpy (new_path, win_part); - strcat (new_path, unix_part); - return new_path; -} - -char * -msys2_get_relocated_path_list(char const * paths) -{ - char win_part[MAX_PATH]; - get_executable_path (NULL, &win_part[0], MAX_PATH); - strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ - - char **arr = NULL; - - size_t count = split_path_list (paths, ':', &arr); - int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ - size_t i; - for (i = 0; i < count; ++i) - { - arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); - result_size += strlen (arr[i]) + strlen (win_part); - } - char * result = (char *) malloc (result_size); - if (result == NULL) - { - return NULL; - } - result[0] = '\0'; - for (i = 0; i < count; ++i) - { - strcat (result, win_part); - strcat (result, arr[i]); - if (i != count-1) - { -#if defined(_WIN32) - strcat (result, ";"); -#else - strcat (result, ":"); -#endif - } - } - free ((void*)arr); - return result; -} diff --git a/mingw-w64-pathtools/msys2_relocate.h b/mingw-w64-pathtools/msys2_relocate.h deleted file mode 100644 index c87e1358aa420..0000000000000 --- a/mingw-w64-pathtools/msys2_relocate.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - .Some useful path tools. - Written by Ray Donnelly in 2014. - Licensed under CC0. No warranty. - */ - -#ifndef MSYS2_RELOCATE_H -#define MSYS2_RELOCATE_H - -/* Allocates (via malloc) and returns a relocated path from a single Unix path. - This function makes large assumptions regarding PREFIX and is therefore very - much an MSYS2-only function. It operates by removing the first folder of the - input and final folder of the program executable then appending the input to - that. -*/ -char const * msys2_get_relocated_single_path(char const * unix_path); - -/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the - result of applying the procedure detailed for msys2_get_relocated_single_path - on that Unix sub-path with the results joined up again with a ';' delimiter. - It implements the same logic in msys2_get_relocated_single_path to reduce the - the number of mallocs. -*/ -char * msys2_get_relocated_path_list(char const * paths); - -#endif /* MSYS2_RELOCATE_H */ diff --git a/mingw-w64-pathtools/pathtools-private.h b/mingw-w64-pathtools/pathtools-private.h new file mode 100644 index 0000000000000..d4566b99d1869 --- /dev/null +++ b/mingw-w64-pathtools/pathtools-private.h @@ -0,0 +1,20 @@ +/* + .Some useful path tools. + .ASCII only for now. + .Written by Ray Donnelly in 2014. + .Licensed under CC0 (and anything. + .else you need to license it under). + .No warranties whatsoever. + .email: . + */ + +#ifndef PATHTOOLS_PRIVATE_H +#define PATHTOOLS_PRIVATE_H + +#include +#include + +/* In-place replaces any '\' with '/' and any '//' with '/' */ +void sanitise_path(char * path); + +#endif /* PATHTOOLS_PRIVATE_H */ diff --git a/mingw-w64-pathtools/pathtools.c b/mingw-w64-pathtools/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-pathtools/pathtools.c +++ b/mingw-w64-pathtools/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-pathtools/pathtools.h b/mingw-w64-pathtools/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-pathtools/pathtools.h +++ b/mingw-w64-pathtools/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ From 6dd4efad4cec3441422fad4a30dd2b4d4ef161fd Mon Sep 17 00:00:00 2001 From: Christoph Reiter Date: Fri, 27 Oct 2023 10:56:50 +0200 Subject: [PATCH 2/2] synchronize pathtools no rebuilds, since nothing changed for users. Thy only exception is extremetuxracer where the header can now be included in cpp code as is. --- mingw-w64-connect/PKGBUILD | 4 +- mingw-w64-connect/pathtools.c | 77 +++++++++++-------- mingw-w64-connect/pathtools.h | 49 ++++++------ mingw-w64-curl/PKGBUILD | 4 +- mingw-w64-curl/pathtools.c | 77 +++++++++++-------- mingw-w64-curl/pathtools.h | 49 ++++++------ mingw-w64-cyrus-sasl/PKGBUILD | 4 +- mingw-w64-cyrus-sasl/pathtools.c | 77 +++++++++++-------- mingw-w64-cyrus-sasl/pathtools.h | 49 ++++++------ mingw-w64-extremetuxracer/0001-relocate.patch | 4 +- mingw-w64-extremetuxracer/PKGBUILD | 8 +- mingw-w64-extremetuxracer/pathtools.c | 77 +++++++++++-------- mingw-w64-extremetuxracer/pathtools.h | 49 ++++++------ mingw-w64-ffmpeg/PKGBUILD | 4 +- mingw-w64-ffmpeg/pathtools.c | 77 +++++++++++-------- mingw-w64-ffmpeg/pathtools.h | 49 ++++++------ mingw-w64-firebird2-git/PKGBUILD | 4 +- mingw-w64-firebird2-git/pathtools.c | 77 +++++++++++-------- mingw-w64-firebird2-git/pathtools.h | 49 ++++++------ mingw-w64-graphicsmagick/PKGBUILD | 4 +- mingw-w64-graphicsmagick/pathtools.c | 77 +++++++++++-------- mingw-w64-graphicsmagick/pathtools.h | 49 ++++++------ mingw-w64-hunspell/PKGBUILD | 4 +- mingw-w64-hunspell/pathtools.c | 77 +++++++++++-------- mingw-w64-hunspell/pathtools.h | 49 ++++++------ mingw-w64-imagemagick/PKGBUILD | 4 +- mingw-w64-imagemagick/pathtools.c | 77 +++++++++++-------- mingw-w64-imagemagick/pathtools.h | 49 ++++++------ mingw-w64-ldns/PKGBUILD | 4 +- mingw-w64-ldns/pathtools.c | 77 +++++++++++-------- mingw-w64-ldns/pathtools.h | 49 ++++++------ mingw-w64-openssl/PKGBUILD | 4 +- mingw-w64-openssl/pathtools.c | 77 +++++++++++-------- mingw-w64-openssl/pathtools.h | 49 ++++++------ mingw-w64-p11-kit/PKGBUILD | 4 +- mingw-w64-p11-kit/pathtools.c | 77 +++++++++++-------- mingw-w64-p11-kit/pathtools.h | 49 ++++++------ mingw-w64-port-scanner/PKGBUILD | 4 +- mingw-w64-port-scanner/pathtools.c | 77 +++++++++++-------- mingw-w64-port-scanner/pathtools.h | 49 ++++++------ mingw-w64-swig/PKGBUILD | 4 +- mingw-w64-swig/pathtools.c | 77 +++++++++++-------- mingw-w64-swig/pathtools.h | 49 ++++++------ 43 files changed, 1025 insertions(+), 803 deletions(-) diff --git a/mingw-w64-connect/PKGBUILD b/mingw-w64-connect/PKGBUILD index 90469cb07e4fb..b7a697d492f6d 100644 --- a/mingw-w64-connect/PKGBUILD +++ b/mingw-w64-connect/PKGBUILD @@ -19,8 +19,8 @@ source=(${_realname}-${pkgver}.tar.gz::"${url}/archive/${pkgver}.tar.gz" "pathtools.h") sha256sums=('96c50fefe7ecf015cf64ba6cec9e421ffd3b18fef809f59961ef9229df528f3e' '1e1c89159178349a75665fcb9dfb7639e477b9af32165a377dad54c55e8a59d3' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6') + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a') prepare() { test ! -d "${startdir}/../mingw-w64-pathtools" || { diff --git a/mingw-w64-connect/pathtools.c b/mingw-w64-connect/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-connect/pathtools.c +++ b/mingw-w64-connect/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-connect/pathtools.h b/mingw-w64-connect/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-connect/pathtools.h +++ b/mingw-w64-connect/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-curl/PKGBUILD b/mingw-w64-curl/PKGBUILD index 4802b532f53a6..1cae875c3953b 100644 --- a/mingw-w64-curl/PKGBUILD +++ b/mingw-w64-curl/PKGBUILD @@ -39,8 +39,8 @@ source=("https://github.com/curl/curl/releases/download/${_realname}-${pkgver//. "0004-more-static-fixes.patch") sha256sums=('16c62a9c4af0f703d28bda6d7bbf37ba47055ad3414d70dec63e2e6336f2a82d' 'SKIP' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' 'c4e6bfd5b58f944d75293128effbd22fe42ee0131b915d9230ceb3c004c0322d' '3ee9c75a3046f86f91290c143170179230c9adc6eabfbb79eb26f708a165b719' '7492d019036b5bec251bfbc3c0b40e5f16d3dd6b2515068835e087a6c21f19ad' diff --git a/mingw-w64-curl/pathtools.c b/mingw-w64-curl/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-curl/pathtools.c +++ b/mingw-w64-curl/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-curl/pathtools.h b/mingw-w64-curl/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-curl/pathtools.h +++ b/mingw-w64-curl/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-cyrus-sasl/PKGBUILD b/mingw-w64-cyrus-sasl/PKGBUILD index 446d10fb8fa12..7b9bd46c83167 100644 --- a/mingw-w64-cyrus-sasl/PKGBUILD +++ b/mingw-w64-cyrus-sasl/PKGBUILD @@ -48,8 +48,8 @@ source=(https://github.com/cyrusimap/${_realname}/releases/download/${_realname} 23-Fix-building-digest-plugin.patch) sha256sums=('7ccfc6abd01ed67c1a0924b353e526f1b766b21f42d4562ee635a8ebfc5bb38c' 'SKIP' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '432c24477aa527c1fdb42977797054ee1a541597448d07f8c0201909b3adaf8c' 'e101e1bd3ee03650e89e05c18d5f699d2f69aecc4f7aac4b11db2d1755783c5c' 'b55f1444f5c2b9f3ac252867c89de692dd69e82bff3f843f6340adea31e04d09' diff --git a/mingw-w64-cyrus-sasl/pathtools.c b/mingw-w64-cyrus-sasl/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-cyrus-sasl/pathtools.c +++ b/mingw-w64-cyrus-sasl/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-cyrus-sasl/pathtools.h b/mingw-w64-cyrus-sasl/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-cyrus-sasl/pathtools.h +++ b/mingw-w64-cyrus-sasl/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-extremetuxracer/0001-relocate.patch b/mingw-w64-extremetuxracer/0001-relocate.patch index 82e4e205c75b9..784fe0d9f6829 100644 --- a/mingw-w64-extremetuxracer/0001-relocate.patch +++ b/mingw-w64-extremetuxracer/0001-relocate.patch @@ -29,13 +29,11 @@ CXXFLAGS="${CXXFLAGS} -std=c++14" --- etr-0.8.3/src/game_config.cpp.orig 2023-06-19 21:53:25.000000000 +0200 +++ etr-0.8.3/src/game_config.cpp 2023-06-22 09:41:50.400527900 +0200 -@@ -39,6 +39,9 @@ +@@ -39,6 +39,7 @@ #include #endif -+extern "C" { +#include "pathtools.h" -+} #include "game_config.h" #include "spx.h" #include "translation.h" diff --git a/mingw-w64-extremetuxracer/PKGBUILD b/mingw-w64-extremetuxracer/PKGBUILD index 7a58a787d666c..76201040253e8 100644 --- a/mingw-w64-extremetuxracer/PKGBUILD +++ b/mingw-w64-extremetuxracer/PKGBUILD @@ -4,7 +4,7 @@ _realname=extremetuxracer pkgbase=mingw-w64-${_realname} pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}") pkgver=0.8.3 -pkgrel=2 +pkgrel=3 pkgdesc="Downhill racing game starring Tux (mingw-w64)" arch=('any') mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64') @@ -23,9 +23,9 @@ source=("https://downloads.sourceforge.net/${_realname}/etr-${pkgver}.tar.xz" "pathtools.c" "pathtools.h") sha256sums=('2ee42f3f5fc2f8d49aa75056eb116f6cab84d6564120e6961ae5927367245113' - '99200769921b20ad281fca39125a50fdbe88c8641ad30aa40fae69d3a87f9717' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6') + 'dfe6fa9c5ac538545dca8c734fb10f79e9d1a44440c44c1f22227c7289cbc67b' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a') prepare() { test ! -d "${startdir}/../mingw-w64-pathtools" || { diff --git a/mingw-w64-extremetuxracer/pathtools.c b/mingw-w64-extremetuxracer/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-extremetuxracer/pathtools.c +++ b/mingw-w64-extremetuxracer/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-extremetuxracer/pathtools.h b/mingw-w64-extremetuxracer/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-extremetuxracer/pathtools.h +++ b/mingw-w64-extremetuxracer/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-ffmpeg/PKGBUILD b/mingw-w64-ffmpeg/PKGBUILD index 6c8adf4597eb0..45320ade31fe3 100644 --- a/mingw-w64-ffmpeg/PKGBUILD +++ b/mingw-w64-ffmpeg/PKGBUILD @@ -77,8 +77,8 @@ source=(https://ffmpeg.org/releases/${_realname}-${pkgver}.tar.xz{,.asc} validpgpkeys=('FCF986EA15E6E293A5644F10B4322F04D67658D8') sha256sums=('57be87c22d9b49c112b6d24bc67d42508660e6b718b3db89c44e47e289137082' 'SKIP' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '58f91fde8be7fa093b13275c37b0276de08537449749599e5a50f4f9c8b20926' '84b9fcaa188eef15201a105a44c53d647e4fb800a5032336e0948d6bed2cbc1b' 'bbc7e7b91886a8ac037d8e70692186ee4b48c37b4f1d82b81af8a54463b24803' diff --git a/mingw-w64-ffmpeg/pathtools.c b/mingw-w64-ffmpeg/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-ffmpeg/pathtools.c +++ b/mingw-w64-ffmpeg/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-ffmpeg/pathtools.h b/mingw-w64-ffmpeg/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-ffmpeg/pathtools.h +++ b/mingw-w64-ffmpeg/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-firebird2-git/PKGBUILD b/mingw-w64-firebird2-git/PKGBUILD index fc39e38a9eafe..5d61ccad7dddb 100644 --- a/mingw-w64-firebird2-git/PKGBUILD +++ b/mingw-w64-firebird2-git/PKGBUILD @@ -181,8 +181,8 @@ package() { } sha256sums=('SKIP' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' 'eaa4b490dfaac611001d06f9e1f0fc782340c9631808cb4ded16148f16498146' '6d8c2321a4fe693ac444db650b090fd841cc7c7b914bb30d0fe76559ca1be029' '563193c16e0004f0b4123f153b09462fde08e8a1ab9de25c6de762a7a5751b1e' diff --git a/mingw-w64-firebird2-git/pathtools.c b/mingw-w64-firebird2-git/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-firebird2-git/pathtools.c +++ b/mingw-w64-firebird2-git/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-firebird2-git/pathtools.h b/mingw-w64-firebird2-git/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-firebird2-git/pathtools.h +++ b/mingw-w64-firebird2-git/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-graphicsmagick/PKGBUILD b/mingw-w64-graphicsmagick/PKGBUILD index 08ed3a43983bc..c5f6489f7452c 100644 --- a/mingw-w64-graphicsmagick/PKGBUILD +++ b/mingw-w64-graphicsmagick/PKGBUILD @@ -46,8 +46,8 @@ source=(https://sourceforge.net/projects/graphicsmagick/files/${_realname}/${pkg pathtools.h 001-relocate.patch) sha256sums=('484fccfd2b2faf6c2ba9151469ece5072bcb91ba4ed73e75ed3d8e46c759d557' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '73ce65aad39e54b786c332a9aac42d39353af02cf32e3fbfe4e607644cc0a254') # Helper macros to help make tasks easier # diff --git a/mingw-w64-graphicsmagick/pathtools.c b/mingw-w64-graphicsmagick/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-graphicsmagick/pathtools.c +++ b/mingw-w64-graphicsmagick/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-graphicsmagick/pathtools.h b/mingw-w64-graphicsmagick/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-graphicsmagick/pathtools.h +++ b/mingw-w64-graphicsmagick/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-hunspell/PKGBUILD b/mingw-w64-hunspell/PKGBUILD index 6e5b39720420c..10dc2ecfdf6e8 100644 --- a/mingw-w64-hunspell/PKGBUILD +++ b/mingw-w64-hunspell/PKGBUILD @@ -31,8 +31,8 @@ source=("${_realname}-${pkgver}.tar.gz"::"https://github.com/hunspell/hunspell/a 02-fix-link-with-pdcurses.patch) noextract=("${_realname}-${pkgver}.tar.gz") sha256sums=('69fa312d3586c988789266eaf7ffc9861d9f6396c31fc930a014d551b59bbd6e' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '628ac7f44ae0e093f229e88316cc8fbfb027cdcbe2bc5cc28d75bc3c57413f7a' '260432a8f01525e83124c79e375cc9f0692b1a6c97773add4c69b8efe081cf1d') diff --git a/mingw-w64-hunspell/pathtools.c b/mingw-w64-hunspell/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-hunspell/pathtools.c +++ b/mingw-w64-hunspell/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-hunspell/pathtools.h b/mingw-w64-hunspell/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-hunspell/pathtools.h +++ b/mingw-w64-hunspell/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-imagemagick/PKGBUILD b/mingw-w64-imagemagick/PKGBUILD index a34b120067fad..372c74d4878cc 100644 --- a/mingw-w64-imagemagick/PKGBUILD +++ b/mingw-w64-imagemagick/PKGBUILD @@ -70,8 +70,8 @@ source=(https://imagemagick.org/archive/releases/ImageMagick-${_basever}${_rc}.t 001-7.0.4.1-relocate.patch) sha256sums=('1e44faec8bf603e8c894a7c039fb1b4bb83dc0c429c79c74577e73ceefe4a238' 'SKIP' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '778fecad954d030d8cfd81e30188600bc428a8cac8a4aa7c862ed14bdf46a610') #Lexie Parsimoniae (ImageMagick code signing key) validpgpkeys=('D8272EF51DA223E4D05B466989AB63D48277377A') diff --git a/mingw-w64-imagemagick/pathtools.c b/mingw-w64-imagemagick/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-imagemagick/pathtools.c +++ b/mingw-w64-imagemagick/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-imagemagick/pathtools.h b/mingw-w64-imagemagick/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-imagemagick/pathtools.h +++ b/mingw-w64-imagemagick/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-ldns/PKGBUILD b/mingw-w64-ldns/PKGBUILD index 1480c4da979fa..975a09238a616 100644 --- a/mingw-w64-ldns/PKGBUILD +++ b/mingw-w64-ldns/PKGBUILD @@ -24,8 +24,8 @@ source=("https://www.nlnetlabs.nl/downloads/${_realname}/${_realname}-${pkgver}. sha256sums=('c3f72dd1036b2907e3a56e6acf9dfb2e551256b3c1bbd9787942deeeb70e7860' 'SKIP' '2b7f5a1c9982134f69154cb7445ac16eae1170a86c1d631d56fb9a135c44ec0d' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '5384bc9ed57a2b44999e2c850318001c36809a42e9f3117d42c83911540dd8d0') validpgpkeys=('DC34EE5DB2417BCC151E5100E5F8F8212F77A498') noextract=(${_realname}-${pkgver}.tar.gz) diff --git a/mingw-w64-ldns/pathtools.c b/mingw-w64-ldns/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-ldns/pathtools.c +++ b/mingw-w64-ldns/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-ldns/pathtools.h b/mingw-w64-ldns/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-ldns/pathtools.h +++ b/mingw-w64-ldns/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-openssl/PKGBUILD b/mingw-w64-openssl/PKGBUILD index ade4f0f1f8579..0dc659821f460 100644 --- a/mingw-w64-openssl/PKGBUILD +++ b/mingw-w64-openssl/PKGBUILD @@ -23,8 +23,8 @@ sha256sums=('840af5366ab9b522bde525826be3ef0fb0af81c6a9ebd84caa600fea1731eee3' 'SKIP' '21b96771b401442570e885c2d5689a359a91e86dcbf5511db3667202b6c1fa8a' '5628dd39ab0d3ce4afbb5207bab5d22766abc86a8875b48b6d4d3efd68550e68' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6') + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a') # https://www.openssl.org/community/otc.html validpgpkeys=( diff --git a/mingw-w64-openssl/pathtools.c b/mingw-w64-openssl/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-openssl/pathtools.c +++ b/mingw-w64-openssl/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-openssl/pathtools.h b/mingw-w64-openssl/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-openssl/pathtools.h +++ b/mingw-w64-openssl/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-p11-kit/PKGBUILD b/mingw-w64-p11-kit/PKGBUILD index 99ea88762ee57..4858860390307 100644 --- a/mingw-w64-p11-kit/PKGBUILD +++ b/mingw-w64-p11-kit/PKGBUILD @@ -44,8 +44,8 @@ sha256sums=('d55583bcdde83d86579cabe3a8f7f2638675fef01d23cace733ff748fc354706' '195b2e8695f701caf545e2a468383ad29457febd9b1ee57de1986de04ad3c31c' 'aa92f986d3f7dfc119e86f9a8f3987e6ac2562149921820eadbe09218c4df99c' 'ea4593324db6d2d193733561f0352c6d679d1fb00aed0a2bae0d28aecbe92721' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' '34e96b51f3f513bf479d1e6b647b4a417cec5d0139d1e3aa78fd4e449cf89f3b' '2b0fc5c54776aca54e306315338323075e7412d8d800f490a31870008c34f8d1' '3c4821c36f76fd45c0d1ec83474773e45ccefde4ac92ca88b8493425f7553cb9' diff --git a/mingw-w64-p11-kit/pathtools.c b/mingw-w64-p11-kit/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-p11-kit/pathtools.c +++ b/mingw-w64-p11-kit/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-p11-kit/pathtools.h b/mingw-w64-p11-kit/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-p11-kit/pathtools.h +++ b/mingw-w64-p11-kit/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-port-scanner/PKGBUILD b/mingw-w64-port-scanner/PKGBUILD index 2655efed4e7a1..ea83dfd74cb3f 100644 --- a/mingw-w64-port-scanner/PKGBUILD +++ b/mingw-w64-port-scanner/PKGBUILD @@ -17,8 +17,8 @@ source=("https://www.secpoint.com/freetools/threaded-port-scanner-${pkgver}.zip" "paths.patch" "0001-use-CC-from-environment.patch") sha256sums=('768c595fba7ba7e81da35e1bba1118bf08a1d689c6e419804d2109fc64177436' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' 'e27fad5161752247259e271c30aa49ea7eb18fd9f9b4f92553332c5cbb031db8' '66c18874119a4c36116f579f13b97aab538db399be61001f105a56ea1daeb03b') diff --git a/mingw-w64-port-scanner/pathtools.c b/mingw-w64-port-scanner/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-port-scanner/pathtools.c +++ b/mingw-w64-port-scanner/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-port-scanner/pathtools.h b/mingw-w64-port-scanner/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-port-scanner/pathtools.h +++ b/mingw-w64-port-scanner/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */ diff --git a/mingw-w64-swig/PKGBUILD b/mingw-w64-swig/PKGBUILD index e34d725ce7222..682562f6d8dbc 100644 --- a/mingw-w64-swig/PKGBUILD +++ b/mingw-w64-swig/PKGBUILD @@ -22,8 +22,8 @@ source=(https://downloads.sourceforge.net/${_realname}/${_realname}-${pkgver}.ta 001-relocate.patch 002-fix-python-find.patch) sha256sums=('2af08aced8fcd65cdb5cc62426768914bedc735b1c250325203716f78e39ac9b' - '08209cbf1633fa92eae7e5d28f95f8df9d6184cc20fa878c99aec4709bb257fd' - '965d3921ec4fdeec94a2718bc2c85ce5e1a00ea0e499330a554074a7ae15dfc6' + 'ebf471173f5ee9c4416c10a78760cea8afaf1a4a6e653977321e8547ce7bf3c0' + 'e1944d0dcd7837cb25c31832e785c6176916cd42a446ca2f9057a450afafab4a' 'a27041d7b13a17547f8a534d80c370a9e689f8f2784d150fc755cbb91382dac4' '057f0a306aee0d28a5bb6538b569c650e47c05b9848c9477cdeb7bb8c792944d') diff --git a/mingw-w64-swig/pathtools.c b/mingw-w64-swig/pathtools.c index 0a873026215b1..84b9ea1bdb14e 100644 --- a/mingw-w64-swig/pathtools.c +++ b/mingw-w64-swig/pathtools.c @@ -39,7 +39,7 @@ #include "pathtools.h" -char * +static char * malloc_copy_string(char const * original) { char * result = (char *) malloc (sizeof (char*) * strlen (original)+1); @@ -361,7 +361,7 @@ get_dll_path(char * result, unsigned long max_size) } #endif -char const * +static char const * strip_n_prefix_folders(char const * path, size_t n) { if (path == NULL) @@ -404,7 +404,7 @@ strip_n_suffix_folders(char * path, size_t n) return; } -size_t +static size_t split_path_list(char const * path_list, char split_char, char *** arr) { size_t path_count; @@ -586,42 +586,55 @@ single_path_relocation_lib(const char *from, const char *to) #endif } -char * -pathlist_relocation(const char *from_path, const char *to_path_list) +char const * +msys2_get_relocated_single_path(char const * unix_path) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) - { - char const * relocated = get_relocated_path_list(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; - } - return stored_path; -#else - return (to_path_list); -#endif + char * unix_part = (char *) strip_n_prefix_folders (unix_path, 1); + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + char * new_path = (char *) malloc (strlen (unix_part) + strlen (win_part) + 1); + strcpy (new_path, win_part); + strcat (new_path, unix_part); + return new_path; } char * -pathlist_relocation_lib(const char *from_path, const char *to_path_list) +msys2_get_relocated_path_list(char const * paths) { -#if defined(__MINGW32__) - static char stored_path[PATH_MAX]; - static int stored = 0; - if (stored == 0) + char win_part[MAX_PATH]; + get_executable_path (NULL, &win_part[0], MAX_PATH); + strip_n_suffix_folders (&win_part[0], 2); /* 2 because the file name is present. */ + + char **arr = NULL; + + size_t count = split_path_list (paths, ':', &arr); + int result_size = 1 + (count - 1); /* count - 1 is for ; delim. */ + size_t i; + for (i = 0; i < count; ++i) { - char const * relocated = get_relocated_path_list_lib(from_path, to_path_list); - strncpy (stored_path, relocated, PATH_MAX); - stored_path[PATH_MAX-1] = '\0'; - free ((void *)relocated); - stored = 1; + arr[i] = (char *) strip_n_prefix_folders (arr[i], 1); + result_size += strlen (arr[i]) + strlen (win_part); } - return stored_path; + char * result = (char *) malloc (result_size); + if (result == NULL) + { + return NULL; + } + result[0] = '\0'; + for (i = 0; i < count; ++i) + { + strcat (result, win_part); + strcat (result, arr[i]); + if (i != count-1) + { +#if defined(_WIN32) + strcat (result, ";"); #else - return (to_path_list); + strcat (result, ":"); #endif + } + } + free ((void*)arr); + return result; } diff --git a/mingw-w64-swig/pathtools.h b/mingw-w64-swig/pathtools.h index fca987b2e5c1e..af2f129483885 100644 --- a/mingw-w64-swig/pathtools.h +++ b/mingw-w64-swig/pathtools.h @@ -11,26 +11,18 @@ #ifndef PATHTOOLS_H #define PATHTOOLS_H -#include -#if defined(__APPLE__) -#include -#else -#include -#endif -#include - -char * malloc_copy_string(char const * original); +#include +#include -/* In-place replaces any '\' with '/' and any '//' with '/' */ -void sanitise_path(char * path); +#ifdef __cplusplus +extern "C" { +#endif /* Uses a host OS specific function to determine the path of the executable, if IMPLEMENT_SYS_GET_EXECUTABLE_PATH is defined, otherwise uses argv0. */ int get_executable_path(char const * argv0, char * result, ssize_t max_size); -#if defined(_WIN32) int get_dll_path(char * result, unsigned long max_size); -#endif /* Where possible, in-place removes occourances of '.' and 'path/..' */ void simplify_path(char * path); @@ -38,22 +30,33 @@ void simplify_path(char * path); /* Allocates (via malloc) and returns the path to get from from to to. */ char * get_relative_path(char const * from, char const * to); -size_t split_path_list(char const * path_list, char split_char, char *** arr); - -/* Advances path along by the amount that removes n prefix folders. */ -char const * -strip_n_prefix_folders(char const * path, size_t n); - /* NULL terminates path to remove n suffix folders. */ -void -strip_n_suffix_folders(char * path, size_t n); +void strip_n_suffix_folders(char * path, size_t n); char * get_relocated_path_list(char const * from, char const * to_path_list); char * get_relocated_path_list_lib(char const * from, char const * to_path_list); char * single_path_relocation(const char *from, const char *to); char * single_path_relocation_lib(const char *from, const char *to); -char * pathlist_relocation(const char *from_path, const char *to_path_list); -char * pathlist_relocation_lib(const char *from_path, const char *to_path_list); + +/* Allocates (via malloc) and returns a relocated path from a single Unix path. + This function makes large assumptions regarding PREFIX and is therefore very + much an MSYS2-only function. It operates by removing the first folder of the + input and final folder of the program executable then appending the input to + that. +*/ +char const * msys2_get_relocated_single_path(char const * unix_path); + +/* Allocates (via malloc) and for each ':' delimited Unix sub-path, returns the + result of applying the procedure detailed for msys2_get_relocated_single_path + on that Unix sub-path with the results joined up again with a ';' delimiter. + It implements the same logic in msys2_get_relocated_single_path to reduce the + the number of mallocs. +*/ +char * msys2_get_relocated_path_list(char const * paths); + +#ifdef __cplusplus +} +#endif #endif /* PATHTOOLS_H */