liolib.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. /*
  2. ** $Id: liolib.c,v 2.120 2014/03/19 18:57:42 roberto Exp roberto $
  3. ** Standard I/O (and system) library
  4. ** See Copyright Notice in lua.h
  5. */
  6. /*
  7. ** This definition must come before the inclusion of 'stdio.h'; it
  8. ** should not affect non-POSIX systems
  9. */
  10. #if !defined(_FILE_OFFSET_BITS)
  11. #define _LARGEFILE_SOURCE 1
  12. #define _FILE_OFFSET_BITS 64
  13. #endif
  14. #include <errno.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #define liolib_c
  19. #define LUA_LIB
  20. #include "lua.h"
  21. #include "lauxlib.h"
  22. #include "lualib.h"
  23. #if !defined(l_checkmode)
  24. /*
  25. ** Check whether 'mode' matches '[rwa]%+?b?'.
  26. ** Change this macro to accept other modes for 'fopen' besides
  27. ** the standard ones.
  28. */
  29. #define l_checkmode(mode) \
  30. (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
  31. (*mode != '+' || ++mode) && /* skip if char is '+' */ \
  32. (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
  33. (*mode == '\0'))
  34. #endif
  35. /*
  36. ** {======================================================
  37. ** l_popen spawns a new process connected to the current
  38. ** one through the file streams.
  39. ** =======================================================
  40. */
  41. #if !defined(l_popen) /* { */
  42. #if defined(LUA_USE_POSIX) /* { */
  43. #define l_popen(L,c,m) (fflush(NULL), popen(c,m))
  44. #define l_pclose(L,file) (pclose(file))
  45. #elif defined(LUA_WIN) /* }{ */
  46. #define l_popen(L,c,m) (_popen(c,m))
  47. #define l_pclose(L,file) (_pclose(file))
  48. #else /* }{ */
  49. /* ANSI definitions */
  50. #define l_popen(L,c,m) \
  51. ((void)((void)c, m), \
  52. luaL_error(L, LUA_QL("popen") " not supported"), \
  53. (FILE*)0)
  54. #define l_pclose(L,file) ((void)L, (void)file, -1)
  55. #endif /* } */
  56. #endif /* } */
  57. /* }====================================================== */
  58. #if !defined(l_getc) /* { */
  59. #if defined(LUA_USE_POSIX)
  60. #define l_getc(f) getc_unlocked(f)
  61. #define l_lockfile(f) flockfile(f)
  62. #define l_unlockfile(f) funlockfile(f)
  63. #else
  64. #define l_getc(f) getc(f)
  65. #define l_lockfile(f) ((void)0)
  66. #define l_unlockfile(f) ((void)0)
  67. #endif
  68. #endif /* } */
  69. /*
  70. ** {======================================================
  71. ** l_fseek: configuration for longer offsets
  72. ** =======================================================
  73. */
  74. #if !defined(l_fseek) /* { */
  75. #if defined(LUA_USE_POSIX) /* { */
  76. #define l_fseek(f,o,w) fseeko(f,o,w)
  77. #define l_ftell(f) ftello(f)
  78. #define l_seeknum off_t
  79. #elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
  80. && defined(_MSC_VER) && (_MSC_VER >= 1400) /* }{ */
  81. /* Windows (but not DDK) and Visual C++ 2005 or higher */
  82. #define l_fseek(f,o,w) _fseeki64(f,o,w)
  83. #define l_ftell(f) _ftelli64(f)
  84. #define l_seeknum __int64
  85. #else /* }{ */
  86. /* ANSI definitions */
  87. #define l_fseek(f,o,w) fseek(f,o,w)
  88. #define l_ftell(f) ftell(f)
  89. #define l_seeknum long
  90. #endif /* } */
  91. #endif /* } */
  92. /* }====================================================== */
  93. #define IO_PREFIX "_IO_"
  94. #define IO_INPUT (IO_PREFIX "input")
  95. #define IO_OUTPUT (IO_PREFIX "output")
  96. typedef luaL_Stream LStream;
  97. #define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
  98. #define isclosed(p) ((p)->closef == NULL)
  99. static int io_type (lua_State *L) {
  100. LStream *p;
  101. luaL_checkany(L, 1);
  102. p = (LStream *)luaL_testudata(L, 1, LUA_FILEHANDLE);
  103. if (p == NULL)
  104. lua_pushnil(L); /* not a file */
  105. else if (isclosed(p))
  106. lua_pushliteral(L, "closed file");
  107. else
  108. lua_pushliteral(L, "file");
  109. return 1;
  110. }
  111. static int f_tostring (lua_State *L) {
  112. LStream *p = tolstream(L);
  113. if (isclosed(p))
  114. lua_pushliteral(L, "file (closed)");
  115. else
  116. lua_pushfstring(L, "file (%p)", p->f);
  117. return 1;
  118. }
  119. static FILE *tofile (lua_State *L) {
  120. LStream *p = tolstream(L);
  121. if (isclosed(p))
  122. luaL_error(L, "attempt to use a closed file");
  123. lua_assert(p->f);
  124. return p->f;
  125. }
  126. /*
  127. ** When creating file handles, always creates a `closed' file handle
  128. ** before opening the actual file; so, if there is a memory error, the
  129. ** file is not left opened.
  130. */
  131. static LStream *newprefile (lua_State *L) {
  132. LStream *p = (LStream *)lua_newuserdata(L, sizeof(LStream));
  133. p->closef = NULL; /* mark file handle as 'closed' */
  134. luaL_setmetatable(L, LUA_FILEHANDLE);
  135. return p;
  136. }
  137. static int aux_close (lua_State *L) {
  138. LStream *p = tolstream(L);
  139. lua_CFunction cf = p->closef;
  140. p->closef = NULL; /* mark stream as closed */
  141. return (*cf)(L); /* close it */
  142. }
  143. static int io_close (lua_State *L) {
  144. if (lua_isnone(L, 1)) /* no argument? */
  145. lua_getfield(L, LUA_REGISTRYINDEX, IO_OUTPUT); /* use standard output */
  146. tofile(L); /* make sure argument is an open stream */
  147. return aux_close(L);
  148. }
  149. static int f_gc (lua_State *L) {
  150. LStream *p = tolstream(L);
  151. if (!isclosed(p) && p->f != NULL)
  152. aux_close(L); /* ignore closed and incompletely open files */
  153. return 0;
  154. }
  155. /*
  156. ** function to close regular files
  157. */
  158. static int io_fclose (lua_State *L) {
  159. LStream *p = tolstream(L);
  160. int res = fclose(p->f);
  161. return luaL_fileresult(L, (res == 0), NULL);
  162. }
  163. static LStream *newfile (lua_State *L) {
  164. LStream *p = newprefile(L);
  165. p->f = NULL;
  166. p->closef = &io_fclose;
  167. return p;
  168. }
  169. static void opencheck (lua_State *L, const char *fname, const char *mode) {
  170. LStream *p = newfile(L);
  171. p->f = fopen(fname, mode);
  172. if (p->f == NULL)
  173. luaL_error(L, "cannot open file " LUA_QS " (%s)", fname, strerror(errno));
  174. }
  175. static int io_open (lua_State *L) {
  176. const char *filename = luaL_checkstring(L, 1);
  177. const char *mode = luaL_optstring(L, 2, "r");
  178. LStream *p = newfile(L);
  179. const char *md = mode; /* to traverse/check mode */
  180. luaL_argcheck(L, l_checkmode(md), 2, "invalid mode");
  181. p->f = fopen(filename, mode);
  182. return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
  183. }
  184. /*
  185. ** function to close 'popen' files
  186. */
  187. static int io_pclose (lua_State *L) {
  188. LStream *p = tolstream(L);
  189. return luaL_execresult(L, l_pclose(L, p->f));
  190. }
  191. static int io_popen (lua_State *L) {
  192. const char *filename = luaL_checkstring(L, 1);
  193. const char *mode = luaL_optstring(L, 2, "r");
  194. LStream *p = newprefile(L);
  195. p->f = l_popen(L, filename, mode);
  196. p->closef = &io_pclose;
  197. return (p->f == NULL) ? luaL_fileresult(L, 0, filename) : 1;
  198. }
  199. static int io_tmpfile (lua_State *L) {
  200. LStream *p = newfile(L);
  201. p->f = tmpfile();
  202. return (p->f == NULL) ? luaL_fileresult(L, 0, NULL) : 1;
  203. }
  204. static FILE *getiofile (lua_State *L, const char *findex) {
  205. LStream *p;
  206. lua_getfield(L, LUA_REGISTRYINDEX, findex);
  207. p = (LStream *)lua_touserdata(L, -1);
  208. if (isclosed(p))
  209. luaL_error(L, "standard %s file is closed", findex + strlen(IO_PREFIX));
  210. return p->f;
  211. }
  212. static int g_iofile (lua_State *L, const char *f, const char *mode) {
  213. if (!lua_isnoneornil(L, 1)) {
  214. const char *filename = lua_tostring(L, 1);
  215. if (filename)
  216. opencheck(L, filename, mode);
  217. else {
  218. tofile(L); /* check that it's a valid file handle */
  219. lua_pushvalue(L, 1);
  220. }
  221. lua_setfield(L, LUA_REGISTRYINDEX, f);
  222. }
  223. /* return current value */
  224. lua_getfield(L, LUA_REGISTRYINDEX, f);
  225. return 1;
  226. }
  227. static int io_input (lua_State *L) {
  228. return g_iofile(L, IO_INPUT, "r");
  229. }
  230. static int io_output (lua_State *L) {
  231. return g_iofile(L, IO_OUTPUT, "w");
  232. }
  233. static int io_readline (lua_State *L);
  234. static void aux_lines (lua_State *L, int toclose) {
  235. int i;
  236. int n = lua_gettop(L) - 1; /* number of arguments to read */
  237. /* ensure that arguments will fit here and into 'io_readline' stack */
  238. luaL_argcheck(L, n <= LUA_MINSTACK - 3, LUA_MINSTACK - 3, "too many options");
  239. lua_pushvalue(L, 1); /* file handle */
  240. lua_pushinteger(L, n); /* number of arguments to read */
  241. lua_pushboolean(L, toclose); /* close/not close file when finished */
  242. for (i = 1; i <= n; i++) lua_pushvalue(L, i + 1); /* copy arguments */
  243. lua_pushcclosure(L, io_readline, 3 + n);
  244. }
  245. static int f_lines (lua_State *L) {
  246. tofile(L); /* check that it's a valid file handle */
  247. aux_lines(L, 0);
  248. return 1;
  249. }
  250. static int io_lines (lua_State *L) {
  251. int toclose;
  252. if (lua_isnone(L, 1)) lua_pushnil(L); /* at least one argument */
  253. if (lua_isnil(L, 1)) { /* no file name? */
  254. lua_getfield(L, LUA_REGISTRYINDEX, IO_INPUT); /* get default input */
  255. lua_replace(L, 1); /* put it at index 1 */
  256. tofile(L); /* check that it's a valid file handle */
  257. toclose = 0; /* do not close it after iteration */
  258. }
  259. else { /* open a new file */
  260. const char *filename = luaL_checkstring(L, 1);
  261. opencheck(L, filename, "r");
  262. lua_replace(L, 1); /* put file at index 1 */
  263. toclose = 1; /* close it after iteration */
  264. }
  265. aux_lines(L, toclose);
  266. return 1;
  267. }
  268. /*
  269. ** {======================================================
  270. ** READ
  271. ** =======================================================
  272. */
  273. static int read_integer (lua_State *L, FILE *f) {
  274. lua_Integer d;
  275. if (fscanf(f, LUA_INTEGER_SCAN, &d) == 1) {
  276. lua_pushinteger(L, d);
  277. return 1;
  278. }
  279. else {
  280. lua_pushnil(L); /* "result" to be removed */
  281. return 0; /* read fails */
  282. }
  283. }
  284. static int read_number (lua_State *L, FILE *f) {
  285. lua_Number d;
  286. if (fscanf(f, LUA_NUMBER_SCAN, &d) == 1) {
  287. lua_pushnumber(L, d);
  288. return 1;
  289. }
  290. else {
  291. lua_pushnil(L); /* "result" to be removed */
  292. return 0; /* read fails */
  293. }
  294. }
  295. static int test_eof (lua_State *L, FILE *f) {
  296. int c = getc(f);
  297. ungetc(c, f); /* no-op when c == EOF */
  298. lua_pushlstring(L, NULL, 0);
  299. return (c != EOF);
  300. }
  301. static int read_line (lua_State *L, FILE *f, int chop) {
  302. luaL_Buffer b;
  303. int c;
  304. luaL_buffinit(L, &b);
  305. l_lockfile(f);
  306. while ((c = l_getc(f)) != EOF && c != '\n')
  307. luaL_addchar(&b, c);
  308. l_unlockfile(f);
  309. if (!chop && c == '\n') luaL_addchar(&b, c);
  310. luaL_pushresult(&b); /* close buffer */
  311. return (c == '\n' || lua_rawlen(L, -1) > 0);
  312. }
  313. static void read_all (lua_State *L, FILE *f) {
  314. size_t nr;
  315. luaL_Buffer b;
  316. luaL_buffinit(L, &b);
  317. do { /* read file in chunks of LUAL_BUFFERSIZE bytes */
  318. char *p = luaL_prepbuffsize(&b, LUAL_BUFFERSIZE);
  319. nr = fread(p, sizeof(char), LUAL_BUFFERSIZE, f);
  320. luaL_addsize(&b, nr);
  321. } while (nr == LUAL_BUFFERSIZE);
  322. luaL_pushresult(&b); /* close buffer */
  323. }
  324. static int read_chars (lua_State *L, FILE *f, size_t n) {
  325. size_t nr; /* number of chars actually read */
  326. char *p;
  327. luaL_Buffer b;
  328. luaL_buffinit(L, &b);
  329. p = luaL_prepbuffsize(&b, n); /* prepare buffer to read whole block */
  330. nr = fread(p, sizeof(char), n, f); /* try to read 'n' chars */
  331. luaL_addsize(&b, nr);
  332. luaL_pushresult(&b); /* close buffer */
  333. return (nr > 0); /* true iff read something */
  334. }
  335. static int g_read (lua_State *L, FILE *f, int first) {
  336. int nargs = lua_gettop(L) - 1;
  337. int success;
  338. int n;
  339. clearerr(f);
  340. if (nargs == 0) { /* no arguments? */
  341. success = read_line(L, f, 1);
  342. n = first+1; /* to return 1 result */
  343. }
  344. else { /* ensure stack space for all results and for auxlib's buffer */
  345. luaL_checkstack(L, nargs+LUA_MINSTACK, "too many arguments");
  346. success = 1;
  347. for (n = first; nargs-- && success; n++) {
  348. if (lua_type(L, n) == LUA_TNUMBER) {
  349. size_t l = (size_t)lua_tointeger(L, n);
  350. success = (l == 0) ? test_eof(L, f) : read_chars(L, f, l);
  351. }
  352. else {
  353. const char *p = luaL_checkstring(L, n);
  354. if (*p == '*') p++; /* skip optional '*' (for compatibility) */
  355. switch (*p) {
  356. case 'i': /* integer */
  357. success = read_integer(L, f);
  358. break;
  359. case 'n': /* number */
  360. success = read_number(L, f);
  361. break;
  362. case 'l': /* line */
  363. success = read_line(L, f, 1);
  364. break;
  365. case 'L': /* line with end-of-line */
  366. success = read_line(L, f, 0);
  367. break;
  368. case 'a': /* file */
  369. read_all(L, f); /* read entire file */
  370. success = 1; /* always success */
  371. break;
  372. default:
  373. return luaL_argerror(L, n, "invalid format");
  374. }
  375. }
  376. }
  377. }
  378. if (ferror(f))
  379. return luaL_fileresult(L, 0, NULL);
  380. if (!success) {
  381. lua_pop(L, 1); /* remove last result */
  382. lua_pushnil(L); /* push nil instead */
  383. }
  384. return n - first;
  385. }
  386. static int io_read (lua_State *L) {
  387. return g_read(L, getiofile(L, IO_INPUT), 1);
  388. }
  389. static int f_read (lua_State *L) {
  390. return g_read(L, tofile(L), 2);
  391. }
  392. static int io_readline (lua_State *L) {
  393. LStream *p = (LStream *)lua_touserdata(L, lua_upvalueindex(1));
  394. int i;
  395. int n = (int)lua_tointeger(L, lua_upvalueindex(2));
  396. if (isclosed(p)) /* file is already closed? */
  397. return luaL_error(L, "file is already closed");
  398. lua_settop(L , 1);
  399. for (i = 1; i <= n; i++) /* push arguments to 'g_read' */
  400. lua_pushvalue(L, lua_upvalueindex(3 + i));
  401. n = g_read(L, p->f, 2); /* 'n' is number of results */
  402. lua_assert(n > 0); /* should return at least a nil */
  403. if (!lua_isnil(L, -n)) /* read at least one value? */
  404. return n; /* return them */
  405. else { /* first result is nil: EOF or error */
  406. if (n > 1) { /* is there error information? */
  407. /* 2nd result is error message */
  408. return luaL_error(L, "%s", lua_tostring(L, -n + 1));
  409. }
  410. if (lua_toboolean(L, lua_upvalueindex(3))) { /* generator created file? */
  411. lua_settop(L, 0);
  412. lua_pushvalue(L, lua_upvalueindex(1));
  413. aux_close(L); /* close it */
  414. }
  415. return 0;
  416. }
  417. }
  418. /* }====================================================== */
  419. static int g_write (lua_State *L, FILE *f, int arg) {
  420. int nargs = lua_gettop(L) - arg;
  421. int status = 1;
  422. for (; nargs--; arg++) {
  423. if (lua_type(L, arg) == LUA_TNUMBER) {
  424. /* optimization: could be done exactly as for strings */
  425. int len = lua_isinteger(L, arg)
  426. ? fprintf(f, LUA_INTEGER_FMT, lua_tointeger(L, arg))
  427. : fprintf(f, LUA_NUMBER_FMT, lua_tonumber(L, arg));
  428. status = status && (len > 0);
  429. }
  430. else {
  431. size_t l;
  432. const char *s = luaL_checklstring(L, arg, &l);
  433. status = status && (fwrite(s, sizeof(char), l, f) == l);
  434. }
  435. }
  436. if (status) return 1; /* file handle already on stack top */
  437. else return luaL_fileresult(L, status, NULL);
  438. }
  439. static int io_write (lua_State *L) {
  440. return g_write(L, getiofile(L, IO_OUTPUT), 1);
  441. }
  442. static int f_write (lua_State *L) {
  443. FILE *f = tofile(L);
  444. lua_pushvalue(L, 1); /* push file at the stack top (to be returned) */
  445. return g_write(L, f, 2);
  446. }
  447. static int f_seek (lua_State *L) {
  448. static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
  449. static const char *const modenames[] = {"set", "cur", "end", NULL};
  450. FILE *f = tofile(L);
  451. int op = luaL_checkoption(L, 2, "cur", modenames);
  452. lua_Integer p3 = luaL_optinteger(L, 3, 0);
  453. l_seeknum offset = (l_seeknum)p3;
  454. luaL_argcheck(L, (lua_Integer)offset == p3, 3,
  455. "not an integer in proper range");
  456. op = l_fseek(f, offset, mode[op]);
  457. if (op)
  458. return luaL_fileresult(L, 0, NULL); /* error */
  459. else {
  460. lua_pushinteger(L, (lua_Integer)l_ftell(f));
  461. return 1;
  462. }
  463. }
  464. static int f_setvbuf (lua_State *L) {
  465. static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
  466. static const char *const modenames[] = {"no", "full", "line", NULL};
  467. FILE *f = tofile(L);
  468. int op = luaL_checkoption(L, 2, NULL, modenames);
  469. lua_Integer sz = luaL_optinteger(L, 3, LUAL_BUFFERSIZE);
  470. int res = setvbuf(f, NULL, mode[op], sz);
  471. return luaL_fileresult(L, res == 0, NULL);
  472. }
  473. static int io_flush (lua_State *L) {
  474. return luaL_fileresult(L, fflush(getiofile(L, IO_OUTPUT)) == 0, NULL);
  475. }
  476. static int f_flush (lua_State *L) {
  477. return luaL_fileresult(L, fflush(tofile(L)) == 0, NULL);
  478. }
  479. /*
  480. ** functions for 'io' library
  481. */
  482. static const luaL_Reg iolib[] = {
  483. {"close", io_close},
  484. {"flush", io_flush},
  485. {"input", io_input},
  486. {"lines", io_lines},
  487. {"open", io_open},
  488. {"output", io_output},
  489. {"popen", io_popen},
  490. {"read", io_read},
  491. {"tmpfile", io_tmpfile},
  492. {"type", io_type},
  493. {"write", io_write},
  494. {NULL, NULL}
  495. };
  496. /*
  497. ** methods for file handles
  498. */
  499. static const luaL_Reg flib[] = {
  500. {"close", io_close},
  501. {"flush", f_flush},
  502. {"lines", f_lines},
  503. {"read", f_read},
  504. {"seek", f_seek},
  505. {"setvbuf", f_setvbuf},
  506. {"write", f_write},
  507. {"__gc", f_gc},
  508. {"__tostring", f_tostring},
  509. {NULL, NULL}
  510. };
  511. static void createmeta (lua_State *L) {
  512. luaL_newmetatable(L, LUA_FILEHANDLE); /* create metatable for file handles */
  513. lua_pushvalue(L, -1); /* push metatable */
  514. lua_setfield(L, -2, "__index"); /* metatable.__index = metatable */
  515. luaL_setfuncs(L, flib, 0); /* add file methods to new metatable */
  516. lua_pop(L, 1); /* pop new metatable */
  517. }
  518. /*
  519. ** function to (not) close the standard files stdin, stdout, and stderr
  520. */
  521. static int io_noclose (lua_State *L) {
  522. LStream *p = tolstream(L);
  523. p->closef = &io_noclose; /* keep file opened */
  524. lua_pushnil(L);
  525. lua_pushliteral(L, "cannot close standard file");
  526. return 2;
  527. }
  528. static void createstdfile (lua_State *L, FILE *f, const char *k,
  529. const char *fname) {
  530. LStream *p = newprefile(L);
  531. p->f = f;
  532. p->closef = &io_noclose;
  533. if (k != NULL) {
  534. lua_pushvalue(L, -1);
  535. lua_setfield(L, LUA_REGISTRYINDEX, k); /* add file to registry */
  536. }
  537. lua_setfield(L, -2, fname); /* add file to module */
  538. }
  539. LUAMOD_API int luaopen_io (lua_State *L) {
  540. luaL_newlib(L, iolib); /* new module */
  541. createmeta(L);
  542. /* create (and set) default files */
  543. createstdfile(L, stdin, IO_INPUT, "stdin");
  544. createstdfile(L, stdout, IO_OUTPUT, "stdout");
  545. createstdfile(L, stderr, NULL, "stderr");
  546. return 1;
  547. }