Skip to content

[flang] Handle missing LOGIN_NAME_MAX definition in runtime #77775

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion flang/runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
// CALL GETLOG(USRNAME)
void FORTRAN_PROCEDURE_NAME(getlog)(std::byte *arg, std::int64_t length) {
#if _REENTRANT || _POSIX_C_SOURCE >= 199506L
const int nameMaxLen{LOGIN_NAME_MAX + 1};
int nameMaxLen;
#ifdef LOGIN_NAME_MAX
nameMaxLen = LOGIN_NAME_MAX + 1;
#else
nameMaxLen = sysconf(_SC_LOGIN_NAME_MAX) + 1;
if (nameMaxLen == -1)
nameMaxLen = _POSIX_LOGIN_NAME_MAX + 1;
#endif
char str[nameMaxLen];

int error{getlogin_r(str, nameMaxLen)};
Expand Down
9 changes: 8 additions & 1 deletion flang/unittests/Runtime/CommandTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,14 @@ TEST_F(EnvironmentVariables, GetlogGetName) {
#if _REENTRANT || _POSIX_C_SOURCE >= 199506L
TEST_F(EnvironmentVariables, GetlogPadSpace) {
// guarantee 1 char longer than max, last char should be pad space
const int charLen{LOGIN_NAME_MAX + 2};
int charLen;
#ifdef LOGIN_NAME_MAX
charLen = LOGIN_NAME_MAX + 2;
#else
charLen = sysconf(_SC_LOGIN_NAME_MAX) + 2;
if (charLen == -1)
charLen = _POSIX_LOGIN_NAME_MAX + 2;
#endif
char input[charLen];

FORTRAN_PROCEDURE_NAME(getlog)
Expand Down