Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace calls to putenv with setenv #18530

Merged
merged 7 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/pure/includes/osenv.nim
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ else:

proc c_getenv(env: cstring): cstring {.
importc: "getenv", header: "<stdlib.h>".}
proc c_putenv(env: cstring): cint {.
importc: "putenv", header: "<stdlib.h>".}
proc c_setenv(envname: cstring, envval: cstring, overwrite: cint): cint {.
importc: "setenv", header: "<stdlib.h>".}
proc c_unsetenv(env: cstring): cint {.
importc: "unsetenv", header: "<stdlib.h>".}
brightly-salty marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -221,7 +221,7 @@ else:
else:
if setEnvironmentVariableA(key, val) == 0'i32: raiseOSError(osLastError())
else:
if c_putenv(environment[indx]) != 0'i32:
if c_setenv(key, val, 1'i32) != 0'i32:
raiseOSError(osLastError())

proc delEnv*(key: string) {.tags: [WriteEnvEffect].} =
Expand Down
3 changes: 3 additions & 0 deletions tests/stdlib/tos.nim
Original file line number Diff line number Diff line change
Expand Up @@ -614,6 +614,9 @@ block osenv:
doAssert existsEnv(dummyEnvVar) == false
delEnv(dummyEnvVar) # deleting an already deleted env var
doAssert existsEnv(dummyEnvVar) == false
block: # putEnv, bug #18502
doAssertRaises(OSError): putEnv("DUMMY_ENV_VAR_PUT=DUMMY_VALUE", "NEW_DUMMY_VALUE")
doAssertRaises(OSError): putEnv("", "NEW_DUMMY_VALUE")
block:
doAssert getEnv("DUMMY_ENV_VAR_NONEXISTENT", "") == ""
doAssert getEnv("DUMMY_ENV_VAR_NONEXISTENT", " ") == " "
Expand Down