MVMString * MVM_io_get_hostname(MVMThreadContext *tc) { char hostname[MAXHOSTNAMELEN+1]; size_t size = MAXHOSTNAMELEN+1; int result = uv_os_gethostname(hostname, &size); if(result < 0) { MVM_exception_throw_adhoc(tc, "Failed to get hostname: %i", result); } return MVM_string_ascii_decode_nt(tc, tc->instance->VMString, hostname); }
static int luv_os_gethostname(lua_State* L) { #if LUV_UV_VERSION_GEQ(1, 26, 0) char hostname[UV_MAXHOSTNAMESIZE]; #else char hostname[PATH_MAX]; #endif size_t size = sizeof(hostname); int ret = uv_os_gethostname(hostname, &size); if (ret == 0) { lua_pushlstring(L, hostname, size); ret = 1; } else ret = luv_error(L, ret); return ret; }