emilk / loguru

A lightweight C++ logging library
The Unlicense
1.79k stars 260 forks source link

Fix home_dir() for MinGW #131

Closed tstenner closed 3 years ago

tstenner commented 4 years ago

_dupenv_s isn't available when compiling with MinGW (e.g. #128). This PR retrieves the Windows-specific USERPROFILE environment variable with the default getenv function.

Tested with MinGW 7.3.0 and MSVC14.22.

legends2k commented 3 years ago

This patch can be simplified without introducing a new __MINGW32__ branch by simply changing #ifdef _WIN32 to #ifdef _MSC_VER.

The reason this patch is needed in the first place is because almost always loguru uses _WIN32 when _MSC_VER would be better i.e. checking for compiler is better than checking for a platform.

tstenner commented 3 years ago

@legends2k It can't, because the environment variable with the home directory path is USERPROFILE on Windows (Mingw32 + MSVC), but HOME everywhere else. The check could be split into two parts (WIN32->USERPROFILE/HOME, _MSC_VER->_dupenv_s/getenv), but that won't make it any shorter.

legends2k commented 3 years ago

@tstenner Agreed on the shorter part and about Windows having different $HOME. However, not introducing __MINGW32__ would be cleaner; MINGW's after all a Windows port of GCC.