================ @@ -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 <windows.h> + +#include <cstdlib> // wcstombs_s +#include <lmcons.h> // UNLEN=256 +#include <wchar.h> // 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, &nameLen)) { + // 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); ---------------- klausler wrote:
Please write the NUL character as a character literal (`'\0'`). The parentheses are needless. 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