MCPcopy Create free account
hub / github.com/ObEngine/ObEngine / prepbuffsize

Function prepbuffsize

extlibs/lua/src/lauxlib.c:535–558  ·  view source on GitHub ↗

** 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. */

Source from the content-addressed store, hash-verified

533** buffer's box is or should be.
534*/
535static 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

Callers 4

luaL_prepbuffsizeFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_addvalueFunction · 0.85
luaL_buffinitsizeFunction · 0.85

Calls 6

newbuffsizeFunction · 0.85
resizeboxFunction · 0.85
lua_pushnilFunction · 0.85
newboxFunction · 0.85
lua_tocloseFunction · 0.85
lua_rotateFunction · 0.70

Tested by

no test coverage detected