return true
end
+--- Flush file object user space buffers.
+-- @param file File object (or nil).
+-- @return True on success, false on error.
+-- @return Error object on failure.
+function eio.fflush(file)
+ local rc, re, errstring, handle
+
+ if file then
+ rc, re = is_eio_object(file)
+ if not rc then
+ return false, re
+ end
+ end
+
+ if file then
+ rc, errstring = leio.fflush(file.handle)
+ if not rc then
+ return false, err.new("error flushing file %s: %s", file.finfo, errstring)
+ end
+ else
+ rc, errstring = leio.fflush(nil)
+ if not rc then
+ return false, err.new("error flushing files: %s", errstring)
+ end
+ end
+
+ return true
+end
+
--- Close a file descriptor.
-- @param fd File descriptor.
-- @return True on success, false on error.
return 1;
}
+static int
+eio_fflush(lua_State *lua)
+{
+ FILE *f;
+ f = lua_touserdata(lua, 0); /* May be NULL */
+
+ if (fflush(f) == EOF) {
+ lua_pushboolean(lua, 0);
+ lua_pushstring(lua, strerror(errno));
+ return 2;
+ }
+
+ lua_pushboolean(lua, 1);
+ return 1;
+}
+
static int
eio_close(lua_State *L)
{
{ "fclose", eio_fclose },
{ "fdopen", eio_fdopen },
{ "feof", eio_feof },
+ { "fflush", eio_fflush },
{ "fgetc", eio_fgetc },
{ "fileno", eio_fileno },
{ "fopen", eio_fopen },