MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / prepbuffsize

Function prepbuffsize

lib/lua/src/lauxlib.c:550–573  ·  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 is the ** buffer's box or its placeholder. */

Source from the content-addressed store, hash-verified

548** buffer's box or its placeholder.
549*/
550static 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

Callers 4

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

Calls 4

newbuffsizeFunction · 0.85
resizeboxFunction · 0.85
newboxFunction · 0.85
lua_tocloseFunction · 0.85

Tested by

no test coverage detected