[hackers] [sbase] Use HOST_NAME_MAX in hostname(1) || sin

From: <git_AT_suckless.org>
Date: Tue, 11 Feb 2014 12:01:54 +0100

commit 3bf464c1d62176a2f78924ff32b220d3893677bd
Author: sin <sin_AT_2f30.org>
Date: Tue Feb 11 10:59:53 2014 +0000

    Use HOST_NAME_MAX in hostname(1)

diff --git a/hostname.c b/hostname.c
index 4a377d9..5a8b2eb 100644
--- a/hostname.c
+++ b/hostname.c
_AT_@ -1,8 +1,9 @@
 /* See LICENSE file for copyright and license details. */
-#include <unistd.h>
+#include <limits.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include "util.h"
 
 static void
_AT_@ -14,7 +15,7 @@ usage(void)
 int
 main(int argc, char *argv[])
 {
- char buf[BUFSIZ];
+ char host[HOST_NAME_MAX + 1];
 
         ARGBEGIN {
         default:
_AT_@ -22,9 +23,9 @@ main(int argc, char *argv[])
         } ARGEND;
 
         if (argc < 1) {
- if (gethostname(buf, sizeof(buf)) < 0)
+ if (gethostname(host, sizeof(host)) < 0)
                         eprintf("gethostname:");
- puts(buf);
+ puts(host);
         } else {
                 if (sethostname(argv[0], strlen(argv[0])) < 0)
                         eprintf("sethostname:");
Received on Tue Feb 11 2014 - 12:01:54 CET

This archive was generated by hypermail 2.3.0 : Tue Feb 11 2014 - 12:12:23 CET