[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: compiling packages



> Also, what should I do to this code:
> 
>     char name[MAXHOSTNAMELEN];
>     memset(name, 0, sizeof(name));
>     gethostname(name, MAXHOSTNAMELEN);
> 
> as MAXHOSTNAMELEN is not defined?

You should use the procedure specified in the libc manual for reallocating
the buffer as necessary when gethostname returns ENAMETOOLONG.  When there
a MAXHOSTNAMELEN definition that corresponds to a fixed limit (as on most
systems), then gethostname will never fail with ENAMETOOLONG.  When there
is no MAXHOSTNAMELEN (as on the Hurd), there is no fixed limit and
theoretically it might be any size; you can pick some reasonable value like
64 or 128 for the initial buffer size, and in practice noone will use a
hostname longer than that.



Reply to: