commit 71344b5cacce22a7a2a5dcdaccf4340420b0afa1
parent f230898ad6f1d3fd1bc0216b2f4a504db112f2df
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Mon, 23 Nov 2015 09:35:45 -0200
easy the way to accept other modifiers for 'mode' in 'io.open'
Diffstat:
1 file changed, 13 insertions(+), 7 deletions(-)
diff --git a/liolib.c b/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
** See Copyright Notice in lua.h
*/
@@ -23,18 +23,24 @@
#include "lualib.h"
-#if !defined(l_checkmode)
+
/*
-** Check whether 'mode' matches '[rwa]%+?b?'.
** Change this macro to accept other modes for 'fopen' besides
** 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) \
(*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \
- (*mode != '+' || ++mode) && /* skip if char is '+' */ \
- (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \
- (*mode == '\0'))
+ (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ \
+ (strspn(mode, L_MODEEXT) == strlen(mode)))
#endif
@@ -469,7 +475,7 @@ static int read_line (lua_State *L, FILE *f, int chop) {
int c = '\0';
luaL_buffinit(L, &b);
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;
l_lockfile(f); /* no memory errors can happen inside the lock */
while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n')