[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [RFC] fixing dup() in luaposix
- From: Natanael Copa <natanael.copa@...>
- Date: Mon, 28 Jan 2008 19:56:40 +0100
I'm looking into fixing dup() in luaposix.
The problem in the current implementation from lposix is that it only
deals with fd's, integers, not lua files. This means you can not really
use the value returned from dup(2)
I can think of 4 options:
1) add a new dup2(), keep old dup() for compatibility.
I doubt anyone uses it since it does not take lua files.
static int Pdup2(lua_State *L) /* dup(old) */
FILE* oldf = *(FILE**)luaL_checkudata(L, 1, LUA_FILEHANDLE);
FILE* newf = *(FILE**)luaL_checkudata(L, 2, LUA_FILEHANDLE);
return pushresult(L, dup2(fileno(oldf), fileno(newf)), NULL);
2) create dup2() as above but fix dup() to map the dup(2) function and
use lua files rather then integer fd's. (break compatibility)
use fileno(*oldf) and pushfile() to create new lua file from dup(2)'s
This is rather simple to implement, and makes the difference between
dup(2) and dup2(2) clearer.
3) keep the kurrent dup(oldfile, [newfile]) but fix it to deal with lua
files. this is IMHO the cleanest way to deal with it.
4) keep implementation as it is, but add a fileno() function so you can
dup lua files. (only the dup2() variant is useable)