[clang-tools-extra] [clang] [llvm] [flang] [flang] GETLOG runtime and extension implementation: get login username (PR #74628)

Yi Wu via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 6 11:06:21 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:

Good idea, changed.

https://github.com/llvm/llvm-project/pull/74628


More information about the cfe-commits mailing list