| 544 | } |
| 545 | |
| 546 | static int Lio_read(lua_State *L) { |
| 547 | const char *fname = luaL_optstring(L, 1, NULL); |
| 548 | FILE *fp = stdin; |
| 549 | int ret; |
| 550 | if (fname == NULL) |
| 551 | (void)setmode(fileno(stdin), O_BINARY); |
| 552 | else if ((fp = fopen(fname, "rb")) == NULL) |
| 553 | return luaL_fileresult(L, 0, fname); |
| 554 | lua_pushcfunction(L, io_read); |
| 555 | lua_pushlightuserdata(L, fp); |
| 556 | ret = lua_pcall(L, 1, 1, 0); |
| 557 | if (fp != stdin) fclose(fp); |
| 558 | else (void)setmode(fileno(stdin), O_TEXT); |
| 559 | if (ret != LUA_OK) { lua_pushnil(L); lua_insert(L, -2); return 2; } |
| 560 | return 1; |
| 561 | } |
| 562 | |
| 563 | static int Lio_write(lua_State *L) { |
| 564 | int res; |
nothing calls this directly
no test coverage detected