Skip to content

Commit

Permalink
No HOST_NAME_MAX.
Browse files Browse the repository at this point in the history
  • Loading branch information
floitsch committed Oct 23, 2024
1 parent 064dc15 commit c3af100
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/primitive_core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2577,11 +2577,14 @@ PRIMITIVE(hostname) {
#ifdef TOIT_ESP32
name = CONFIG_LWIP_LOCAL_HOSTNAME;
#else
char buffer[HOST_NAME_MAX + 1];
// HOST_NAME_MAX (set to 64 on my system) is not available on all platforms.
// We use a reasonable default.
char buffer[256];
int result = gethostname(buffer, sizeof(buffer));
if (result != 0) {
return Primitive::os_error(errno, process);
}
buffer[sizeof(buffer) - 1] = '\0';
name = buffer;
#endif
return process->allocate_string_or_error(name);
Expand Down

0 comments on commit c3af100

Please sign in to comment.