Hostname: Difference between revisions

Line 39:
 
{{works with|POSIX|.1}}
<lang c>#include <limitsstdlib.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("Hostname: %s\n", name) < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
gethostname(name, _POSIX_HOST_NAME_MAX+1);
return 0;
}</lang>
 
Anonymous user