Merge branch 'upstream-KWSys' into update-kwsys

# By KWSys Upstream
* upstream-KWSys:
  KWSys 2024-10-28 (c87126a2)
This commit is contained in:
Brad King
2024-10-28 09:35:12 -04:00
2 changed files with 6 additions and 21 deletions

View File

@@ -666,14 +666,14 @@ int kwsysProcess_SetWorkingDirectory(kwsysProcess* cp, const char* dir)
if (dir && dir[0]) {
wchar_t* wdir = kwsysEncoding_DupToWide(dir);
/* We must convert the working directory to a full path. */
DWORD length = GetFullPathNameW(wdir, 0, 0, 0);
DWORD length = GetFullPathNameW(wdir, 0, NULL, NULL);
if (length > 0) {
wchar_t* work_dir = malloc(length * sizeof(wchar_t));
if (!work_dir) {
free(wdir);
return 0;
}
if (!GetFullPathNameW(wdir, length, work_dir, 0)) {
if (!GetFullPathNameW(wdir, length, work_dir, NULL)) {
free(work_dir);
free(wdir);
return 0;

View File

@@ -59,9 +59,6 @@
#include <cctype>
#include <cerrno>
#ifdef __QNX__
# include <malloc.h> /* for malloc/free on QNX */
#endif
#include <cstdio>
#include <cstdlib>
#include <cstring>
@@ -338,10 +335,9 @@ inline void Realpath(const std::string& path, std::string& resolved_path,
std::string* errorMessage = nullptr)
{
std::wstring tmp = KWSYS_NAMESPACE::Encoding::ToWide(path);
wchar_t* ptemp;
wchar_t fullpath[MAX_PATH];
DWORD bufferLen = GetFullPathNameW(
tmp.c_str(), sizeof(fullpath) / sizeof(fullpath[0]), fullpath, &ptemp);
tmp.c_str(), sizeof(fullpath) / sizeof(fullpath[0]), fullpath, nullptr);
if (bufferLen < sizeof(fullpath) / sizeof(fullpath[0])) {
resolved_path = KWSYS_NAMESPACE::Encoding::ToNarrow(fullpath);
KWSYS_NAMESPACE::SystemTools::ConvertToUnixSlashes(resolved_path);
@@ -824,25 +820,14 @@ static int kwsysUnPutEnv(const std::string& env)
#elif defined(__CYGWIN__) || defined(__GLIBC__)
/* putenv("A") removes A from the environment. It must not put the
memory in the environment because it does not have any "=" syntax. */
static int kwsysUnPutEnv(const std::string& env)
{
int err = 0;
size_t pos = env.find('=');
size_t const len = pos == std::string::npos ? env.size() : pos;
size_t const sz = len + 1;
char local_buf[256];
char* buf = sz > sizeof(local_buf) ? (char*)malloc(sz) : local_buf;
if (!buf) {
return -1;
}
strncpy(buf, env.c_str(), len);
buf[len] = 0;
if (putenv(buf) < 0 && errno != EINVAL) {
std::string buf = env.substr(0, env.find('='));
if (putenv(&buf[0]) < 0 && errno != EINVAL) {
err = errno;
}
if (buf != local_buf) {
free(buf);
}
if (err) {
errno = err;
return -1;