| 1256 | } |
| 1257 | |
| 1258 | static JSValue js_std_open(JSContext *ctx, JSValueConst this_val, |
| 1259 | int argc, JSValueConst *argv) |
| 1260 | { |
| 1261 | const char *filename, *mode = NULL; |
| 1262 | FILE *f; |
| 1263 | int err; |
| 1264 | |
| 1265 | filename = JS_ToCString(ctx, argv[0]); |
| 1266 | if (!filename) |
| 1267 | goto fail; |
| 1268 | mode = JS_ToCString(ctx, argv[1]); |
| 1269 | if (!mode) |
| 1270 | goto fail; |
| 1271 | if (mode[strspn(mode, "rwa+bx")] != '\0') { |
| 1272 | JS_ThrowTypeError(ctx, "invalid file mode"); |
| 1273 | goto fail; |
| 1274 | } |
| 1275 | |
| 1276 | f = fopen(filename, mode); |
| 1277 | if (!f) |
| 1278 | err = errno; |
| 1279 | else |
| 1280 | err = 0; |
| 1281 | if (argc >= 3) |
| 1282 | js_set_error_object(ctx, argv[2], err); |
| 1283 | JS_FreeCString(ctx, filename); |
| 1284 | JS_FreeCString(ctx, mode); |
| 1285 | if (!f) |
| 1286 | return JS_NULL; |
| 1287 | return js_new_std_file(ctx, f, false); |
| 1288 | fail: |
| 1289 | JS_FreeCString(ctx, filename); |
| 1290 | JS_FreeCString(ctx, mode); |
| 1291 | return JS_EXCEPTION; |
| 1292 | } |
| 1293 | |
| 1294 | #if !defined(__wasi__) |
| 1295 | static JSValue js_std_popen(JSContext *ctx, JSValueConst this_val, |
nothing calls this directly
no test coverage detected