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

via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 13 06:57:58 PST 2023


================
@@ -10,13 +10,29 @@
 // extensions that will eventually be implemented in Fortran.
 
 #include "flang/Runtime/extensions.h"
+#include "flang/Runtime/character.h"
 #include "flang/Runtime/command.h"
 #include "flang/Runtime/descriptor.h"
 #include "flang/Runtime/io-api.h"
 
+#if _REENTRANT || _POSIX_C_SOURCE >= 199506L
+// System is posix-compliant and has getlogin_r
+#include <unistd.h>
+#endif
+
 extern "C" {
 
 namespace Fortran::runtime {
+
+void GetUsernameEnvVar(
+    const char *envName, std::byte *arg, std::int64_t length) {
+  Descriptor name{
+      *Descriptor::Create(1, sizeof(envName), const_cast<char *>(envName), 0)};
----------------
jeanPerier wrote:

I think that when @klausler suggested using sizeof(), the type was a `char[n]`, here it is a `const char*` so I expect this will be 8 on 64bits machines which is OK by accident for `USERNAME`, but just wrong in general.

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


More information about the cfe-commits mailing list