]> granicus.if.org Git - procps-ng/commitdiff
watch: use sysconf() for hostname length
authorCraig Small <csmall@enc.com.au>
Sat, 3 Mar 2018 07:36:44 +0000 (18:36 +1100)
committerCraig Small <csmall@enc.com.au>
Sat, 3 Mar 2018 07:36:44 +0000 (18:36 +1100)
Hurd doesn't have HOST_NAME_MAX, neither does Solaris.
An early fix just checked for this value and used 64 instead.
This change uses sysconf which is the correct method, possibly until
this compiles on some mis-behaving OS which doesn't have this value.

References:
 commit e564ddcb01c3c11537432faa9c7a7a6badb05930
 procps-ng/procps#54

watch.c

diff --git a/watch.c b/watch.c
index 048a4507db6e45c16fafd67b8207537889655cf0..c438178f82ee28427f3b2c477c8c2c4d0f54b53f 100644 (file)
--- a/watch.c
+++ b/watch.c
@@ -60,9 +60,6 @@
 # define isprint(x) ( (x>=' '&&x<='~') || (x>=0xa0) )
 #endif
 
-#ifndef HOST_NAME_MAX
-#define HOST_NAME_MAX 64
-#endif
 
 /* Boolean command line options */
 static int flags;
@@ -380,7 +377,8 @@ static void output_header(char *restrict command, double interval)
        char *ts = ctime(&t);
        char *header;
        char *right_header;
-       char hostname[HOST_NAME_MAX + 1];
+    int max_host_name_len = (int) sysconf(_SC_HOST_NAME_MAX);
+       char hostname[max_host_name_len + 1];
        int command_columns = 0;        /* not including final \0 */
 
        gethostname(hostname, sizeof(hostname));