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

Function js_std_file_getline

deps/quickjs/quickjs-libc.c:1593–1626  ·  view source on GitHub ↗

XXX: could use less memory and go faster */

Source from the content-addressed store, hash-verified

1591
1592/* XXX: could use less memory and go faster */
1593static JSValue js_std_file_getline(JSContext *ctx, JSValueConst this_val,
1594 int argc, JSValueConst *argv)
1595{
1596 FILE *f = js_std_file_get(ctx, this_val);
1597 int c;
1598 DynBuf dbuf;
1599 JSValue obj;
1600
1601 if (!f)
1602 return JS_EXCEPTION;
1603
1604 js_std_dbuf_init(ctx, &dbuf);
1605 for(;;) {
1606 c = fgetc(f);
1607 if (c == EOF) {
1608 if (dbuf.size == 0) {
1609 /* EOF */
1610 dbuf_free(&dbuf);
1611 return JS_NULL;
1612 } else {
1613 break;
1614 }
1615 }
1616 if (c == '\n')
1617 break;
1618 if (dbuf_putc(&dbuf, c)) {
1619 dbuf_free(&dbuf);
1620 return JS_ThrowOutOfMemory(ctx);
1621 }
1622 }
1623 obj = JS_NewStringLen(ctx, (const char *)dbuf.buf, dbuf.size);
1624 dbuf_free(&dbuf);
1625 return obj;
1626}
1627
1628/* XXX: could use less memory and go faster */
1629static JSValue js_std_file_readAs(JSContext *ctx, JSValueConst this_val,

Callers

nothing calls this directly

Calls 4

js_std_file_getFunction · 0.85
js_std_dbuf_initFunction · 0.85
dbuf_freeFunction · 0.85
dbuf_putcFunction · 0.85

Tested by

no test coverage detected