]> git.e2factory.org Git - e2factory.git/commitdiff
Add eio.setunbuffered()
authorTobias Ulmer <tu@emlix.com>
Wed, 15 Jan 2014 18:29:34 +0000 (19:29 +0100)
committerTobias Ulmer <tu@emlix.com>
Wed, 16 Nov 2016 14:41:17 +0000 (15:41 +0100)
Signed-off-by: Tobias Ulmer <tu@emlix.com>
generic/eio.lua
generic/leio.c

index 46545b5e8a921041485e6ae8ef31b30bca607aec..9e4f6e357d6dfb0437333bed5bc826d274a53c73 100644 (file)
@@ -304,6 +304,24 @@ function eio.setlinebuf(file)
     end
 end
 
+--- Turn line and block buffering off. See setbuf(3) for details. setunbuffered
+-- has no error conditions. If an invalid file object is passed, it calls
+-- e2lib.abort() terminating the process.
+-- @param file File object
+function eio.setunbuffered(file)
+    local errstring, rc, re
+
+    rc, re = is_eio_object(file)
+    if not rc then
+        e2lib.abort(re)
+    end
+
+    rc, errstring = leio.setunbuffered(file.handle)
+    if not rc then
+        e2lib.abort(err.new("%s", errstring))
+    end
+end
+
 --- Duplicate a file descriptor. See dup(2) for details.
 -- @param oldfd File descriptor to duplicate.
 -- @param newfd Duplicated file descritor. If the file descriptor was open
index e44cbe5cfaf02fb7891cc66042a200571ac3a736..d6d710148987c10c8683ccbd17b19f079ce5c2ae 100644 (file)
@@ -297,6 +297,24 @@ eio_setlinebuf(lua_State *lua)
        return 1;
 }
 
+static int
+eio_setunbuffered(lua_State *lua)
+{
+       FILE *f;
+
+       f = lua_touserdata(lua, 1);
+       if (!f) {
+               lua_pushboolean(lua, 0);
+               lua_pushstring(lua, "eio_setunbuffered: one or more arguments "
+                   "of wrong type/missing");
+               return 2;
+       }
+
+       setbuf(f, NULL);
+       lua_pushboolean(lua, 1);
+       return 1;
+}
+
 static int
 eio_dup2(lua_State *lua)
 {
@@ -373,6 +391,7 @@ static luaL_Reg lib[] = {
   { "fwrite", eio_fwrite },
   { "pipe", eio_pipe },
   { "setlinebuf", eio_setlinebuf },
+  { "setunbuffered", eio_setunbuffered },
   { NULL, NULL }
 };