FileIsOpen
Description
Check whether the file handle currently holds an open fd / HANDLE.
Success
Returns true when the handle is open.
Failure
Returns false otherwise (closed or never opened). Cannot fail.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
File.c:233:
}
bool FileIsOpen(const File *f) {
if (!f) {
return false;- In
File.c:249:
i64 file_read(File *f, void *buf, u64 n) {
if (!FileIsOpen(f) || !buf) {
return -1;
}- In
File.c:286:
i64 FileWrite(File *f, const void *buf, u64 n) {
if (!FileIsOpen(f) || !buf) {
return -1;
}- In
File.c:314:
i64 FileSeek(File *f, i64 offset, FileWhence whence) {
if (!FileIsOpen(f)) {
return -1;
}- In
File.c:347:
bool FileFlush(File *f) {
if (!FileIsOpen(f)) {
return false;
}- In
Dns.c:102:
static bool slurp_file(Zstr path, Str *out) {
File f = FileOpen(path, "rb");
if (!FileIsOpen(&f)) {
// Missing config file is fine -- resolver just won't know about it.
return true;- In
_Helpers.h:24:
static inline bool sys_path_exists(Zstr path) {
File f = FileOpen(path, "rb");
if (!FileIsOpen(&f)) {
return false;
}- In
ProcMaps.c:236:
// kernel on read, so we loop-read into a growing buffer ourselves.
File f = FileOpen("/proc/self/maps", "rb");
if (!FileIsOpen(&f)) {
LOG_ERROR("ProcMapsLoad: FileOpen(/proc/self/maps) failed");
ProcMapsDeinit(out);- In
ProcMaps.c:263:
out->raw = StrInit(alloc);
out->entries = VecInitT(out->entries, alloc);
if (!FileIsOpen(f)) {
LOG_ERROR("ProcMapsLoadFrom: file is not open");
ProcMapsDeinit(out);- In
File.c:16:
static bool write_test_file(Zstr text, Str *out_path, Allocator *alloc) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f)) {
return false;
}- In
File.c:43:
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);
StrDeinit(&path);- In
File.c:77:
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);
StrDeinit(&path);- In
File.c:116:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
FileClose(&f);- In
File.c:120:
// After close the handle must read as not-open.
ok = ok && !FileIsOpen(&f);
char scratch[8] = {0};- In
File.c:150:
// "q" is not a recognised mode.
File f = FileOpen(&path, "q");
ok = ok && !FileIsOpen(&f);
FileClose(&f);- In
File.c:155:
// An empty mode is also rejected.
File g = FileOpen(&path, "");
ok = ok && !FileIsOpen(&g);
FileClose(&g);- In
File.c:176:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:225:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
// A zero-byte request returns 0 and must NOT flag eof.
- In
File.c:260:
File w = FileOpen(&path, "w");
ok = ok && FileIsOpen(&w);
ok = ok && (FileWrite(&w, "new", 3) == 3);
FileClose(&w);- In
File.c:265:
File r = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&r);
Str body = StrInit(alloc_base);
i64 got = FileRead(&r, &body);- In
File.c:295:
File a = FileOpen(&path, "a");
ok = ok && FileIsOpen(&a);
ok = ok && (FileWrite(&a, "tail", 4) == 4);
FileClose(&a);- In
File.c:326:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:360:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:397:
File f = FileOpen(&path, "r");
ok = ok && FileIsOpen(&f);
// A read-only handle must reject writes.
ok = ok && (FileWrite(&f, "X", 1) == -1);- In
File.c:424:
File f = FileOpen(&path, "r+");
ok = ok && FileIsOpen(&f);
// "r+" must permit writes (does not truncate). Overwrite first 3 bytes.
ok = ok && (FileWrite(&f, "AAA", 3) == 3);- In
File.c:460:
File f = FileOpen(&path, "r");
ok = ok && FileIsOpen(&f);
char buf[8] = {0};
i64 got = FileRead(&f, buf, 7);- In
File.c:512:
Str path;
File owner = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&owner)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:554:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:561:
bool ok = (FileClose(&f) == true);
// And the handle is now not-open.
ok = ok && !FileIsOpen(&f);
FileRemove(&path);- In
File.c:580:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:588:
// and returns true without touching any fd.
ok = ok && (FileClose(&f) == true);
ok = ok && !FileIsOpen(&f);
FileRemove(&path);- In
File.c:610:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:645:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
char buf[4] = {0};
ok = ok && (FileRead(&f, buf, 2) == 2) && !FileIsEof(&f);- In
File.c:678:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
char buf[8] = {0};
// Drain to EOF to set at_eof.
- In
File.c:708:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:750:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
// Move the cursor to offset 10; remaining size must be 16 - 10 = 6.
ok = ok && (FileSeek(&f, 10, FILE_SEEK_SET) == 10);- In
File.c:784:
File f = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&f);
Str body = StrInit(alloc_base);
i64 got = FileRead(&f, &body);- In
File.c:815:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:831:
File r = FileOpen(&path, "rb");
ok = ok && FileIsOpen(&r);
Buf dst = BufInit(alloc_base);
i64 got = FileRead(&r, &dst);- In
File.c:861:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:924:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:959:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:997:
Str path;
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);
// The resolved path must be non-empty (16 hex chars).
ok = ok && (StrLen(&path) == 16);- In
File.c:1029:
File f2 = FileOpenTemp(&p2, alloc_base);
bool ok = FileIsOpen(&f1) && FileIsOpen(&f2);
ok = ok && (StrLen(&p1) == 16) && (StrLen(&p2) == 16);
// Distinct names (overwhelmingly likely; the loop draws fresh entropy).
- In
File.c:1070:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
File.c:1102:
Str path;
File seed = FileOpenTemp(&path, alloc_base);
if (FileIsOpen(&seed)) {
FileClose(&seed);
}- In
File.c:1122:
// FileIsOpen on fd 0, so the `>= 0` vs `> 0` boundary is unpinned there.
bool test_mut_240_isopen_fd_zero(void) {
WriteFmt("Testing FileIsOpen reports a borrowed fd 0 as open (>= 0 boundary)\n");
#if PLATFORM_WINDOWS- In
File.c:1133:
// a `> 0` mutant would wrongly report it not-open.
File f = FileFromFd(0);
bool ok = (FileIsOpen(&f) == true);
// Sanity: a genuinely-negative fd is not open under either form, so
// the discriminating case really is fd == 0.
- In
File.c:1137:
// the discriminating case really is fd == 0.
File g = FileFromFd(-1);
ok = ok && (FileIsOpen(&g) == false);
return ok;
#endif- In
File.c:1199:
Str pb;
File b = FileOpenTemp(&pb, alloc_base);
if (!FileIsOpen(&a) || !FileIsOpen(&b)) {
if (FileIsOpen(&a)) {
FileClose(&a);- In
File.c:1200:
File b = FileOpenTemp(&pb, alloc_base);
if (!FileIsOpen(&a) || !FileIsOpen(&b)) {
if (FileIsOpen(&a)) {
FileClose(&a);
FileRemove(&pa);- In
File.c:1205:
StrDeinit(&pa);
}
if (FileIsOpen(&b)) {
FileClose(&b);
FileRemove(&pb);- In
File.c:1225:
Str pc;
File c = FileOpenTemp(&pc, alloc_base);
ok = ok && FileIsOpen(&c);
i32 fd_c = FileFd(&c);
bool reuse = (fd_c == fd_a);- In
ArgParse.c:619:
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))
LOG_FATAL("capture_help: FileOpenTemp failed");- In
ArgParse.c:890:
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))
return false;- In
ArgParse.c:1777:
File tmp = FileOpenTemp(&tmp_path, p->alloc);
StrDeinit(&tmp_path);
if (!FileIsOpen(&tmp))
LOG_FATAL("capture_run: FileOpenTemp failed");- In
Write.c:973:
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))
return f;
FileWrite(&f, content, len);- In
Write.c:1012:
File f = FileOpen(path, "r");
bool ok = false;
if (FileIsOpen(&f)) {
Str back = StrInit(&alloc);
FileRead(&f, &back);- In
Write.c:3033:
Zstr path = "io_mutants28_str.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;
}- In
Write.c:3050:
Zstr path = "io_mutants28_int.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;
}- In
Write.c:3067:
Zstr path = "io_mutants28_ln.txt"; // CWD-relative: portable (no /tmp on Windows)
File f = FileOpen(path, "w");
if (!FileIsOpen(&f)) {
return false;
}- In
Write.c:4192:
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "42 zzzzzzz", 10);
bool ok = FileIsOpen(&f);
i32 v = 0;- In
Write.c:4217:
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "7", 1);
bool ok = FileIsOpen(&f);
i32 v = -1;- In
Write.c:4242:
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "53 and more text", 16);
bool ok = FileIsOpen(&f);
i32 v = 0;- In
Write.c:4992:
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {
ok = ok && FWriteFmtLn(&f, "n={}", LVAL((i32)42));- In
Write.c:4997:
FileClose(&f);
File r = FileOpen(StrBegin(&path), "r");
if (FileIsOpen(&r)) {
Str back = StrInit(&alloc);
FileRead(&r, &back);- In
Write.c:5021:
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {
// FWriteFmt (no newline) of empty string: nothing to write.
- In
Write.c:5028:
FileClose(&f);
File r = FileOpen(StrBegin(&path), "r");
if (FileIsOpen(&r)) {
Str back = StrInit(&alloc);
FileRead(&r, &back);- In
Read.c:41:
static File m4_make_temp(DefaultAllocator *alloc, Str *out_path, const char *content, u64 len) {
File f = FileOpenTemp(out_path, alloc);
if (!FileIsOpen(&f))
return f;
FileWrite(&f, content, len);- In
Read.c:1654:
File f = m4_make_temp(&alloc, &path, content, 52);
bool ok = FileIsOpen(&f);
i32 v = -1;- In
Read.c:1675:
Str path = StrInit(&alloc);
File f = m4_make_temp(&alloc, &path, "", 0);
bool ok = FileIsOpen(&f);
i32 v = 1234;- In
Read.c:2684:
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {
FileWrite(&f, "42", 2);- In
Read.c:2706:
Str path = StrInit(&alloc);
File f = FileOpenTemp(&path, &alloc);
bool ok = FileIsOpen(&f);
if (ok) {
FileWrite(&f, "xx", 2);- In
PdbCache.c:90:
// (no libc fopen/fwrite/fclose).
File f = FileOpen(path, "w");
if (!FileIsOpen(&f))
return false;
bool ok = (u64)FileWrite(&f, data, size) == size;- In
SysDns.c:101:
Str path = StrInit(a);
File f = file_open_temp(&path, a);
if (FileIsOpen(&f)) {
u64 n = ZstrLen(body);
if (n > 0) {- In
MachoCache.c:45:
static bool write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;
bool ok = FileWrite(&f, data, size) == (i64)size;- In
MachoCache.c:307:
static bool mc_write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;
bool ok = FileWrite(&f, data, size) == (i64)size;- In
MachoCache.c:924:
static bool bl_write_file(Zstr path, const u8 *data, u64 size) {
File f = FileOpen(path, "wb");
if (!FileIsOpen(&f))
return false;
bool ok = FileWrite(&f, data, size) == (i64)size;- In
Pe.c:1652:
Str path = StrInit(base);
File f = FileOpenTemp(&path, base);
if (!FileIsOpen(&f)) {
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
Pe.c:1694:
Str path = StrInit(base);
File f = FileOpenTemp(&path, base);
if (!FileIsOpen(&f)) {
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
ProcMaps.c:572:
Str path;
File f = FileOpenTemp(&path, alloc_base);
if (!FileIsOpen(&f)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
ProcMaps.c:599:
File rf = FileOpen(&path, "rb");
if (!FileIsOpen(&rf)) {
FileRemove(&path);
StrDeinit(&path);- In
ProcMaps.c:640:
// A directory: open(2) succeeds (FileIsOpen true) but read(2) returns -1.
File dir = FileOpen("/proc/self", "rb");
if (!FileIsOpen(&dir)) {
DebugAllocatorDeinit(&dbg);
return false;- In
Http.c:215:
Str path = StrInit(alloc_base);
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);
Zstr payload = "hello-body";- In
Http.c:245:
Str path = StrInit(alloc_base);
File f = FileOpenTemp(&path, alloc_base);
bool ok = FileIsOpen(&f);
FileClose(&f); // leave it empty
- In
Http.c:389:
Str path = StrInit(adbg);
File f = FileOpenTemp(&path, adbg);
bool ok = FileIsOpen(&f);
Zstr payload = "file-payload-long-enough-to-heap-allocate-body";
ok = ok && (FileWrite(&f, payload, ZstrLen(payload)) == (i64)ZstrLen(payload));- In
MachO.c:1408:
Str path;
File seed = FileOpenTemp(&path, base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;- In
MachO.c:1450:
Str path;
File seed = FileOpenTemp(&path, base);
if (!FileIsOpen(&seed)) {
DefaultAllocatorDeinit(&alloc);
return false;
Last updated on