mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-10 13:00:29 +03:00
7f25959fa2
This API was returning a "const char*" and it was unclear who took care of the underlying memory. Returning a String makes that obvious. Also make sure we close the /etc/passwd file when we're done with it.
16 lines
300 B
C++
16 lines
300 B
C++
#include "CUserInfo.h"
|
|
#include <pwd.h>
|
|
#include <stdlib.h>
|
|
#include <unistd.h>
|
|
|
|
String get_current_user_home_path()
|
|
{
|
|
if (auto* home_env = getenv("HOME"))
|
|
return home_env;
|
|
|
|
auto* pwd = getpwuid(getuid());
|
|
String path = pwd ? pwd->pw_dir : "/";
|
|
endpwent();
|
|
return path;
|
|
}
|