MCPcopy Create free account
hub / github.com/ByConity/ByConity / getUserName

Function getUserName

programs/keeper/Keeper.cpp:165–183  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

163}
164
165std::string getUserName(uid_t user_id)
166{
167 /// Try to convert user id into user name.
168 auto buffer_size = sysconf(_SC_GETPW_R_SIZE_MAX);
169 if (buffer_size <= 0)
170 buffer_size = 1024;
171 std::string buffer;
172 buffer.reserve(buffer_size);
173
174 struct passwd passwd_entry;
175 struct passwd * result = nullptr;
176 const auto error = getpwuid_r(user_id, &passwd_entry, buffer.data(), buffer_size, &result);
177
178 if (error)
179 throwFromErrno("Failed to find user name for " + toString(user_id), ErrorCodes::FAILED_TO_GETPWUID, error);
180 else if (result)
181 return result->pw_name;
182 return toString(user_id);
183}
184
185}
186

Callers 5

mainMethod · 0.70
usedMethod · 0.50
checkExceededMethod · 0.50
checkAccessImplHelperMethod · 0.50

Calls 4

throwFromErrnoFunction · 0.85
toStringFunction · 0.50
reserveMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected