lua-users home
lua-l archive

Re: file:write() fails silently for read-only files

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


On 8 September 2011 11:54, Tony Finch <dot@dotat.at> wrote:
> On Thu 8 Sep 2011, at 11:47, steve donovan wrote:
>>
>> I assumed that it did, thanks for correcting that.  The portable C way
>> is to check what the number of bytes which fwrite returns.
>
>
> In my tests (on Mac OS X) fprintf() writing to a FILE* stream open for reading returns a successful result, but errno and the ferror() flag are set.
>
I got a contradictory result:
$ cat foo.c
#include <stdio.h>
int main (void)
{
 FILE *f = fopen("foo", "r");
 int ret = fprintf(f, "dfoo");
 printf ("%d %d\n", ret, ferror(f));
}
$ gcc -o foo foo.c
$ ./foo
-1 1
-- 
http://rrt.sc3d.org

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