Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 20 Feb 2001 11:36:04 -0600
From:      "Jacques A. Vidrine" <n@nectar.com>
To:        Andrey Simonenko <simon@comsys.ntu-kpi.kiev.ua>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Staticaly allocated buffers in library. Is it correct?
Message-ID:  <20010220113604.A54305@hamlet.nectar.com>
In-Reply-To: <96u5ao$70r$1@igloo.uran.net.ua>; from simon@comsys.ntu-kpi.kiev.ua on Tue, Feb 20, 2001 at 06:14:42PM %2B0300
References:  <Pine.BSF.4.21.0102171202110.400-100000@scorpion.cosmos.all.net> <200102192046.f1JKkl738082@earth.backplane.com> <96u5ao$70r$1@igloo.uran.net.ua>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Feb 20, 2001 at 06:14:42PM +0300, Andrey Simonenko wrote:
> Let's look at implementation of getaddrinfo(3) function (there are some
> functions more which
> do the same way). We can find source for this function in
> /usr/src/lib/libc/net/getaddrinfo.c file.
> 
> This functions in some case reads /etc/hosts file and try to find out there
> host name. getaddrinfo(3)
> calls some functions and function _gethtent() tries to read line by linefrom
> /etc/hosts file:
[snip code]
> We can see if line is bigger than 8k, then _gethtent() reads until the end
> of line.
> In most case this function doesn't find needed host name in such lines, but
> in some case it can find part of
> line as correct host name and tries to fetch IP address, but it also will
> not work, because we lose
> beginning of line when "goto again".
> 
> This code can be simply rewriten as loop with fgets(), strlen()/strchr() and
> realloc(), but it causes
> speed lost in this function.
> 
> Also I understand that 8k for line in /etc/hosts is enough and should not be
> problem for most of _real life_
> situations.

I'm coming in late in this thread.  What is it you are trying to
accomplish?

FWIW, I've rewritten this and lots of code like it while revamping
nsswitch.  Unlike the traditional code, I am careful to handle lines
of arbitrary length by processing only chunks (e.g. 512 bytes) at a
time.

Cheers,
-- 
Jacques Vidrine / n@nectar.com / jvidrine@verio.net / nectar@FreeBSD.org

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20010220113604.A54305>