Skip to content

Commit

Permalink
fix(Foundation): minor code cleanup. #2282
Browse files Browse the repository at this point in the history
  • Loading branch information
matejk committed Dec 4, 2023
1 parent ccf4fc4 commit 74232e3
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
12 changes: 6 additions & 6 deletions Foundation/src/Path_UNIX.cpp
Expand Up @@ -35,18 +35,18 @@


#ifndef PATH_MAX
#define PATH_MAX 1024 // fallback
#define PATH_MAX 4096 // fallback
#endif


namespace Poco {

std::string PathImpl::selfImpl()
{
std::string path;
char buf[PATH_MAX + 1] {0};

#if POCO_OS == POCO_OS_MAC_OS_X
uint32_t size = sizeof(buf);
std::uint32_t size = sizeof(buf);
if (_NSGetExecutablePath(buf, &size) == 0)
path = buf;
#elif POCO_OS == POCO_OS_FREE_BSD
Expand All @@ -55,11 +55,11 @@ std::string PathImpl::selfImpl()
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
size_t size = sizeof(buf);
std::size_t size = sizeof(buf);
if (sysctl(mib, 4, buf, &size, NULL, 0) == 0)
path = buf;
#elif POCO_OS == POCO_OS_NET_BSD
size_t size = sizeof(buf);
std::size_t size = sizeof(buf);
int n = readlink("/proc/curproc/exe", buf, size);
if (n > 0 && n < PATH_MAX)
path = buf;
Expand All @@ -68,7 +68,7 @@ std::string PathImpl::selfImpl()
if (execName)
path = execName;
#elif POCO_OS == POCO_OS_LINUX || POCO_OS == POCO_OS_ANDROID
size_t size = sizeof(buf);
const std::size_t size = sizeof(buf);
int n = readlink("/proc/self/exe", buf, size);
if (n > 0 && n < PATH_MAX)
path = buf;
Expand Down
10 changes: 3 additions & 7 deletions Foundation/src/Path_WIN32U.cpp
Expand Up @@ -19,19 +19,15 @@
#include "Poco/Exception.h"
#include "Poco/UnWindows.h"

#ifndef PATH_MAX
#define PATH_MAX 1024 // fallback
#endif

namespace Poco {

std::string PathImpl::selfImpl()
{
std::string path;
Buffer<wchar_t> buf(PATH_MAX);
DWORD n = GetModuleFileNameW(NULL, buf.begin(), PATH_MAX);
Buffer<wchar_t> buf(MAX_PATH_LEN);
DWORD n = GetModuleFileNameW(NULL, buf.begin(), MAX_PATH_LEN);

if (n > 0 && n < PATH_MAX)
if (n > 0 && n < MAX_PATH_LEN)
UnicodeConverter::toUTF8(buf.begin(), path);
return path;
}
Expand Down

0 comments on commit 74232e3

Please sign in to comment.