Back out e69aaae67541 (bug 1197941) for being worse than the disease

CLOSED TREE
This commit is contained in:
Phil Ringnalda 2015-09-29 19:19:22 -07:00
Родитель 724bf24658
Коммит aae4eba8d2
1 изменённых файлов: 11 добавлений и 11 удалений

Просмотреть файл

@ -158,21 +158,21 @@ function cLibrary()
fopen: lib.declare("fopen", ctypes.default_abi, ctypes.void_t.ptr, ctypes.char.ptr, ctypes.char.ptr),
getline: lib.declare("getline", ctypes.default_abi, ctypes.ssize_t, ctypes.char.ptr.ptr, ctypes.size_t.ptr, ctypes.void_t.ptr),
fclose: lib.declare("fopen", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr),
free: lib.declare("free", ctypes.default_abi, ctypes.void_t.ptr),
setvbuf: lib.declare("setvbuf", ctypes.default_abi, ctypes.int, ctypes.void_t.ptr, ctypes.char.ptr, ctypes.int, ctypes.size_t),
};
}
function* readFileLines_gen(filename)
{
var libc = cLibrary();
var linebuf = ctypes.char.ptr();
var bufsize = ctypes.size_t(0);
var fp = libc.fopen(filename, "r");
if (fp.isNull())
throw "Unable to open '" + filename + "'"
var libc = cLibrary();
var linebuf = ctypes.char.array(4096)();
var bufsize = ctypes.size_t(4096);
var fp = libc.fopen(filename, "r");
if (fp.isNull())
throw "Unable to open '" + filename + "'"
while (libc.getline(linebuf.address(), bufsize.address(), fp) > 0)
yield linebuf.readString();
libc.fclose(fp);
libc.free(ctypes.void_t.ptr(linebuf));
var bufp = ctypes.char.ptr(linebuf.addressOfElement(0));
while (libc.getline(bufp.address(), bufsize.address(), fp) > 0)
yield bufp.readString();
libc.fclose(fp);
}