diff options
author | Pixel <pixel@nobis-crew.org> | 2009-10-21 09:39:52 -0700 |
---|---|---|
committer | Pixel <pixel@nobis-crew.org> | 2009-10-21 09:39:52 -0700 |
commit | bb0a0a39834894207ddafd069371d5f54818ffc6 (patch) | |
tree | 56aad8771cade496c55f19997c1879b1396cbffd | |
parent | 615d4b72617c42d4c352724379cb1a4b866b0aea (diff) | |
parent | 213a25a18eae1bf57b93618b1b7bbd2fc36fde59 (diff) |
Merge branch 'master' of ssh+git://pixel@git.grumpycoder.net/pub/repo.git/Baltisot
-rw-r--r-- | lib/BLua.cc | 30 | ||||
-rw-r--r-- | lib/String.cc | 6 |
2 files changed, 29 insertions, 7 deletions
diff --git a/lib/BLua.cc b/lib/BLua.cc index b08223c..9bd7828 100644 --- a/lib/BLua.cc +++ b/lib/BLua.cc @@ -339,8 +339,22 @@ int LuaStatics::getenv(lua_State * _L) { if (n != 1) { L->error("Incorrect arguments to function `getenv'"); } - - L->push(::getenv(L->tostring(1).to_charp())); + +#ifdef _WIN32 + char buffer[BUFSIZ + 1]; + if (GetEnvironmentVariable(L->tostring(1).to_charp(), buffer, BUFSIZ)) { + L->push(buffer); + } else { + L->push(); + } +#else + char * var = ::getenv(L->tostring(1).to_charp()); + if (var) { + L->push(var); + } else { + L->push(); + } +#endif return 1; } @@ -352,8 +366,12 @@ int LuaStatics::setenv(lua_State * _L) { if (n != 2) { L->error("Incorrect arguments to function `setenv'"); } - + +#ifdef _WIN32 + SetEnvironmentVariable(L->tostring(1).to_charp(), L->tostring(2).to_charp()); +#else ::setenv(L->tostring(1).to_charp(), L->tostring(2).to_charp(), 1); +#endif return 0; } @@ -365,8 +383,12 @@ int LuaStatics::unsetenv(lua_State * _L) { if (n != 1) { L->error("Incorrect arguments to function `unsetenv'"); } - + +#ifdef _WIN32 + SetEnvironmentVariable(L->tostring(1).to_charp(), NULL); +#else ::unsetenv(L->tostring(1).to_charp()); +#endif return 0; } diff --git a/lib/String.cc b/lib/String.cc index aee7b8d..14195f6 100644 --- a/lib/String.cc +++ b/lib/String.cc @@ -155,7 +155,7 @@ const char * String::set(const char * s, va_list ap) { r = str; #else // !HAVE_VASPRINTF #ifdef HAVE_VSNPRINTF - char String::t[BUFSIZ + 1]; + char t[BUFSIZ + 1]; vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); #else // !HAVE_VSNPRINTF @@ -164,12 +164,12 @@ const char * String::set(const char * s, va_list ap) { r = str = (char *) malloc(_vscprintf(s, ap) + 1); vsprintf(str, s, ap); #else - char String::t[BUFSIZ + 1]; + char t[BUFSIZ + 1]; _vsnprintf(t, BUFSIZ, s, ap); str = Base::strdup(r = t); #endif #else - char String::t[BUFSIZ + 1]; + char t[BUFSIZ + 1]; vsprintf(t, s, ap); str = Base::strdup(r = t); #endif |