-// Copyright (C) 2007-2016 CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2023 CEA, EDF, OPEN CASCADE
//
// This library is free software; you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public
#include <execinfo.h>
#endif
+#include <memory>
+#include <functional>
namespace Kernel_Utils
{
std::string encode_s(const wchar_t* decoded)
{
- return std::string(encode(decoded));
+ std::unique_ptr<char,std::function<void(char*)>> tmp((char *)encode(decoded),[](char *ptr) { delete [] ptr; });
+ return std::string(tmp.get());
}
#ifndef WIN32
{
std::stringstream sstr;
sstr<<name<<'='<<value;
- if(rewrite || std::string(getenv(name)).length() == 0)
+ if(rewrite || getenv(name) == nullptr || std::string(getenv(name)).length() == 0)
return _putenv(sstr.str().c_str());
else return -1;
}
char* utf8_encode(const wchar_t* encoded)
{
if (encoded == NULL) return NULL;
- int size_needed = WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), NULL, 0, NULL, NULL);
+ auto size_needed = WideCharToMultiByte(CP_UTF8, 0, encoded, (int)std::wcslen(encoded), NULL, 0, NULL, NULL);
char* strTo = new char[ size_needed + 1 ];
- WideCharToMultiByte(CP_UTF8, 0, encoded, std::wcslen(encoded), strTo, size_needed, NULL, NULL);
+ WideCharToMultiByte(CP_UTF8, 0, encoded, (int)std::wcslen(encoded), strTo, size_needed, NULL, NULL);
strTo[size_needed] = '\0';
return strTo;
}
wchar_t* utf8_decode(const char* decoded)
{
if (decoded == NULL) return NULL;
- int size_needed = MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), NULL, 0);
+ auto size_needed = MultiByteToWideChar(CP_UTF8, 0, decoded, (int)strlen(decoded), NULL, 0);
wchar_t* wstrTo = new wchar_t[ size_needed + 1 ];
- MultiByteToWideChar(CP_UTF8, 0, decoded, strlen(decoded), wstrTo, size_needed);
+ MultiByteToWideChar(CP_UTF8, 0, decoded, (int)strlen(decoded), wstrTo, size_needed);
wstrTo[size_needed] = '\0';
return wstrTo;
}