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

Function js_std_fdopen

deps/quickjs/quickjs-libc.c:1332–1363  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1330#endif // !defined(__wasi__)
1331
1332static JSValue js_std_fdopen(JSContext *ctx, JSValueConst this_val,
1333 int argc, JSValueConst *argv)
1334{
1335 const char *mode;
1336 FILE *f;
1337 int fd, err;
1338
1339 if (JS_ToInt32(ctx, &fd, argv[0]))
1340 return JS_EXCEPTION;
1341 mode = JS_ToCString(ctx, argv[1]);
1342 if (!mode)
1343 goto fail;
1344 if (mode[strspn(mode, "rwa+")] != '\0') {
1345 JS_ThrowTypeError(ctx, "invalid file mode");
1346 goto fail;
1347 }
1348
1349 f = fdopen(fd, mode);
1350 if (!f)
1351 err = errno;
1352 else
1353 err = 0;
1354 if (argc >= 3)
1355 js_set_error_object(ctx, argv[2], err);
1356 JS_FreeCString(ctx, mode);
1357 if (!f)
1358 return JS_NULL;
1359 return js_new_std_file(ctx, f, false);
1360 fail:
1361 JS_FreeCString(ctx, mode);
1362 return JS_EXCEPTION;
1363}
1364
1365#if !defined(__wasi__)
1366static JSValue js_std_tmpfile(JSContext *ctx, JSValueConst this_val,

Callers

nothing calls this directly

Calls 3

JS_ToCStringFunction · 0.85
js_set_error_objectFunction · 0.85
js_new_std_fileFunction · 0.85

Tested by

no test coverage detected