lua-users home
lua-l archive

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


On Sat, 2008-02-02 at 12:20 +0000, Terisquas Brothers wrote:
> I'm trying to make LUA work in a platform where I have
> no freopen.
> 
> I think there's just one appearance of freopen in the
> code, in luaL_loadfile. Is it safe to modify it from
> 
>     lf.f = freopen(filename, "rb", lf.f);  /* reopen
> in binary mode */
> 
> to
> 
> 	  if (lf.f!=NULL) fclose (lf.f);
> 	  lf.f=fopen (filename,"rb");
> 
> ? 
> 
> 
> Is that a correct equivalence? (the truth is I've
> never seen freopen until now...)

If nothing goes wrong you are fine.

To handle rare errors, something more like:
	if (lf.f){
		if (fclose(lf.f) == EOF){
			/* Bail out here, it's all bad */
		}
        }
	lf.f = fopen(filename,"rb");

BTW: freopen is part of C89, so I'd be double checking platforms that
don't implement it.

	Regards,
	nash
	[Slow on the reply]