MCPcopy Create free account
hub / github.com/buke/quickjs-go / js_load_file

Function js_load_file

deps/quickjs/quickjs-libc.c:454–489  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

452#endif // __GNUC__ || __clang__
453
454uint8_t *js_load_file(JSContext *ctx, size_t *pbuf_len, const char *filename)
455{
456 FILE *f;
457 size_t n, len;
458 uint8_t *p, *buf, tmp[8192];
459
460 f = fopen(filename, "rb");
461 if (!f)
462 return NULL;
463 buf = NULL;
464 len = 0;
465 do {
466 n = fread(tmp, 1, sizeof(tmp), f);
467 if (ctx) {
468 p = js_realloc(ctx, buf, len + n + 1);
469 } else {
470 p = realloc(buf, len + n + 1);
471 }
472 if (!p) {
473 if (ctx) {
474 js_free(ctx, buf);
475 } else {
476 free(buf);
477 }
478 fclose(f);
479 return NULL;
480 }
481 memcpy(&p[len], tmp, n);
482 buf = p;
483 len += n;
484 buf[len] = '\0';
485 } while (n == sizeof(tmp));
486 fclose(f);
487 *pbuf_len = len;
488 return buf;
489}
490
491/* load and evaluate a file */
492static JSValue js_loadScript(JSContext *ctx, JSValueConst this_val,

Callers 6

js_loadScriptFunction · 0.85
js_std_loadFileFunction · 0.85
jsc_module_loaderFunction · 0.85
compile_fileFunction · 0.85
load_fileFunction · 0.85
eval_fileFunction · 0.85

Calls

no outgoing calls

Tested by 1

load_fileFunction · 0.68