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