[flang-commits] [clang-tools-extra] [llvm] [clang] [flang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)
Yi Wu via flang-commits
flang-commits at lists.llvm.org
Wed Dec 6 10:59:58 PST 2023
================
@@ -37,5 +79,34 @@ void FORTRAN_PROCEDURE_NAME(getarg)(
(void)RTNAME(GetCommandArgument)(
n, &value, nullptr, nullptr, __FILE__, __LINE__);
}
+
+// CALL GETLOG(USRNAME)
+void FORTRAN_PROCEDURE_NAME(getlog)(std::int8_t *arg, std::int64_t length) {
+ const int nameMaxLen{LOGIN_NAME_MAX + 1};
+ char str[nameMaxLen];
+
+ int error{getlogin_r(str, nameMaxLen)};
+ Terminator terminator{__FILE__, __LINE__};
+ if (error != 0) {
+ // if there is error, then get username from environment variable
+#ifdef _WIN32
+ const int charLen = 9;
+ char envName[charLen] = "USERNAME";
+#else
+ const int charLen = 8;
+ char envName[charLen] = "LOGNAME";
+#endif
+ std::size_t n{std::strlen(envName)};
----------------
yi-wu-arm wrote:
thanks for pointing this out, I will use `charLen` instead, since its there already.
https://github.com/llvm/llvm-project/pull/74628
More information about the flang-commits
mailing list