bpo-28441: Ensure `.exe` suffix in `sys.executable` on MinGW and Cygwin by embray · Pull Request #4348 · python/cpython
#if defined(__CYGWIN__) || defined(__MINGW32__) /* add_exe_suffix requires that progpath be allocated at least MAXPATHLEN + 1 bytes. */
#ifndef EXE_SUFFIX #define EXE_SUFFIX L".exe" #endif
static void add_exe_suffix(wchar_t *progpath) { /* Check for already have an executable suffix */ size_t n = wcslen(progpath); size_t s = wcslen(EXE_SUFFIX); if (wcsncasecmp(EXE_SUFFIX, progpath+n-s, s) != 0) { if (n + s > MAXPATHLEN) { Py_FatalError("progpath overflow in getpath.c's add_exe_suffix()"); } /* Save original path for revert */ wchar_t orig[MAXPATHLEN+1]; wcsncpy(orig, progpath, MAXPATHLEN);
wcsncpy(progpath+n, EXE_SUFFIX, s); progpath[n+s] = '\0';
if (!isxfile(progpath)) { /* Path that added suffix is invalid */ wcsncpy(progpath, orig, MAXPATHLEN); } } } #endif
/* search_for_prefix requires that argv0_path be no more than MAXPATHLEN bytes long. */
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use brackets {} for new code.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I missed that update to PEP-7. Just as well. I don't like if statements without braces either.
config->program_full_path = _PyMem_RawWcsdup(program_full_path); if (config->program_full_path == NULL) {