]> Savannah Git Hosting - gnulib.git/commit
xgethostname: reorganize / simplify
authorPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Apr 2021 23:07:21 +0000 (16:07 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Sat, 3 Apr 2021 23:07:38 +0000 (16:07 -0700)
commitf30ed230ed479fb1de1cfabadad7b3905ec8b641
tree7a2fb09aed6aa752e73eae67f031bf2c11d2a2c8
parent0cdb81c92993b8b1e41aee9df2170f5dc35e86b8
xgethostname: reorganize / simplify

xgethostname and xgetdomainname were essentially copies long
ago, but they’ve diverged.  Bring them back together again
by implementing the (rarely used) latter in terms of the former.
And avoid some unnecessary realloc calls while we’re at it.
* lib/xgetdomainname.c: Rewrite from scratch so that it merely
includes xgethostname.c with a few preliminaries.
* lib/xgethostname.c: Generalize so that it can be included
from xgetdomainname.c.
(GETANAME, XGETANAME): New macros.
(INITIAL_HOSTNAME_LENGTH): Remove.  No need for this parameter.
Use 100 instead, as few hostnames are longer than that.
(XGETANAME): Try getting the hostname into the stack first,
as that avoids a malloc call in the usual case.
Check for both POSIX-style truncation and SunOS 5.5 bug
in a cleaner way, by simply checking string length.
Don’t use x2realloc, which wastes time preserving buffer garbage;
use xpalloc with NULL instead.  Don’t bother shrinking buffer
in the very rare case where the hostname is longer than sizeof
buf; it’s not worth the aggravation.
* modules/xgetdomainname (Depends-on): Remove free-posix, xalloc.
Add xgethostname.
ChangeLog
lib/xgetdomainname.c
lib/xgethostname.c
modules/xgetdomainname