FileRemove
Description
Remove a regular file. Direct syscall (unlink on Linux x86_64 / Darwin, unlinkat on Linux aarch64, DeleteFileA on Windows). Symlinks are removed, not followed.
Return type is i8 (0/1) rather than bool to dodge the bool-typedef redefinition trap Misra’s Types.h documents: system headers transitively #define bool _Bool and the SAME identifier ends up meaning different types across TUs. Callers can still use the result as a boolean (if (FileRemove(p)) ...).
Parameters
| Name | Direction | Description |
|---|---|---|
path |
in | Path of the file to remove. Prefer Str *; Zstr accepted for literals / borrowed buffers. |
Success
Returns 1; the directory entry is gone.
Failure
Returns 0; logs the failing syscall.
Usage example (Cross-references)
Usage examples (Cross-references)
- In
Dir.c:342:
i8 file_remove(Zstr path) {
if (!path) {
LOG_FATAL("FileRemove: NULL path");
}
#if PLATFORM_WINDOWS- In
Dir.c:346:
#if PLATFORM_WINDOWS
if (!DeleteFileA(path)) {
LOG_ERROR("FileRemove(\"{}\"): DeleteFileA failed (GetLastError={})", path, (i32)GetLastError());
return 0;
}- In
Dir.c:360:
# endif
if (ret < 0) {
LOG_SYS_ERROR(ErrnoOf(ret), "FileRemove(\"{}\")", path);
return 0;
}- In
Dir.c:365:
return 1;
#else
# error "FileRemove: no direct-syscall path. Add the right MISRA_SYS_unlink* number in _Syscall.h for this arch."
#endif
}- In
Dir.c:562:
inner_ok = DirRemoveAll(&child);
} else {
inner_ok = FileRemove(&child);
}
}- In
File.c:24:
FileClose(&f);
if (!ok) {
FileRemove(out_path);
StrDeinit(out_path);
}- In
File.c:44:
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:58:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:78:
File f = FileOpen(&path, "rb");
if (!FileIsOpen(&f)) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:93:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:128:
ok = ok && (FileTell(&f) == -1);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:158:
FileClose(&g);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:203:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:238:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:273:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:307:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:343:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:365:
}
FileClose(&seed);
FileRemove(&path);
Str body = StrInit(alloc_base);- In
File.c:402:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:437:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:470:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:533:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:563:
ok = ok && !FileIsOpen(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:590:
ok = ok && !FileIsOpen(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:624:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:652:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:692:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:722:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:761:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:793:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:840:
BufDeinit(&src);
BufDeinit(&dst);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:878:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:908:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:943:
StrDeinit(&body);
BufDeinit(&in);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:977:
StrDeinit(&body);
StrDeinit(&in);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:1008:
FileClose(&f);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:1047:
StrDeinit(&b1);
StrDeinit(&b2);
FileRemove(&p1);
FileRemove(&p2);
StrDeinit(&p1);- In
File.c:1048:
StrDeinit(&b2);
FileRemove(&p1);
FileRemove(&p2);
StrDeinit(&p1);
StrDeinit(&p2);- In
File.c:1080:
ok = ok && (FileFlush(&f) == false);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:1110:
// Unreachable on real code.
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:1173:
StrDeinit(&body);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
File.c:1202:
if (FileIsOpen(&a)) {
FileClose(&a);
FileRemove(&pa);
StrDeinit(&pa);
}- In
File.c:1207:
if (FileIsOpen(&b)) {
FileClose(&b);
FileRemove(&pb);
StrDeinit(&pb);
}- In
File.c:1231:
FileClose(&b);
FileClose(&c);
FileRemove(&pa);
FileRemove(&pb);
FileRemove(&pc);- In
File.c:1232:
FileClose(&c);
FileRemove(&pa);
FileRemove(&pb);
FileRemove(&pc);
StrDeinit(&pa);- In
File.c:1233:
FileRemove(&pa);
FileRemove(&pb);
FileRemove(&pc);
StrDeinit(&pa);
StrDeinit(&pb);- In
Write.c:982:
static void m4_cleanup(File *f, Str *path) {
FileClose(f);
FileRemove(path);
StrDeinit(path);
}- In
Write.c:5006:
ok = false;
}
FileRemove(&path);
}
StrDeinit(&path);- In
Write.c:5037:
ok = false;
}
FileRemove(&path);
}
StrDeinit(&path);- In
Read.c:50:
static void m4_cleanup(File *f, Str *path) {
FileClose(f);
FileRemove(path);
StrDeinit(path);
}- In
Read.c:2692:
ok = (v == 42);
FileClose(&f);
FileRemove(&path);
}
StrDeinit(&path);- In
Read.c:2717:
ok = (v == 123) && (got == 1) && (c == 'x');
FileClose(&f);
FileRemove(&path);
}
StrDeinit(&path);- In
PdbCache.c:334:
DefaultAllocatorDeinit(&alloc);
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
return ok;- In
PdbCache.c:335:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
return ok;
}- In
PdbCache.c:385:
}
FileRemove(pe_name);
FileRemove(pdb_name);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:386:
FileRemove(pe_name);
FileRemove(pdb_name);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:420:
}
FileRemove((Zstr)pe_path);
DebugAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:458:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);- In
PdbCache.c:459:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:507:
}
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);- In
PdbCache.c:508:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);- In
PdbCache.c:509:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DebugAllocatorDeinit(&alloc);- In
PdbCache.c:510:
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DebugAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:549:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);- In
PdbCache.c:550:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:591:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:592:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:624:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:625:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:660:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:661:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:696:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:697:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:732:
}
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);- In
PdbCache.c:733:
FileRemove((Zstr)pe_path);
FileRemove((Zstr)pdb_path);
DebugAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:772:
}
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);- In
PdbCache.c:773:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);- In
PdbCache.c:774:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DefaultAllocatorDeinit(&alloc);- In
PdbCache.c:775:
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DefaultAllocatorDeinit(&alloc);
return ok;- In
PdbCache.c:820:
}
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);- In
PdbCache.c:821:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);- In
PdbCache.c:822:
FileRemove((Zstr)a_pe);
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DebugAllocatorDeinit(&alloc);- In
PdbCache.c:823:
FileRemove((Zstr)a_pdb);
FileRemove((Zstr)b_pe);
FileRemove((Zstr)b_pdb);
DebugAllocatorDeinit(&alloc);
return ok;- In
SysDns.c:112:
static void drop_temp(Str *path) {
FileRemove(path);
StrDeinit(path);
}- In
SysDns.c:1352:
host_v4_is(find_host(&r.hosts, "beta"), 2, 2, 2, 2);
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {- In
SysDns.c:1353:
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {
StrDeinit(p);- In
SysDns.c:1383:
ns_fmt_is(&r, 1, a, "10.0.0.2:53");
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {- In
SysDns.c:1384:
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {
StrDeinit(p);- In
SysDns.c:1414:
VecLen(&r.nameservers) == 1 && ns_fmt_is(&r, 0, a, "9.9.9.9:53");
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {- In
SysDns.c:1415:
FileRemove(&p0);
FileRemove(&p1);
VecForeachPtr(&paths, p) {
StrDeinit(p);- In
MachoCache.c:202:
MachoCacheDeinit(&cache);
DefaultAllocatorDeinit(&alloc);
FileRemove(bin_path);
return ok;
}- In
MachoCache.c:241:
// Cleanup
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_macho_stripped.dSYM");- In
MachoCache.c:242:
// Cleanup
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_macho_stripped.dSYM");
return ok;- In
MachoCache.c:274:
DefaultAllocatorDeinit(&alloc);
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_macho_uuidmiss.dSYM");- In
MachoCache.c:275:
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_macho_uuidmiss.dSYM");
return ok;- In
MachoCache.c:635:
ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_path);
DebugAllocatorDeinit(&dbg);
return ok;- In
MachoCache.c:691:
ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_a);
FileRemove(bin_b);
DebugAllocatorDeinit(&dbg);- In
MachoCache.c:692:
FileRemove(bin_a);
FileRemove(bin_b);
DebugAllocatorDeinit(&dbg);
return ok;- In
MachoCache.c:727:
ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_dsym.dSYM");- In
MachoCache.c:728:
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_dsym.dSYM");
DebugAllocatorDeinit(&dbg);- In
MachoCache.c:766:
ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_uuidmiss.dSYM");- In
MachoCache.c:767:
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_uuidmiss.dSYM");
DebugAllocatorDeinit(&dbg);- In
MachoCache.c:811:
ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_dwarf.dSYM");- In
MachoCache.c:812:
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_mc_dwarf.dSYM");
DebugAllocatorDeinit(&dbg);- In
MachoCache.c:849:
MachoCacheDeinit(&cache);
FileRemove(bin_path);
DefaultAllocatorDeinit(&alloc);
return ok;- In
MachoCache.c:885:
StrDeinit(&mod);
MachoCacheDeinit(&cache);
FileRemove(bin_path);
DefaultAllocatorDeinit(&alloc);
return ok;
MachoCacheDeinit(&cache);
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf.dSYM"); MachoCacheDeinit(&cache);
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf.dSYM");
DefaultAllocatorDeinit(&alloc);
MachoCacheDeinit(&cache);
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf2.dSYM"); MachoCacheDeinit(&cache);
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf2.dSYM");
DefaultAllocatorDeinit(&alloc); ok = ok && DebugAllocatorLiveCount(&dbg) == baseline;
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf3.dSYM");
FileRemove(bin_path);
FileRemove(dsym_path);
DirRemoveAll("/tmp/misra_bl_dwarf3.dSYM");
DebugAllocatorDeinit(&dbg);- In
Pe.c:1659:
FileClose(&f);
if (FileWriteAndClose((Zstr)StrBegin(&path), blob, sizeof(blob)) < 0) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
Pe.c:1673:
}
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
Pe.c:1701:
FileClose(&f);
if (FileWriteAndClose((Zstr)StrBegin(&path), junk, sizeof(junk)) < 0) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
Pe.c:1712:
PeDeinit(&pe);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
ProcMaps.c:592:
FileClose(&f);
if (!wrote_ok) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
ProcMaps.c:600:
File rf = FileOpen(&path, "rb");
if (!FileIsOpen(&rf)) {
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
ProcMaps.c:620:
}
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
Http.c:229:
(ZstrCompare(StrBegin(&response.body), payload) == 0);
FileRemove(StrBegin(&path));
StrDeinit(&path);
HttpResponseDeinit(&response);- In
Http.c:254:
ok = ok && (res != NULL) && (response.status_code == HTTP_RESPONSE_CODE_OK) && (StrLen(&response.body) == 0);
FileRemove(StrBegin(&path));
StrDeinit(&path);
HttpResponseDeinit(&response);- In
Http.c:399:
ok = ok && (res != NULL);
FileRemove(StrBegin(&path));
StrDeinit(&path);
HttpResponseDeinit(&response);- In
MachO.c:1433:
MachoDeinit(&m);
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);- In
MachO.c:1470:
ok = ok && !opened; // garbage must be rejected
FileRemove(&path);
StrDeinit(&path);
DefaultAllocatorDeinit(&alloc);
Last updated on