[llvm] [clang-tools-extra] [flang] [clang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)
yi-wu-arm wrote: > This patch broke the Solaris build: > > ``` > FAILED: > tools/flang/runtime/CMakeFiles/obj.FortranRuntime.dir/extensions.cpp.o > [...] > /vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:24: error: > use of undeclared identifier 'LOGIN_NAME_MAX' >60 | const int nameMaxLen{LOGIN_NAME_MAX + 1}; > |^ > /vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: warning: > variable length arrays in C++ are a Clang extension [-Wvla-cxx-extension] >61 | char str[nameMaxLen]; > |^~ > /vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:61:12: note: > initializer of 'nameMaxLen' is unknown > /vol/llvm/src/llvm-project/dist/flang/runtime/extensions.cpp:60:13: note: > declared here >60 | const int nameMaxLen{LOGIN_NAME_MAX + 1}; > | ^ > 1 warning and 1 error generated. > ``` > > and > > ``` > FAILED: > tools/flang/unittests/Runtime/CMakeFiles/FlangRuntimeTests.dir/CommandTest.cpp.o > [...] > /vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:21: > error: use of undeclared identifier 'LOGIN_NAME_MAX' > 530 | const int charLen{LOGIN_NAME_MAX + 2}; > | ^ > /vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: > warning: variable length arrays in C++ are a Clang extension > [-Wvla-cxx-extension] > 531 | char input[charLen]; > | ^~~ > /vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:531:14: > note: initializer of 'charLen' is unknown > /vol/llvm/src/llvm-project/dist/flang/unittests/Runtime/CommandTest.cpp:530:13: > note: declared here > 530 | const int charLen{LOGIN_NAME_MAX + 2}; > | ^ > ``` > > As documented in Solaris `limits.h(3HEAD)` (and exactly matching XPG7), > `LOGIN_NAME_MAX` not being defined is an allowed configuration: > > ``` >Runtime Invariant Values (Possibly Indeterminate) >A definition of one of the symbolic names in the following list is >omitted fromon specific implementations where the corre- >sponding value is equal to or greater than the stated minimum, but is >unspecified. > >This indetermination might depend on the amount of available memory >space on a specific instance of a specific implementation. The actual >value supported by a specific instance will be provided by the >sysconf() function. > [...] >LOGIN_NAME_MAX > >Maximum length of a login name. > ``` > > So the code needs to fall back to `sysconf(_SC_LOGIN_NAME_MAX)` if > `LOGIN_NAME_MAX` is not defined. > > I've used the attached patch to implement this, which allowed the build and > `ninja check-all` to finish. I'm uncertain if support for `syscconf() == -1` > is really necessary, though. > [lnm.txt](https://github.com/llvm/llvm-project/files/13887475/lnm.txt) Thanks for reporting and providing a fix for this. I do not have a Solaris instance on hand to test it, so if you don't mind, could you send this out as a pull request? https://github.com/llvm/llvm-project/pull/74628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [flang] [clang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)
https://github.com/jeanPerier approved this pull request. https://github.com/llvm/llvm-project/pull/74628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [flang] [clang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)
@@ -6,6 +6,37 @@ // //===--===// +// character.h DavidTruby wrote: nit: `string.h` instead? This is really dealing with c-style strings rather than characters https://github.com/llvm/llvm-project/pull/74628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[llvm] [clang-tools-extra] [flang] [clang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)
@@ -10,10 +10,52 @@ // extensions that will eventually be implemented in Fortran. #include "flang/Runtime/extensions.h" +#include "terminator.h" +#include "flang/Runtime/character.h" #include "flang/Runtime/command.h" #include "flang/Runtime/descriptor.h" #include "flang/Runtime/io-api.h" +#ifdef _WIN32 +#define WIN32_LEAN_AND_MEAN +#define NOMINMAX +#include + +#include // wcstombs_s +#include // UNLEN=256 +#include // wchar_t cast to LPWSTR +#pragma comment(lib, "Advapi32.lib") // Link Advapi32.lib for GetUserName +#define LOGIN_NAME_MAX UNLEN + +inline int getlogin_r(char *buf, size_t bufSize) { + wchar_t w_username[UNLEN + 1]; + DWORD nameLen{UNLEN + 1}; + + if (GetUserName(w_username, )) { +// Convert the wchar_t string to a regular C string using wcstombs_s +if (wcstombs_s(nullptr, buf, bufSize, w_username, _TRUNCATE) != 0) { + // Conversion failed + return -1; +} +return (buf[0] == 0 ? -1 : 0); + } else { +return -1; + } + return -1; klausler wrote: This line will never be reached. https://github.com/llvm/llvm-project/pull/74628 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits