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

Function luaO_chunkid

freebsd/contrib/openzfs/module/lua/lobject.c:247–281  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

245#define addstr(a,b,l) ( memcpy(a,b,(l) * sizeof(char)), a += (l) )
246
247void luaO_chunkid (char *out, const char *source, size_t bufflen) {
248 size_t l = strlen(source);
249 if (*source == '=') { /* 'literal' source */
250 if (l <= bufflen) /* small enough? */
251 memcpy(out, source + 1, l * sizeof(char));
252 else { /* truncate it */
253 addstr(out, source + 1, bufflen - 1);
254 *out = '\0';
255 }
256 }
257 else if (*source == '@') { /* file name */
258 if (l <= bufflen) /* small enough? */
259 memcpy(out, source + 1, l * sizeof(char));
260 else { /* add '...' before rest of name */
261 addstr(out, RETS, LL(RETS));
262 bufflen -= LL(RETS);
263 memcpy(out, source + 1 + l - bufflen, bufflen * sizeof(char));
264 }
265 }
266 else { /* string; format as [string "source"] */
267 const char *nl = strchr(source, '\n'); /* find first new line (if any) */
268 addstr(out, PRE, LL(PRE)); /* add prefix */
269 bufflen -= LL(PRE RETS POS) + 1; /* save space for prefix+suffix+'\0' */
270 if (l < bufflen && nl == NULL) { /* small one-line source? */
271 addstr(out, source, l); /* keep it */
272 }
273 else {
274 if (nl != NULL) l = nl - source; /* stop at first newline */
275 if (l > bufflen) l = bufflen;
276 addstr(out, source, l);
277 addstr(out, RETS, LL(RETS));
278 }
279 memcpy(out, POS, (LL(POS) + 1) * sizeof(char));
280 }
281}
282/* END CSTYLED */

Callers 3

lexerrorFunction · 0.70
funcinfoFunction · 0.70
addinfoFunction · 0.70

Calls 2

strchrFunction · 0.85
memcpyFunction · 0.50

Tested by

no test coverage detected