Fix #19038 - making the Nim compiler work again on Windows XP (#19331)

* Update osenv.nim

* Update win_setenv.nim

* Update lib/pure/includes/osenv.nim

* Update lib/pure/includes/osenv.nim

* fixing cstring

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
This commit is contained in:
rockcavera 2022-01-07 04:26:55 -03:00 • committed by GitHub
commit c7d5b8c83d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 22 deletions

View file

@ -45,7 +45,7 @@ when not defined(nimscript):
proc c_getenv(env: cstring): cstring {.
importc: "getenv", header: "<stdlib.h>".}
when defined(windows):
proc c_putenv_s(envname: cstring, envval: cstring): cint {.importc: "_putenv_s", header: "<stdlib.h>".}
proc c_putenv(envstring: cstring): cint {.importc: "_putenv", header: "<stdlib.h>".}
from std/private/win_setenv import setEnvImpl
else:
proc c_setenv(envname: cstring, envval: cstring, overwrite: cint): cint {.importc: "setenv", header: "<stdlib.h>".}
@ -121,7 +121,8 @@ when not defined(nimscript):
]#
if key.len == 0 or '=' in key:
raise newException(OSError, "invalid key, got: " & key)
if c_putenv_s(key, "") != 0'i32: bail
let envToDel = key & "="
if c_putenv(cstring envToDel) != 0'i32: bail
else:
if c_unsetenv(key) != 0'i32: bail