lua-users home
lua-l archive

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


KHMan wrote:
Ah, MSVCRT is very old and very non-compliant. Should someone use
fgets in a C program and rely on this behaviour and use mem* calls
to deal with NULs in the data stream, as opposed to the usual
practice of using str* calls on textual strings? Does the
developer has better, safer options?

I wouldn't want to write code that depends on
implementation-specific behaviour if I can help it, so I would
never dream of using fgets (or the Lua equivalent of "*l") for
anything that isn't standard text files. The issue just doesn't
arise. But that's just me, I guess.

What make you think that treating null characters by fgets is implementation specific?

IMHO, if fgets definition does not mention null characters, then the obvious conclusion one could make is that fgets does not handle null characters as a special case.

Here is an fgets specification from The Open Group:

The fgets() function shall read bytes from stream into the array
pointed to by s, until n-1 bytes are read, or a <newline> is read
and transferred to s, or an end-of-file condition is encountered.
The string is then terminated with a null byte.

From this specification, it is quite obvious that only <newline> is special in the input stream.

I have nothing further to add, so that's all from me for this
thread, I won't post anything more on this topic.

Thanks anyway.

--
Shmuel