Hostname: Difference between revisions

Add a Limbo version
m (Correctly alphabetize.)
(Add a Limbo version)
Line 284:
 
print CurrentComputerName$</lang>
 
=={{header|Limbo}}==
As with nearly anything in Inferno, it boils down to reading a file:
 
<lang Limbo>implement Hostname;
 
include "sys.m"; sys: Sys;
include "draw.m";
 
Hostname: module {
init: fn(nil: ref Draw->Context, nil: list of string);
};
 
init(nil: ref Draw->Context, nil: list of string)
{
sys = load Sys Sys->PATH;
# Technically, this program is wrong if the hostname is longer than 8k.
buf := array[Sys->ATOMICIO] of byte;
 
fd := sys->open("/dev/sysname", Sys->OREAD);
if(fd == nil)
die("Couldn't open /dev/sysname");
 
n := sys->read(fd, buf, len buf - 1);
if(n < 1)
die("Couldn't read /dev/sysname");
 
buf[n++] = byte '\n';
sys->write(sys->fildes(1), buf, n);
}
 
die(s: string)
{
sys->fprint(sys->fildes(2), "hostname: %s: %r", s);
raise "fail:errors";
}
</lang>
 
 
=={{header|Lua}}==
32

edits