summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWilliam Wilgus <me.theuser@yahoo.com>2018-11-02 14:13:27 -0400
committerWilliam Wilgus <me.theuser@yahoo.com>2018-11-02 23:18:30 -0400
commitd9f9def505b367b9361ba96d33e6edf1687716fb (patch)
tree9fd2c48e10c8c193bb6f55fa077eddc237b717c2
parentf6e10b84882387e304467f22ea2f6126cbaa1264 (diff)
downloadrockbox-d9f9def505b367b9361ba96d33e6edf1687716fb.tar.gz
rockbox-d9f9def505b367b9361ba96d33e6edf1687716fb.zip
Lua fix failure to read lines longer than LUAL_BUFFERSIZE
Readline didn't handle lines longer than LUAL_BUFFERSIZE it now reads these in chunks. Change-Id: Iffe12447e5441ff6b479ce3de1d36df64c276183
-rw-r--r--apps/plugins/lua/liolib.c23
1 files changed, 10 insertions, 13 deletions
diff --git a/apps/plugins/lua/liolib.c b/apps/plugins/lua/liolib.c
index 6744efedd5..fb6765492b 100644
--- a/apps/plugins/lua/liolib.c
+++ b/apps/plugins/lua/liolib.c
@@ -269,22 +269,19 @@ static int _read_line (lua_State *L, int *f) {
269 luaL_buffinit(L, &b); 269 luaL_buffinit(L, &b);
270 for (;;) { 270 for (;;) {
271 size_t l; 271 size_t l;
272 off_t r;
273 char *p = luaL_prepbuffer(&b); 272 char *p = luaL_prepbuffer(&b);
274 r = rb->read_line(*f, p, LUAL_BUFFERSIZE); 273 off_t r = rb->read_line(*f, p, LUAL_BUFFERSIZE); /* does not include `eol' */
275 l = strlen(p); 274 if (r <= 0) { /* eof? */
276
277 if (l == 0 || p[l-1] != '\n')
278 luaL_addsize(&b, l);
279 else {
280 luaL_addsize(&b, l - 1); /* do not include `eol' */
281 luaL_pushresult(&b); /* close buffer */ 275 luaL_pushresult(&b); /* close buffer */
282 return 1; /* read at least an `eol' */ 276 return (lua_objlen(L, -1) > 0); /* check whether read something */
283 }
284 if (r < LUAL_BUFFERSIZE) { /* eof? */
285 luaL_pushresult(&b); /* close buffer */
286 return (r > 0); /* check whether read something */
287 } 277 }
278 l = strlen(p);
279 luaL_addsize(&b, l);
280 if(r >= LUAL_BUFFERSIZE - 1)
281 continue; /* more to read */
282
283 luaL_pushresult(&b); /* close buffer */
284 return 1; /* we read at least 1 character */
288 } 285 }
289} 286}
290 287