** returns a pointer to a free area with at least 'sz' bytes */
| 446 | ** returns a pointer to a free area with at least 'sz' bytes |
| 447 | */ |
| 448 | LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { |
| 449 | lua_State *L = B->L; |
| 450 | if (B->size - B->n < sz) { /* not enough space? */ |
| 451 | char *newbuff; |
| 452 | size_t newsize = B->size * 2; /* double buffer size */ |
| 453 | if (newsize - B->n < sz) /* not big enough? */ |
| 454 | newsize = B->n + sz; |
| 455 | if (newsize < B->n || newsize - B->n < sz) |
| 456 | luaL_error(L, "buffer too large"); |
| 457 | /* create larger buffer */ |
| 458 | newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char)); |
| 459 | /* move content to new buffer */ |
| 460 | memcpy(newbuff, B->b, B->n * sizeof(char)); |
| 461 | if (buffonstack(B)) |
| 462 | lua_remove(L, -2); /* remove old buffer */ |
| 463 | B->b = newbuff; |
| 464 | B->size = newsize; |
| 465 | } |
| 466 | return &B->b[B->n]; |
| 467 | } |
| 468 | |
| 469 | |
| 470 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { |
no test coverage detected