diff options
Diffstat (limited to 'liolib.c')
-rw-r--r-- | liolib.c | 20 |
1 files changed, 13 insertions, 7 deletions
@@ -1,5 +1,5 @@ | |||
1 | /* | 1 | /* |
2 | ** $Id: liolib.c,v 2.146 2015/07/07 17:03:34 roberto Exp roberto $ | 2 | ** $Id: liolib.c,v 2.147 2015/07/15 14:40:28 roberto Exp roberto $ |
3 | ** Standard I/O (and system) library | 3 | ** Standard I/O (and system) library |
4 | ** See Copyright Notice in lua.h | 4 | ** See Copyright Notice in lua.h |
5 | */ | 5 | */ |
@@ -23,18 +23,24 @@ | |||
23 | #include "lualib.h" | 23 | #include "lualib.h" |
24 | 24 | ||
25 | 25 | ||
26 | #if !defined(l_checkmode) | 26 | |
27 | 27 | ||
28 | /* | 28 | /* |
29 | ** Check whether 'mode' matches '[rwa]%+?b?'. | ||
30 | ** Change this macro to accept other modes for 'fopen' besides | 29 | ** Change this macro to accept other modes for 'fopen' besides |
31 | ** the standard ones. | 30 | ** the standard ones. |
32 | */ | 31 | */ |
32 | #if !defined(l_checkmode) | ||
33 | |||
34 | /* accepted extensions to 'mode' in 'fopen' */ | ||
35 | #if !defined(L_MODEEXT) | ||
36 | #define L_MODEEXT "b" | ||
37 | #endif | ||
38 | |||
39 | /* Check whether 'mode' matches '[rwa]%+?[L_MODEEXT]*' */ | ||
33 | #define l_checkmode(mode) \ | 40 | #define l_checkmode(mode) \ |
34 | (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \ | 41 | (*mode != '\0' && strchr("rwa", *(mode++)) != NULL && \ |
35 | (*mode != '+' || ++mode) && /* skip if char is '+' */ \ | 42 | (*mode != '+' || (++mode, 1)) && /* skip if char is '+' */ \ |
36 | (*mode != 'b' || ++mode) && /* skip if char is 'b' */ \ | 43 | (strspn(mode, L_MODEEXT) == strlen(mode))) |
37 | (*mode == '\0')) | ||
38 | 44 | ||
39 | #endif | 45 | #endif |
40 | 46 | ||
@@ -469,7 +475,7 @@ static int read_line (lua_State *L, FILE *f, int chop) { | |||
469 | int c = '\0'; | 475 | int c = '\0'; |
470 | luaL_buffinit(L, &b); | 476 | luaL_buffinit(L, &b); |
471 | while (c != EOF && c != '\n') { /* repeat until end of line */ | 477 | while (c != EOF && c != '\n') { /* repeat until end of line */ |
472 | char *buff = luaL_prepbuffer(&b); /* pre-allocate buffer */ | 478 | char *buff = luaL_prepbuffer(&b); /* preallocate buffer */ |
473 | int i = 0; | 479 | int i = 0; |
474 | l_lockfile(f); /* no memory errors can happen inside the lock */ | 480 | l_lockfile(f); /* no memory errors can happen inside the lock */ |
475 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') | 481 | while (i < LUAL_BUFFERSIZE && (c = l_getc(f)) != EOF && c != '\n') |