** 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. */
| 562 | ** buffer's box or its placeholder. |
| 563 | */ |
| 564 | static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) { |
| 565 | checkbufferlevel(B, boxidx); |
| 566 | if (B->size - B->n >= sz) /* enough space? */ |
| 567 | return B->b + B->n; |
| 568 | else { |
| 569 | lua_State *L = B->L; |
| 570 | char *newbuff; |
| 571 | size_t newsize = newbuffsize(B, sz); |
| 572 | /* create larger buffer */ |
| 573 | if (buffonstack(B)) /* buffer already has a box? */ |
| 574 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ |
| 575 | else { /* no box yet */ |
| 576 | lua_remove(L, boxidx); /* remove placeholder */ |
| 577 | newbox(L); /* create a new box */ |
| 578 | lua_insert(L, boxidx); /* move box to its intended position */ |
| 579 | lua_toclose(L, boxidx); |
| 580 | newbuff = (char *)resizebox(L, boxidx, newsize); |
| 581 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ |
| 582 | } |
| 583 | B->b = newbuff; |
| 584 | B->size = newsize; |
| 585 | return newbuff + B->n; |
| 586 | } |
| 587 | } |
| 588 | |
| 589 | /* |
| 590 | ** returns a pointer to a free area with at least 'sz' bytes |
no test coverage detected