mirror of https://github.com/rusefi/lua.git
easy the way to accept other modifiers for 'mode' in 'io.open'
This commit is contained in:
parent
f230898ad6
commit
71344b5cac
20
liolib.c
20
liolib.c
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
** $Id: liolib.c,v 2.146 2015/07/07 17:03:34 roberto Exp roberto $
|
** $Id: liolib.c,v 2.147 2015/07/15 14:40:28 roberto Exp roberto $
|
||||||
** Standard I/O (and system) library
|
** Standard I/O (and system) library
|
||||||
** See Copyright Notice in lua.h
|
** See Copyright Notice in lua.h
|
||||||
*/
|
*/
|
||||||
|
@ -23,18 +23,24 @@
|
||||||
#include "lualib.h"
|
#include "lualib.h"
|
||||||
|
|
||||||
|
|
||||||
#if !defined(l_checkmode)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Check whether 'mode' matches '[rwa]%+?b?'.
|
|
||||||
** Change this macro to accept other modes for 'fopen' besides
|
** Change this macro to accept other modes for 'fopen' besides
|
||||||
** the standard ones.
|
** the standard ones.
|
||||||
*/
|
*/
|
||||||
|
#if !defined(l_checkmode)
|
||||||
|
|
||||||
|
/* accepted extensions to 'mode' in 'fopen' */
|
||||||
|
#if !defined(L_MODEEXT)
|
||||||
|
#define L_MODEEXT "b"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */
|
||||||
#define l_checkmode(mode) \
|
#define l_checkmode(mode) \
|
||||||
(*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
|
(*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
|
||||||
(*mode != '+' || ++mode) && /* skip if char is '+' */ \
|
(*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ \
|
||||||
(*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
|
(strspn(mode, L_MODEEXT) == strlen(mode)))
|
||||||
(*mode == '\0'))
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -469,7 +475,7 @@ static int read_line (lua_State *L, FILE *f, int chop) {
|
||||||
int c = '\0';
|
int c = '\0';
|
||||||
luaL_buffinit(L, &b);
|
luaL_buffinit(L, &b);
|
||||||
while (c != EOF && c != '\n') { /* repeat until end of line */
|
while (c != EOF && c != '\n') { /* repeat until end of line */
|
||||||
char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */
|
char *buff = luaL_prepbuffer(&b); /* preallocate buffer */
|
||||||
int i = 0;
|
int i = 0;
|
||||||
l_lockfile(f); /* no memory errors can happen inside the lock */
|
l_lockfile(f); /* no memory errors can happen inside the lock */
|
||||||
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
|
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')
|
||||||
|
|
Loading…
Reference in New Issue