lua-users home
lua-l archive

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


On Wed, Mar 21, 2012 at 5:12 PM, Roberto Ierusalimschy
<roberto@inf.puc-rio.br> wrote:
>> I wonder why the 5.2 manual doesn't say it's the same as fopen,
>> though. Did they change/add some modes, or did they just not want to
>> have to guarantee fopen's behaviour? Or is it a simple omission?
>
> Lua 5.2 did not changed/add modes, but it may restrict some. ANSI C
> demands that 'mode' have a valid, specific format, and some machines
> may have real problems with invalid modes. So we added a verification
> step in io.open. Now, even if your native C fopen accepts extensions
> (e.g., Linux seems to accept 'wb+'), io.open does not accept them.

ANSI C90 accepts both "w+b" and "wb+" I think; I don't have a final
copy but the draft3 available online does call out those two
alternatives.  C99 does as well.

K&R2 is a little confusing:

  If the mode includes 'b' after the initial letter as in "rb" or
"w+b", that indicates a binary file.

Strictly speaking "wb+" has a 'b' after the initial letter, but in
context it is not clear that this is meant to be legal. K&R2 does an
excellent job of editing the standard down to the important parts, but
this may be a case where they cut a little too much.

The only thing everybody is clear on is that the mode string cannot
start with 'b'.

Jay