// Fs.exists — distinguish an absent path from metadata failures. #include #include Term exists_run(Env e, Term* f, IoWork* w) { uint64_t n = 0; char* path = io_cstr(e, f[0], &n); struct stat st; int rc = stat(path, &st); int err = errno; free(path); (void)w; if (rc == 0) { return io_done(e, term_pak(CID(True), 0)); } if (err == ENOENT) { return io_done(e, term_pak(CID(False), 0)); } return io_fail(e, err, NULL); } static void __attribute__((constructor)) exists_use(void) { io_eff(CID(exists), exists_run, 0); }