watch: use sysconf() for hostname length __ (catch up)

--------------- Original Master Branch Commit Message:
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 e564ddcb01
 procps-ng/procps#54

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2018-04-11 00:00:00 -05:00 committed by Craig Small
parent 583472be8b
commit 39980d6e31
1 changed files with 2 additions and 1 deletions

View File

@ -380,7 +380,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));