12#if !defined(_FILE_OFFSET_BITS)
13#define _LARGEFILE_SOURCE 1
14#define _FILE_OFFSET_BITS 64
32#if !defined(lua_checkmode)
39#define lua_checkmode(mode) \
40 (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
41 (*mode != '+' || ++mode) && \
42 (*mode != 'b' || ++mode) && \
54#if !defined(lua_popen)
56#if defined(LUA_USE_POPEN)
58#define lua_popen(L,c,m) ((void)L, fflush(NULL), popen(c,m))
59#define lua_pclose(L,file) ((void)L, pclose(file))
63#define lua_popen(L,c,m) ((void)L, _popen(c,m))
64#define lua_pclose(L,file) ((void)L, _pclose(file))
69#define lua_popen(L,c,m) ((void)((void)c, m), \
70 luaL_error(L, LUA_QL("popen") " not supported"), (FILE*)0)
71#define lua_pclose(L,file) ((void)((void)L, file), -1)
87#if !defined(lua_fseek) && !defined(LUA_ANSI)
89#if defined(LUA_USE_POSIX)
91#define l_fseek(f,o,w) fseeko(f,o,w)
92#define l_ftell(f) ftello(f)
93#define l_seeknum off_t
95#elif defined(LUA_WIN) && !defined(_CRTIMP_TYPEINFO) \
96 && defined(_MSC_VER) && (_MSC_VER >= 1400)
99#define l_fseek(f,o,w) _fseeki64(f,o,w)
100#define l_ftell(f) _ftelli64(f)
101#define l_seeknum __int64
109#define l_fseek(f,o,w) fseek(f,o,w)
110#define l_ftell(f) ftell(f)
111#define l_seeknum long
117#define IO_PREFIX "_IO_"
118#define IO_INPUT (IO_PREFIX "input")
119#define IO_OUTPUT (IO_PREFIX "output")
125#define tolstream(L) ((LStream *)luaL_checkudata(L, 1, LUA_FILEHANDLE))
127#define isclosed(p) ((p)->closef == NULL)
157 luaL_error(L,
"attempt to use a closed file");
205 int res = fclose(p->
f);
220 p->
f = fopen(fname, mode);
230 const char *md = mode;
232 p->
f = fopen(filename, mode);
382 if (l == 0 || p[l-1] !=
'\n')
393#define MAX_SIZE_T (~(size_t)0)
401 size_t nr =
fread(p,
sizeof(
char), rlen, f);
403 if (nr < rlen)
break;
417 nr =
fread(p,
sizeof(
char), n, f);
436 for (n = first; nargs-- && success; n++) {
489 return luaL_error(L,
"file is already closed");
491 for (i = 1; i <= n; i++)
517 for (; nargs--;
arg++) {
526 status = status && (
fwrite(
s,
sizeof(
char), l, f) == l);
529 if (status)
return 1;
547 static const int mode[] = {SEEK_SET, SEEK_CUR, SEEK_END};
548 static const char *
const modenames[] = {
"set",
"cur",
"end",
NULL};
554 "not an integer in proper range");
555 op =
l_fseek(f, offset, mode[op]);
566 static const int mode[] = {_IONBF, _IOFBF, _IOLBF};
567 static const char *
const modenames[] = {
"no",
"full",
"line",
NULL};
571 int res = setvbuf(f,
NULL, mode[op], 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 void lua_pushnumber(lua_State *L, lua_Number n)
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_pushlstring(lua_State *L, const char *s, size_t len)
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 lua_Number luaL_optnumber(lua_State *L, int narg, lua_Number def)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
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_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)
static int io_tmpfile(lua_State *L)
static void createstdfile(lua_State *L, FILE *f, const char *k, const char *fname)
#define lua_pclose(L, file)
static int aux_close(lua_State *L)
static int io_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)
#define lua_popen(L, c, m)
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 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 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)
#define lua_checkmode(mode)
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_tointeger(L, i)
#define lua_tonumber(L, i)
#define lua_replace(L, idx)
#define lua_newuserdata(L, s)
CURL_EXTERN CURLMcode curl_socket_t s