| 1330 | #endif // !defined(__wasi__) |
| 1331 | |
| 1332 | static 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__) |
| 1366 | static JSValue js_std_tmpfile(JSContext *ctx, JSValueConst this_val, |
nothing calls this directly
no test coverage detected