diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 11:32:49 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2025-04-03 11:32:49 -0300 |
commit | 3f4f28010aa5065456f1edf97de1ab268cc49944 (patch) | |
tree | 18ef631f33d1e71cf7f9d20b67d9148499a9dcf4 /ltests.c | |
parent | 93e347b51923a3f0b993aac37c74e1489c02f3b5 (diff) | |
download | lua-3f4f28010aa5065456f1edf97de1ab268cc49944.tar.gz lua-3f4f28010aa5065456f1edf97de1ab268cc49944.tar.bz2 lua-3f4f28010aa5065456f1edf97de1ab268cc49944.zip |
io.write returns number of written bytes on error
Diffstat (limited to 'ltests.c')
-rw-r--r-- | ltests.c | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -2106,6 +2106,25 @@ static int coresume (lua_State *L) { | |||
2106 | } | 2106 | } |
2107 | } | 2107 | } |
2108 | 2108 | ||
2109 | #if !defined(LUA_USE_POSIX) | ||
2110 | |||
2111 | #define nonblock NULL | ||
2112 | |||
2113 | #else | ||
2114 | |||
2115 | #include <unistd.h> | ||
2116 | #include <fcntl.h> | ||
2117 | |||
2118 | static int nonblock (lua_State *L) { | ||
2119 | FILE *f = cast(luaL_Stream*, luaL_checkudata(L, 1, LUA_FILEHANDLE))->f; | ||
2120 | int fd = fileno(f); | ||
2121 | int flags = fcntl(fd, F_GETFL, 0); | ||
2122 | flags |= O_NONBLOCK; | ||
2123 | fcntl(fd, F_SETFL, flags); | ||
2124 | return 0; | ||
2125 | } | ||
2126 | #endif | ||
2127 | |||
2109 | /* }====================================================== */ | 2128 | /* }====================================================== */ |
2110 | 2129 | ||
2111 | 2130 | ||
@@ -2159,6 +2178,7 @@ static const struct luaL_Reg tests_funcs[] = { | |||
2159 | {"upvalue", upvalue}, | 2178 | {"upvalue", upvalue}, |
2160 | {"externKstr", externKstr}, | 2179 | {"externKstr", externKstr}, |
2161 | {"externstr", externstr}, | 2180 | {"externstr", externstr}, |
2181 | {"nonblock", nonblock}, | ||
2162 | {NULL, NULL} | 2182 | {NULL, NULL} |
2163 | }; | 2183 | }; |
2164 | 2184 | ||