RosettaCodeData/Task/Hostname/C/hostname.c

11 lines
241 B
C
Raw Permalink Normal View History

2013-04-10 21:29:02 -07:00
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <unistd.h>
int main(void)
{
char name[_POSIX_HOST_NAME_MAX + 1];
return gethostname(name, sizeof name) == -1 || printf("%s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
}