lua-users home
lua-l archive

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

> 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...)

It (re)appeared in 5.1.3. We removed it from Lua some time ago because
some systems did not support it (even it being part of ISO C). As that
was a long time ago, we thought it would be "safe" to use it again.
Anyway, you do not need to change the source code to correct your problem.
You can simply add the next definition to luaconf.h:

   #define freopen(n,m,f)  (fclose(f), fopen(n,m))

(If you prefer, you can protect this definition with #if defined(lauxlib_c)...)

-- Roberto