alinaliBQ commented on code in PR #40939: URL: https://github.com/apache/arrow/pull/40939#discussion_r2035903643
########## cpp/src/arrow/flight/sql/odbc/odbcabstraction/whereami.cc: ########## @@ -0,0 +1,675 @@ +// (‑●‑●)> dual licensed under the WTFPL v2 and MIT licenses +// without any warranty. +// by Gregory Pakosz (@gpakosz) +// https://github.com/gpakosz/whereami +// Copyright 2024 Gregory Pakosz + +// in case you want to #include "whereami.c" in a larger compilation unit +#if !defined(WHEREAMI_H) +# include "whereami.h" +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +#if defined(__linux__) || defined(__CYGWIN__) +# undef _DEFAULT_SOURCE +# define _DEFAULT_SOURCE +#elif defined(__APPLE__) +# undef _DARWIN_C_SOURCE +# define _DARWIN_C_SOURCE +# define _DARWIN_BETTER_REALPATH +#endif + +#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC) +# include <stdlib.h> +#endif + +#if !defined(WAI_MALLOC) +# define WAI_MALLOC(size) malloc(size) +#endif + +#if !defined(WAI_FREE) +# define WAI_FREE(p) free(p) +#endif + +#if !defined(WAI_REALLOC) +# define WAI_REALLOC(p, size) realloc(p, size) +#endif + +#ifndef WAI_NOINLINE +# if defined(_MSC_VER) +# define WAI_NOINLINE __declspec(noinline) +# elif defined(__GNUC__) +# define WAI_NOINLINE __attribute__((noinline)) +# else +# error unsupported compiler +# endif +#endif + +#if defined(_MSC_VER) +# define WAI_RETURN_ADDRESS() _ReturnAddress() +#elif defined(__GNUC__) +# define WAI_RETURN_ADDRESS() __builtin_extract_return_addr(__builtin_return_address(0)) +#else +# error unsupported compiler +#endif + +#if defined(_WIN32) + +# ifndef WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +# endif +# if defined(_MSC_VER) +# pragma warning(push, 3) +# endif +# include <intrin.h> +# include <windows.h> +# if defined(_MSC_VER) +# pragma warning(pop) +# endif +# include <stdbool.h> + +static int WAI_PREFIX(getModulePath_)(HMODULE module, char* out, int capacity, + int* dirname_length) { + wchar_t buffer1[MAX_PATH]; + wchar_t buffer2[MAX_PATH]; + wchar_t* path = NULL; + int length = -1; + bool ok; + + for (ok = false; !ok; ok = true) { + DWORD size; + int length_, length__; + + size = GetModuleFileNameW(module, buffer1, sizeof(buffer1) / sizeof(buffer1[0])); + + if (size == 0) { + // no-op + } + break; + } else if (size == (DWORD)(sizeof(buffer1) / sizeof(buffer1[0]))) { + DWORD size_ = size; + do { + wchar_t* path_; + + path_ = (wchar_t*)WAI_REALLOC(path, sizeof(wchar_t) * size_ * 2); + if (!path_) break; + size_ *= 2; + path = path_; + size = GetModuleFileNameW(module, path, size_); + } while (size == size_); + + if (size == size_) break; + } else { Review Comment: ```suggestion } else { ``` nit - from [CI Checks](https://github.com/apache/arrow/actions/runs/14362316249/job/40266696240?pr=40939#step:6:1711) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org