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

add system.setenv #1706

Merged
merged 6 commits into from
Jan 22, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
system.setenv: use wide versions of functions on windows
  • Loading branch information
CosmicToast committed Jan 21, 2024
commit de24d338e86845d0d41e66a6d5b6c7d9c0b3cad1
7 changes: 4 additions & 3 deletions src/api/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <direct.h>
#include <windows.h>
#include <fileapi.h>
#include <processenv.h>
CosmicToast marked this conversation as resolved.
Show resolved Hide resolved
#include "../utfconv.h"

// Windows does not define the S_ISREG and S_ISDIR macros in stat.h, so we do.
Expand Down Expand Up @@ -1157,9 +1158,9 @@ static int f_setenv(lua_State* L) {

int ok; // unused: this could be used later to report success
#ifdef _WIN32
// I can't find documentation on whether SetEnvironmentVariable
// makes a copy of its arguments.
ok = SetEnvironmentVariable(key, val);
LPWSTR wkey = utfconv_utf8towc(key);
LPWSTR wval = utfconv_utf8towc(val);
CosmicToast marked this conversation as resolved.
Show resolved Hide resolved
CosmicToast marked this conversation as resolved.
Show resolved Hide resolved
ok = SetEnvironmentVariableW(wkey, wval);
#else
// right now we overwrite unconditionally
// this could be expanded later as an optional 3rd boolean argument
Expand Down
Loading