MCPcopy Create free account
hub / github.com/F-Stack/f-stack / luaL_prepbuffsize

Function luaL_prepbuffsize

freebsd/contrib/openzfs/module/lua/lauxlib.c:397–416  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

395** returns a pointer to a free area with at least 'sz' bytes
396*/
397LUALIB_API char *luaL_prepbuffsize (luaL_Buffer *B, size_t sz) {
398 lua_State *L = B->L;
399 if (B->size - B->n < sz) { /* not enough space? */
400 char *newbuff;
401 size_t newsize = B->size * 2; /* double buffer size */
402 if (newsize - B->n < sz) /* not big enough? */
403 newsize = B->n + sz;
404 if (newsize < B->n || newsize - B->n < sz)
405 luaL_error(L, "buffer too large");
406 /* create larger buffer */
407 newbuff = (char *)lua_newuserdata(L, newsize * sizeof(char));
408 /* move content to new buffer */
409 memcpy(newbuff, B->b, B->n * sizeof(char));
410 if (buffonstack(B))
411 lua_remove(L, -2); /* remove old buffer */
412 B->b = newbuff;
413 B->size = newsize;
414 }
415 return &B->b[B->n];
416}
417
418
419LUALIB_API void luaL_addlstring (luaL_Buffer *B, const char *s, size_t l) {

Callers 3

str_formatFunction · 0.85
luaL_addlstringFunction · 0.85
luaL_buffinitsizeFunction · 0.85

Calls 4

luaL_errorFunction · 0.70
lua_newuserdataFunction · 0.70
lua_removeFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected