summaryrefslogtreecommitdiff
path: root/Libraries/LibCore
diff options
context:
space:
mode:
Diffstat (limited to 'Libraries/LibCore')
-rw-r--r--Libraries/LibCore/CUserInfo.cpp12
-rw-r--r--Libraries/LibCore/CUserInfo.h6
2 files changed, 10 insertions, 8 deletions
diff --git a/Libraries/LibCore/CUserInfo.cpp b/Libraries/LibCore/CUserInfo.cpp
index d5308d454e..4a232c3752 100644
--- a/Libraries/LibCore/CUserInfo.cpp
+++ b/Libraries/LibCore/CUserInfo.cpp
@@ -3,15 +3,13 @@
#include <stdlib.h>
#include <unistd.h>
-const char* get_current_user_home_path()
+String get_current_user_home_path()
{
if (auto* home_env = getenv("HOME"))
return home_env;
- auto d = "/";
- uid_t uid = getuid();
- if (auto* pwd = getpwuid(uid))
- return pwd->pw_dir;
-
- return d;
+ auto* pwd = getpwuid(getuid());
+ String path = pwd ? pwd->pw_dir : "/";
+ endpwent();
+ return path;
}
diff --git a/Libraries/LibCore/CUserInfo.h b/Libraries/LibCore/CUserInfo.h
index b47cec4af1..2c172098e6 100644
--- a/Libraries/LibCore/CUserInfo.h
+++ b/Libraries/LibCore/CUserInfo.h
@@ -1 +1,5 @@
-const char* get_current_user_home_path();
+#pragma once
+
+#include <AK/AKString.h>
+
+String get_current_user_home_path();