** returns a pointer to a free area with at least 'sz' bytes */
| 395 | ** returns a pointer to a free area with at least 'sz' bytes |
| 396 | */ |
| 397 | LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) { |
| 398 | lua_State *L = B->L; |
| 399 | if (B->size - B->n < sz) { /* not enough space? */ |
| 400 | char *newbuff; |
| 401 | size_t newsize = B->size * 2; /* double buffer size */ |
| 402 | if (newsize - B->n < sz) /* not big enough? */ |
| 403 | newsize = B->n + sz; |
| 404 | if (newsize < B->n || newsize - B->n < sz) |
| 405 | luaL_error(L, "buffer too large"); |
| 406 | /* create larger buffer */ |
| 407 | newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char)); |
| 408 | /* move content to new buffer */ |
| 409 | memcpy(newbuff, B->b, B->n * sizeof(char)); |
| 410 | if (buffonstack(B)) |
| 411 | lua_remove(L, -2); /* remove old buffer */ |
| 412 | B->b = newbuff; |
| 413 | B->size = newsize; |
| 414 | } |
| 415 | return &B->b[B->n]; |
| 416 | } |
| 417 | |
| 418 | |
| 419 | LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) { |
no test coverage detected