KWSys 2024-10-28 (c87126a2)

Code extracted from:

    https://gitlab.kitware.com/utils/kwsys.git

at commit c87126a29ffa83a2dc44dbd117121050f4628199 (master).

Upstream Shortlog
-----------------

scivision (3):
      3f14fce6 Process: Replace 0 with NULL in pointer arguments to GetFullPathNameW
      210cea0a SystemTools: Replace unused argument to GetFullPathNameW with nullptr
      f5e82d63 SystemTools: Replace malloc() with std::string
This commit is contained in:
KWSys Upstream authored and Brad King committed 2024-10-28 09:35:11 -04:00
1 parent acade348a7
commit 875cf5f61f
2 files changed
+6 -21

No files matched your search

+2 -2
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;
+4 -19
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;