17 #ifndef COM_BORA_SOFTWARE__BALAU_UTIL__USER 18 #define COM_BORA_SOFTWARE__BALAU_UTIL__USER 37 const uid_t uid = geteuid();
38 const passwd * pw = getpwuid(uid);
41 return std::string(pw->pw_name);
45 ,
"Failed to obtain the user name: user entry not found in passwd." 48 #elif BOOST_OS_WINDOWS 49 #error "The Windows platform is not yet implemented." 51 #error "Platform not implemented." 63 const char * home = std::getenv(
"HOME");
72 size_t bufferSize = 512;
73 std::vector<char> buffer(bufferSize);
77 s = getpwuid_r(getuid(), &pwd, buffer.data(), bufferSize, &result);
79 if (result ==
nullptr) {
83 ,
"Failed to locate the user home directory: user entry not found in passwd." 85 }
else if (errno == ERANGE) {
87 if (bufferSize >= 1048576) {
90 ,
"Failed to locate the user home directory with buffer size of 1MB." 95 buffer.resize(bufferSize, 0);
100 ,
"Failed to locate the user home directory: getpwnam_r raised an error, errno = " +
107 if (result ==
nullptr || result->pw_dir ==
nullptr) {
110 , ::
toString(
"Failed to locate the user home directory: getpwnam_r raised an error, errno = ", errno)
115 #elif BOOST_OS_WINDOWS 116 #error "The Windows platform is not yet implemented." 119 const char * up = std::getenv(
"USERPROFILE");
125 const char * hd = std::getenv(
"HOMEDRIVE");
126 const char * hp = std::getenv(
"HOMEPATH");
128 if (hd !=
nullptr && hp !=
nullptr && !
Util::Strings::trim(hd).empty() && !std::string(hp).empty()) {
133 #error "Platform not implemented." 141 User & operator = (
const User &) =
delete;
146 #endif // COM_BORA_SOFTWARE__BALAU_UTIL__USER U8String< AllocatorT > toString(const ZipEntryInfo &info)
Print the zip entry info as a UTF-8 string.
Definition: Zip.hpp:113
A file on the local file system.
#define ThrowBalauException(ExceptionClass,...)
Throw a Balau style exception, with implicit file and line number, and optional stacktrace.
Definition: BalauException.hpp:45
static std::string getUserName()
Get the name of the user running the process.
Definition: User.hpp:35
static Resource::File getHomeDirectory()
Get the home directory of the user running the process.
Definition: User.hpp:60
Utilities for accessing user information.
Definition: User.hpp:30
static std::string_view trim(const std::string_view &input)
Trim whitespace from the beginning and end of the supplied UTF-8 string.
Definition: Strings.hpp:706
Thrown when a resource is not found.
Definition: ResourceExceptions.hpp:48
A file on the local file system.
Definition: File.hpp:35
Balau exceptions for resources.