[flang] [llvm] [flang] Implement external routine usage of hostnm() (PR #134900)

Eugene Epshteyn via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 8 14:32:45 PDT 2025


================
@@ -264,6 +264,38 @@ int RTNAME(Chdir)(const char *name) {
 #endif
 }
 
+int FORTRAN_PROCEDURE_NAME(hostnm)(char *hn, int length) {
+  std::int32_t status{0};
+
+  if (!hn || length < 0) {
+    return EINVAL;
+  }
+
+#ifdef _WIN32
+  DWORD dwSize{length};
+
+  // Note: Winsock has gethostname(), but use Win32 API GetComputerNameEx(),
+  // in order to avoid adding dependency on Winsock.
+  if (!GetComputerNameExA(ComputerNameDnsHostname, hn, &dwSize)) {
+    status = GetLastError();
+  }
+#else
+  if (gethostname(hn, length) < 0) {
+    status = errno;
+  }
+#endif
+
+  if (status == 0) {
+    // Find zero terminator and fill the string from the
+    // zero terminator to the end with spaces
+    char *str_end = hn + length;
----------------
eugeneepshteyn wrote:

Done

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


More information about the llvm-commits mailing list