[flang] Implement external routine usage of hostnm() (#134900)
Previously, `hostnm` extended intrinsic was implemented as proper intrinsic. Since then we found out that some applications use `hostnm` as external routine via `external hostnm`. This prevents `hostnm` from being recognized as an intrinsic. This PR implements `hostnm` as external routine.
This commit is contained in:
@@ -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{static_cast<DWORD>(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};
|
||||
char *str_zero{std::find(hn, str_end, '\0')};
|
||||
std::fill(str_zero, str_end, ' ');
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
int FORTRAN_PROCEDURE_NAME(ierrno)() { return errno; }
|
||||
|
||||
void FORTRAN_PROCEDURE_NAME(qsort)(int *array, int *len, int *isize,
|
||||
|
||||
Reference in New Issue
Block a user