[FFmpeg-devel] [PATCH v14 2/5] compat/w32dlfcn.h: Remove MAX_PATH limit and replace LoadLibraryExA with LoadLibraryExW
Soft Works
softworkz at hotmail.com
Mon Jun 13 19:39:16 EEST 2022
> -----Original Message-----
> From: ffmpeg-devel <ffmpeg-devel-bounces at ffmpeg.org> On Behalf Of Nil
> Admirari
> Sent: Monday, June 13, 2022 6:26 PM
> To: ffmpeg-devel at ffmpeg.org
> Subject: [FFmpeg-devel] [PATCH v14 2/5] compat/w32dlfcn.h: Remove
> MAX_PATH limit and replace LoadLibraryExA with LoadLibraryExW
>
> ---
> compat/w32dlfcn.h | 80 ++++++++++++++++++++++++++++++++++-------
> --
> libavcodec/mf_utils.h | 1 +
> 2 files changed, 65 insertions(+), 16 deletions(-)
>
> diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
> index 52a94efafb..e49d3841aa 100644
> --- a/compat/w32dlfcn.h
> +++ b/compat/w32dlfcn.h
> @@ -22,9 +22,31 @@
> #ifdef _WIN32
> #include <windows.h>
> #include "config.h"
> -#if (_WIN32_WINNT < 0x0602) || HAVE_WINRT
> #include "libavutil/wchar_filename.h"
> -#endif
> +
> +static inline wchar_t *get_module_filename(HMODULE module)
> +{
> + wchar_t *path = NULL, *new_path;
> + DWORD path_size = 0, path_len;
> +
> + do {
> + path_size = path_size ? 2 * path_size : MAX_PATH;
> + new_path = av_realloc_array(path, path_size, sizeof *path);
> + if (!new_path) {
> + av_free(path);
> + return NULL;
> + }
> + path = new_path;
> + path_len = GetModuleFileNameW(module, path, path_size);
> + } while (path_len && path_size <= 32768 && path_size <=
> path_len);
Why do you use a 'do' loop? Can't you use the normal 2-step
approach, i.e. call the winapi function with a NULL buffer,
and then use the returned size to allocate the buffer.
This way you always need a single allocation only.
softworkz
More information about the ffmpeg-devel
mailing list