5 #if defined(I_UNISTD) && defined(HAS_GETHOSTNAME)
9 /* a reasonable default */
10 #ifndef MAXHOSTNAMELEN
11 # define MAXHOSTNAMELEN 256
14 /* swiped from POSIX.xs */
15 #if defined(__VMS) && !defined(__POSIX_SOURCE)
16 # if ((__VMS_VER >= 70000000) && (__DECC_VER >= 50200000)) || (__CRTL_VER >= 70000000)
22 # include <sys/utsname.h>
25 MODULE = Sys::Hostname PACKAGE = Sys::Hostname
34 #ifdef HAS_GETHOSTNAME
36 char tmps[MAXHOSTNAMELEN];
37 retval = PerlSock_gethostname(tmps, sizeof(tmps));
38 sv = newSVpvn(tmps, strlen(tmps));
44 char tmps[MAXHOSTNAMELEN];
47 io = PerlProc_popen(PHOSTNAME, "r");
50 while (PerlIO_read(io, &c, sizeof(c)) == 1) {
51 if (isSPACE(c) || p - tmps >= sizeof(tmps))
58 sv = newSVpvn(tmps, strlen(tmps));
64 if (PerlEnv_uname(&u) == -1)
66 sv = newSVpvn(u.nodename, strlen(u.nodename));
72 #ifndef HAS_GETHOSTNAME
78 PUSHs(sv_2mortal(sv));