MCPcopy Create free account
hub / github.com/DFHack/dfhack / luaL_prepbuffsize

Function luaL_prepbuffsize

depends/lua/src/lauxlib.c:505–525  ·  view source on GitHub ↗

** returns a pointer to a free area with at least 'sz' bytes */

Source from the content-addressed store, hash-verified

503** returns a pointer to a free area with at least 'sz' bytes
504*/
505LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
506 lua_State *L = B->L;
507 if (B->size - B->n < sz) { /* not enough space? */
508 char *newbuff;
509 size_t newsize = B->size * 2; /* double buffer size */
510 if (newsize - B->n < sz) /* not big enough? */
511 newsize = B->n + sz;
512 if (newsize < B->n || newsize - B->n < sz)
513 luaL_error(L, "buffer too large");
514 /* create larger buffer */
515 if (buffonstack(B))
516 newbuff = (char *)resizebox(L, -1, newsize);
517 else { /* no buffer yet */
518 newbuff = (char *)newbox(L, newsize);
519 memcpy(newbuff, B->b, B->n * sizeof(char)); /* copy original content */
520 }
521 B->b = newbuff;
522 B->size = newsize;
523 }
524 return &B->b[B->n];
525}
526
527
528LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {

Callers 8

addliteralFunction · 0.85
str_formatFunction · 0.85
packintFunction · 0.85
str_packFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_buffinitsizeFunction · 0.85
os_dateFunction · 0.85
read_charsFunction · 0.85

Calls 3

luaL_errorFunction · 0.85
resizeboxFunction · 0.85
newboxFunction · 0.85

Tested by

no test coverage detected