Isn't this whole function the same as calling php_uname('n') ?

According to gethostname()'s manpage on Linux:

The GNU C library implements gethostname() as a library function that
calls uname(2) and copies up to len bytes from the returned nodename
field into name. 

php_uname('n') is already implementing this, so why adding
gethostname() ? (also I belive php_uname() works on windows, dunno if
the hostname option works).


A final note about using HOST_NAME_MAX if we still want to add
gethostname(), according to BSD manpages:

The gethostname() function conforms to IEEE Std 1003.1-2001
(``POSIX.1'').  Callers should be aware that {HOST_NAME_MAX} may be
variable or infinite, but is guaranteed to be no less than
{_POSIX_HOST_NAME_MAX}.  On older systems, this limit was defined in the
non-standard header <sys/param.h> as MAXHOSTNAMELEN, and counted the
terminating null.  The sethostname() function and the error returns for
gethostname() are not standardized.

Allocating a buffer of size "infinite" in the stack looks like a bad
idea. Anyway a machine with an hostname over 4kB is really unlikely. It
also won't work if the value is variable (or we would have to allocate
this on the heap with emalloc).


Mark

Le lundi 29 décembre 2008 à 23:51 -0300, Cristian Rodríguez a écrit :
> Ilia Alshanetsky escribió:
> 
> > +   char buf[4096];
> 
> Shouldnt that be
> 
> char buf[HOST_NAME_MAX + 1] ?
> 
> 
> 
> 


-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to