lua-users home
lua-l archive

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

Hi Luiz:

On Thu, Feb 20, 2014 at 4:49 PM, Luiz Henrique de Figueiredo
<> wrote:
>> For me fgets(buf, size, file) should be equivalent to a getc loop with
>> some checkings for size, \n and EOF. And, from what we've seen on this
>> thread, it seems the libC implementation do it that way.

> Not really. See for instance

Your point being? as this example seem to prove my point.

I mean, are this implementations not equivalent to a getc loop on the
same implementations? ( ignoring multithreading issues ) ( I've
changed your links fgets=>fgetc/getc  but they both end up calling
__s* stuff, and I'm unable to follow them more ).

To me it seems they are optimized equivalents. In particular I notice
they do not use any str* functions, but use mem*, probably for speed
and/or  to be nul safe, but they are nul safe like doing it with getc.

In case I did not explain myself. No production libC I've ever looked
at does fgets with a getc loop, I knew this. But all the ones I
remember using give the same result ( as chars stored in the buffer,
not counting buffer overflows, EOF checking  and the errors I'm sure
to introduce now ) for 'fgets(buf, size, file)' and
'while((c=getc(f)!='\n' && c!=EOF) *buf++=c; *buf=0;', and that is
what I meant for equivalent.

For 'do it that way' I meant do it so the result the same, I never
expected modern libraries like freebsd or its cousins to use a loop.

Francisco Olarte.