liolib.c 17 KB

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