From 3f4f28010aa5065456f1edf97de1ab268cc49944 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Thu, 3 Apr 2025 11:32:49 -0300 Subject: io.write returns number of written bytes on error --- ltests.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index 6a638d05..1517aa88 100644 --- a/ltests.c +++ b/ltests.c @@ -2106,6 +2106,25 @@ static int coresume (lua_State *L) { } } +#if !defined(LUA_USE_POSIX) + +#define nonblock NULL + +#else + +#include +#include + +static int nonblock (lua_State *L) { + FILE *f = cast(luaL_Stream*, luaL_checkudata(L, 1, LUA_FILEHANDLE))->f; + int fd = fileno(f); + int flags = fcntl(fd, F_GETFL, 0); + flags |= O_NONBLOCK; + fcntl(fd, F_SETFL, flags); + return 0; +} +#endif + /* }====================================================== */ @@ -2159,6 +2178,7 @@ static const struct luaL_Reg tests_funcs[] = { {"upvalue", upvalue}, {"externKstr", externKstr}, {"externstr", externstr}, + {"nonblock", nonblock}, {NULL, NULL} }; -- cgit v1.2.3-55-g6feb