lua-users home
lua-l archive

Re: io:lines() and 0円

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


It was thus said that the Great Francisco Olarte once stated:
> 
> >> > How is discarding '015円' any different from mapping "015円012円" to "012円"?
> >> Isn't obvious? The simpler example: '015円' => '', some more:
> >> 'ab015円cd015円012円' => abcd\n vs. ab\rcd\n
 How I should have answered that was, "no, that was not obvious to me." In
all my years of programming, I had not come across a text file with both CR
and LF that weren't paired together.
> >> > The problem with that is if the file in question has multiple NUL byte
> >> > runs (enough to fill a buffer, or even an unfortunate alignment where the
> >> > last byte read in the buffer is NUL).
> >> Not an issue. If C guaranteed me fgets would not touch the buffer
> >> after the null, I can fill it with ones, and as I know it MUST have a
> >> null at the end I can scan backwards, the first one is the terminating
> >> null.
> 
> > Sigh. That *still* wouldn't work. Assume (for sake of argument) a buffer
> > size of 8 bytes. You fill it with all ones (0xFF):
> > FF FF FF FF FF FF FF FF
> > And you read the following binary file using your version of fgets():
> > 34 89 00 FF 23 08 FF FF
> > So the buffer now contains:
> > 34 89 00 FF 23 08 FF FF
> 
> Are you trying to kid me again? My buffer will contain a terminating
> null, that is guaranteed by fgets. Where is it?
 My mistake. I am sorry about that.
 -spc

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