32#if !defined(l_checkmode)
35#if !defined(L_MODEEXT)
41 return (*mode !=
'\0' && strchr(
"rwa", *(mode++)) !=
NULL &&
42 (*mode !=
'+' || (++mode, 1)) &&
43 (strspn(mode,
L_MODEEXT) == strlen(mode)));
57#if defined(LUA_USE_POSIX)
59#define l_popen(L,c,m) (fflush(NULL), popen(c,m))
60#define l_pclose(L,file) (pclose(file))
62#elif defined(LUA_USE_WINDOWS)
64#define l_popen(L,c,m) (_popen(c,m))
65#define l_pclose(L,file) (_pclose(file))
70#define l_popen(L,c,m) \
71 ((void)((void)c, m), \
72 luaL_error(L, "'popen' not supported"), \
74#define l_pclose(L,file) ((void)L, (void)file, -1)
85#if defined(LUA_USE_POSIX)
86#define l_getc(f) getc_unlocked(f)
87#define l_lockfile(f) flockfile(f)
88#define l_unlockfile(f) funlockfile(f)
90#define l_getc(f) getc(f)
91#define l_lockfile(f) ((void)0)
92#define l_unlockfile(f) ((void)0)
106#if defined(LUA_USE_POSIX)
108#include <sys/types.h>
110#define l_fseek(f,o,w) fseeko(f,o,w)
111#define l_ftell(f) ftello(f)
112#define l_seeknum off_t
114#elif defined(LUA_USE_WINDOWS) && !defined(_CRTIMP_TYPEINFO) \
115 && defined(_MSC_VER) && (_MSC_VER >= 1400)
118#define l_fseek(f,o,w) _fseeki64(f,o,w)
119#define l_ftell(f) _ftelli64(f)
120#define l_seeknum __int64
125#define l_fseek(f,o,w) fseek(f,o,w)
126#define l_ftell(f) ftell(f)
127#define l_seeknum long
136#define IO_PREFIX "_IO_"
137#define IOPREF_LEN (sizeof(IO_PREFIX)/sizeof(char) - 1)
138#define IO_INPUT (IO_PREFIX "input")
139#define IO_OUTPUT (IO_PREFIX "output")
145#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
147#define isclosed(p) ((p)->closef == NULL)
177 luaL_error(L,
"attempt to use a closed file");
235 int res = fclose(p->
f);
250 p->
f = fopen(fname, mode);
252 luaL_error(L,
"cannot open file '%s' (%s)", fname, strerror(errno));
260 const char *md = mode;
262 p->
f = fopen(filename, mode);
280 luaL_argcheck(L, ((mode[0] ==
'r' || mode[0] ==
'w') && mode[1] ==
'\0'),
339#define MAXARGLINE 250
386#if !defined (L_MAXLENNUM)
387#define L_MAXLENNUM 200
409 rn->
buff[rn->
n++] = rn->
c;
420 if (rn->
c == set[0] || rn->
c == set[1])
431 while ((hex ? isxdigit(rn->
c) : isdigit(rn->
c)) &&
nextc(rn))
451 do { rn.
c =
l_getc(rn.
f); }
while (isspace(rn.
c));
453 if (
test2(&rn,
"00")) {
454 if (
test2(&rn,
"xX")) hex = 1;
458 if (
test2(&rn, decp))
460 if (count > 0 &&
test2(&rn, (hex ?
"pP" :
"eE"))) {
466 rn.
buff[rn.
n] =
'\0';
488 while (c != EOF && c !=
'\n') {
497 if (!chop && c ==
'\n')
524 nr =
fread(p,
sizeof(
char), n, f);
543 for (n = first; nargs-- && success; n++) {
596 return luaL_error(L,
"file is already closed");
599 for (i = 1; i <= n; i++)
625 for (; nargs--;
arg++) {
633 status = status && (len > 0);
638 status = status && (
fwrite(
s,
sizeof(
char), l, f) == l);
641 if (status)
return 1;
659 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
660 static const char *
const modenames[] = {
"set",
"cur",
"end",
NULL};
666 "not an integer in proper range");
667 op =
l_fseek(f, offset, mode[op]);
678 static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
679 static const char *
const modenames[] = {
"no",
"full",
"line",
NULL};
683 int res = setvbuf(f,
NULL, mode[op], (
size_t)sz);
#define lua_rawlen(L, index)
CURL_EXTERN int void * arg
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUA_API void lua_pushnil(lua_State *L)
LUA_API const char * lua_pushfstring(lua_State *L, const char *fmt,...)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API void lua_pushboolean(lua_State *L, int b)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API void * lua_touserdata(lua_State *L, int idx)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *mes)
LUALIB_API int luaL_newmetatable(lua_State *L, const char *tname)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUALIB_API void luaL_checkany(lua_State *L, int narg)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
LUALIB_API int luaL_checkoption(lua_State *L, int narg, const char *def, const char *const lst[])
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
#define luaL_addsize(B, n)
#define luaL_addchar(B, c)
#define luaL_optstring(L, n, d)
#define luaL_checkstring(L, n)
#define luaL_argcheck(L, cond, numarg, extramsg)
#define LUA_REGISTRYINDEX
#define lua_pushliteral(L, s)
int(* lua_CFunction)(lua_State *L)
#define lua_upvalueindex(i)
#define lua_tostring(L, i)
#define lua_isnoneornil(L, n)
LUALIB_API void * luaL_testudata(lua_State *L, int ud, const char *tname)
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
LUALIB_API int luaL_execresult(lua_State *L, int stat)
LUALIB_API void luaL_setfuncs(lua_State *L, const luaL_Reg *l, int nup)
LUALIB_API int luaL_fileresult(lua_State *L, int stat, const char *fname)
LUALIB_API void luaL_setmetatable(lua_State *L, const char *tname)
#define luaL_newlib(L, l)
#define luaL_prepbuffer(B)
#define lua_tointeger(L, i)
#define lua_tonumber(L, i)
LUA_API size_t lua_stringtonumber(lua_State *L, const char *s)
LUA_API int lua_isinteger(lua_State *L, int idx)
LUA_API void lua_rotate(lua_State *L, int idx, int n)
static int io_tmpfile(lua_State *L)
static void createstdfile(lua_State *L, FILE *f, const char *k, const char *fname)
static int aux_close(lua_State *L)
static int io_close(lua_State *L)
#define l_pclose(L, file)
static int f_close(lua_State *L)
static int io_type(lua_State *L)
LUAMOD_API int luaopen_io(lua_State *L)
static void createmeta(lua_State *L)
static int io_flush(lua_State *L)
static int io_output(lua_State *L)
static int io_read(lua_State *L)
static void read_all(lua_State *L, FILE *f)
static int read_number(lua_State *L, FILE *f)
static int f_gc(lua_State *L)
static int test2(RN *rn, const char *set)
static void aux_lines(lua_State *L, int toclose)
static int read_chars(lua_State *L, FILE *f, size_t n)
static int io_fclose(lua_State *L)
static int f_lines(lua_State *L)
static int readdigits(RN *rn, int hex)
static int io_noclose(lua_State *L)
static FILE * getiofile(lua_State *L, const char *findex)
static FILE * tofile(lua_State *L)
static const luaL_Reg flib[]
static int io_input(lua_State *L)
static int g_write(lua_State *L, FILE *f, int arg)
static int io_popen(lua_State *L)
static const luaL_Reg iolib[]
static void opencheck(lua_State *L, const char *fname, const char *mode)
static int f_setvbuf(lua_State *L)
static int g_iofile(lua_State *L, const char *f, const char *mode)
static int io_lines(lua_State *L)
static int l_checkmode(const char *mode)
static int io_open(lua_State *L)
static LStream * newfile(lua_State *L)
static int io_readline(lua_State *L)
static int io_pclose(lua_State *L)
static int f_seek(lua_State *L)
static int test_eof(lua_State *L, FILE *f)
static int f_flush(lua_State *L)
static LStream * newprefile(lua_State *L)
static int io_write(lua_State *L)
static int f_write(lua_State *L)
static int f_read(lua_State *L)
static int g_read(lua_State *L, FILE *f, int first)
static int read_line(lua_State *L, FILE *f, int chop)
static int f_tostring(lua_State *L)
#define lua_replace(L, idx)
#define lua_getlocaledecpoint()
#define lua_newuserdata(L, s)
CURL_EXTERN CURLMcode curl_socket_t s