From eecfa75cb57f0eb52c7d7bf91d60e2a32773a364 Mon Sep 17 00:00:00 2001 From: Mirek Fidler Date: Thu, 23 Jul 2026 13:20:03 +0200 Subject: [PATCH] Core: GetUserName posix variant fixed, StdLogSetup now calls SyncLogPath when filepath is empty. --- uppsrc/Core/App.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/uppsrc/Core/App.cpp b/uppsrc/Core/App.cpp index 16ff93559..58af510f2 100644 --- a/uppsrc/Core/App.cpp +++ b/uppsrc/Core/App.cpp @@ -23,6 +23,8 @@ #undef CY #endif +#include + namespace Upp { static StaticMutex sHlock; @@ -719,10 +721,15 @@ String GetUserName() ::GetUserNameW(temp, &w); return temp; #else - char user[1000]; - if(getlogin_r(user, 999)) - return user; - return Nvl(GetEnv("USER"), "root"); + size_t bsz = 1024; + Buffer buf(bsz); + struct passwd pwd; + struct passwd *result = NULL; + int rc; + while((rc = getpwuid_r(getuid(), &pwd, buf, bsz, &result)) == ERANGE) + buf.Alloc(bsz *= 2); + + return rc == 0 && result ? pwd.pw_name : ""; #endif }