Core: GetUserName posix variant fixed, StdLogSetup now calls SyncLogPath when filepath is empty.

This commit is contained in:
Mirek Fidler 2026-07-23 13:20:03 +02:00
parent 924e5de34a
commit eecfa75cb5

View file

@ -23,6 +23,8 @@
#undef CY
#endif
#include <pwd.h>
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<char> 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
}