** Returns a pointer to a free area with at least 'sz' bytes in buffer ** 'B'. 'boxidx' is the relative position in the stack where is the ** buffer's box or its placeholder. */
| 548 | ** buffer's box or its placeholder. |
| 549 | */ |
| 550 | static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) { |
| 551 | checkbufferlevel(B, boxidx); |
| 552 | if (B->size - B->n >= sz) /* enough space? */ |
| 553 | return B->b + B->n; |
| 554 | else { |
| 555 | lua_State *L = B->L; |
| 556 | char *newbuff; |
| 557 | size_t newsize = newbuffsize(B, sz); |
| 558 | /* create larger buffer */ |
| 559 | if (buffonstack(B)) /* buffer already has a box? */ |
| 560 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ |
| 561 | else { /* no box yet */ |
| 562 | lua_remove(L, boxidx); /* remove placeholder */ |
| 563 | newbox(L); /* create a new box */ |
| 564 | lua_insert(L, boxidx); /* move box to its intended position */ |
| 565 | lua_toclose(L, boxidx); |
| 566 | newbuff = (char *)resizebox(L, boxidx, newsize); |
| 567 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ |
| 568 | } |
| 569 | B->b = newbuff; |
| 570 | B->size = newsize; |
| 571 | return newbuff + B->n; |
| 572 | } |
| 573 | } |
| 574 | |
| 575 | /* |
| 576 | ** returns a pointer to a free area with at least 'sz' bytes |
no test coverage detected