The attached patch (against cvs 1.12.11) improves xgethostname() to check for ENOMEM as well as ENAMETOOLONG and EINVAL. I grant permission to distribute this patch under the terms of the GNU Public License. Please apply.
BTW, I think there is still room for improvement:
(a) this behavior is not well-standardized. POSIX claims the hostname will be truncated if it is larger than the passed-in buffer length (and it is undefined whether the return value will be NUL terminated), but AFAICS most systems return an error in this case. It seems glibc < 2.1 will return EINVAL, glibc >= 2.1 and FreeBSD will return ENAMETOOLONG, and other systems may well return other errors. It is unnecessary to rely on this behavior, anyway: why not just make the buffer size HOST_NAME_MAX or MAXHOSTNAMELEN (etc.) to begin with? It seems silly to go through this kind of trouble to avoid the allocation of a few hundred bytes of memory.
(b) not checking the return value of xgethostname() is fragile.
-Neil
2005-02-21 Neil Conway <[EMAIL PROTECTED]>
* lib/xgethostname.c: Check for ENOMEM, which is returned by OSX/Darwin if the specified buffer is not large enough for the hostname.
_______________________________________________ Bug-cvs mailing list Bug-cvs@gnu.org http://lists.gnu.org/mailman/listinfo/bug-cvs