|
On Feb 20, 2014, at 18:17 , Francisco Olarte wrote:
This gets is a plain and simple getchar loop: The (latest) glibc has reads the first with getchar (EOF optimization I guess) and the rest with a call to an internal __iogetline. So everything we saw so far copies everything until end-of-buffer, new-line or end-of-file. To summarize some standard: 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. Upon successful completion, fgets() shall return s. If the stream is at end-of-file, the end-of-file indicator for the stream shall be set and fgets() shall return a null pointer. I think with my latest patch all corner cases should be handled to successfully transfer the string into a Lua string containing all bytes read and returned by the underlying C library. To adjust the chop behavior (I personally also do not like injecting bytes that where not there, I only wanted to make the argument handling more symmetric) as before change the last line change from. --l; /* EOF without \n and thus 0-terminated + our \n */ p[l-1] = '\n'; to: l -= 2; chop = 0; What do the Lua authors think about addressing this inconvenience (not to call it a bug) in the current implementation? René
-- ExactCODE GmbH, Jaegerstr. 67, DE-10117 Berlin http://exactcode.com | http://exactscan.com | http://ocrkit.com | http://t2-project.org | http://rene.rebe.de |