Use HOST_NAME_MAX in hostname(1)
This commit is contained in:
parent
b0e4b45e3b
commit
3bf464c1d6
@ -1,8 +1,9 @@
|
|||||||
/* See LICENSE file for copyright and license details. */
|
/* See LICENSE file for copyright and license details. */
|
||||||
#include <unistd.h>
|
#include <limits.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <unistd.h>
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -14,7 +15,7 @@ usage(void)
|
|||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ];
|
char host[HOST_NAME_MAX + 1];
|
||||||
|
|
||||||
ARGBEGIN {
|
ARGBEGIN {
|
||||||
default:
|
default:
|
||||||
@ -22,9 +23,9 @@ main(int argc, char *argv[])
|
|||||||
} ARGEND;
|
} ARGEND;
|
||||||
|
|
||||||
if (argc < 1) {
|
if (argc < 1) {
|
||||||
if (gethostname(buf, sizeof(buf)) < 0)
|
if (gethostname(host, sizeof(host)) < 0)
|
||||||
eprintf("gethostname:");
|
eprintf("gethostname:");
|
||||||
puts(buf);
|
puts(host);
|
||||||
} else {
|
} else {
|
||||||
if (sethostname(argv[0], strlen(argv[0])) < 0)
|
if (sethostname(argv[0], strlen(argv[0])) < 0)
|
||||||
eprintf("sethostname:");
|
eprintf("sethostname:");
|
||||||
|
Loading…
Reference in New Issue
Block a user