Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions flang-rt/lib/runtime/extensions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,43 @@ int RTNAME(Chdir)(const char *name) {
#endif
}

int FORTRAN_PROCEDURE_NAME(hostnm)(char *hn, int length) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be a lot easier to read if it wasn't so needlessly stretched out vertically by all these blank lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed some blank lines.

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;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Always use braced initialization in the runtime and other modern C++ directories, please.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

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,
Expand Down
2 changes: 1 addition & 1 deletion flang/include/flang/Runtime/extensions.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ uid_t RTNAME(GetUID)();
void FORTRAN_PROCEDURE_NAME(getlog)(char *name, std::int64_t length);

// GNU extension subroutine HOSTNM(C)
void FORTRAN_PROCEDURE_NAME(hostnm)(char *name, std::int64_t length);
int FORTRAN_PROCEDURE_NAME(hostnm)(char *hn, int length);

std::intptr_t RTNAME(Malloc)(std::size_t size);

Expand Down
Loading