[flang-commits] [flang] GETLOG runtime and extension implementation: get login username (PR #70917)
David Truby via flang-commits
flang-commits at lists.llvm.org
Thu Nov 9 08:37:30 PST 2023
================
@@ -222,6 +253,22 @@ std::int32_t RTNAME(GetCommand)(const Descriptor *value,
return stat;
}
+std::int32_t RTNAME(GetLog)(const Descriptor *value, const Descriptor *errmsg) {
+ FillWithSpaces(*value);
+
+ const char *arg = getlogin();
----------------
DavidTruby wrote:
Can we use `getlogin_r` instead of `getlogin()`? getlogin isn't thread safe.
e.g:
```
std::array<char, LOGIN_NAME_MAX> arg;
int err = getlogin_r(arg.data(), arg.size());
if (err != 0) {
// error
}
// Shrink the string to the right length
std::string str(arg);
return CopyToDescriptor(*value, str.data(), str.size(), errmsg);
```
(I haven't tested this it's just an example)
Then we don't need the function local static on Windows either as we can emulate the getlogin_r interface there.
https://github.com/llvm/llvm-project/pull/70917
More information about the flang-commits
mailing list