** Returns a pointer to a free area with at least 'sz' bytes in buffer ** 'B'. 'boxidx' is the relative position in the stack where the ** buffer's box is or should be. */
| 533 | ** buffer's box is or should be. |
| 534 | */ |
| 535 | static char *prepbuffsize (luaL_Buffer *B, size_t sz, int boxidx) { |
| 536 | if (B->size - B->n >= sz) /* enough space? */ |
| 537 | return B->b + B->n; |
| 538 | else { |
| 539 | lua_State *L = B->L; |
| 540 | char *newbuff; |
| 541 | size_t newsize = newbuffsize(B, sz); |
| 542 | /* create larger buffer */ |
| 543 | if (buffonstack(B)) /* buffer already has a box? */ |
| 544 | newbuff = (char *)resizebox(L, boxidx, newsize); /* resize it */ |
| 545 | else { /* no box yet */ |
| 546 | lua_pushnil(L); /* reserve slot for final result */ |
| 547 | newbox(L); /* create a new box */ |
| 548 | /* move box (and slot) to its intended position */ |
| 549 | lua_rotate(L, boxidx - 1, 2); |
| 550 | lua_toclose(L, boxidx); |
| 551 | newbuff = (char *)resizebox(L, boxidx, newsize); |
| 552 | memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */ |
| 553 | } |
| 554 | B->b = newbuff; |
| 555 | B->size = newsize; |
| 556 | return newbuff + B->n; |
| 557 | } |
| 558 | } |
| 559 | |
| 560 | /* |
| 561 | ** returns a pointer to a free area with at least 'sz' bytes |
no test coverage detected