lua-users home
lua-l archive

Re: io:lines() and 0円

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


On Friday, February 21, 2014 09:20:35 AM René Rebe wrote:
> There is no corner case left. At EOF without EOL the string is 0 terminated.
> My last patch checks for if the stream reached EOF and removes the
> superfluous 0円\n.
I realised after I sent the mail that it was less hairy than I had assumed. 
But the way to do it is much simpler than your patch. Just use memrchr instead 
of memchr to find the terminating NULL. The read_line function then becomes:
## SNIP ##
 memset(p, '\n', LUAL_BUFFERSIZE); /* could be any non-NULL character */
 if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
 luaL_pushresult(&b); /* close buffer */
 return (lua_rawlen(L, -1) > 0); /* check whether read something */
 }
 l = (char*)memrchr(p, '0円', LUAL_BUFFERSIZE) - p;
## SNIP ##
1 insertion and 1 changed line. Though I get a warning that I think must be a 
bug in GCC. (It's trying to tell me memrchr returns an int.)
On Friday, February 21, 2014 10:48:00 AM Dirk Laurie wrote:
> 2. Anybody, even the OP, thinking that the Lua developers
> will do this?
I don't recall anyone from PUC-Rio saying they *wouldn't* make the change.
-- 
tom <telliamed@whoopdedo.org>

AltStyle によって変換されたページ (->オリジナル) /