FileRemove
Description
Remove a regular file. Equivalent of POSIX unlink(2) / Win32 DeleteFileA. 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. |
Success
Returns 1; the directory entry is gone.
Failure
Returns 0; logs the failing syscall. Common causes: file doesn’t exist, no write permission on the parent directory, path is a directory (use DirRemove).
Usage example (Cross-references)
Usage examples (Cross-references)
- In
PdbCache.c:314:
DefaultAllocatorDeinit(&alloc);
FileRemove(pe_path);
FileRemove(pdb_path);
return ok;- In
PdbCache.c:315:
FileRemove(pe_path);
FileRemove(pdb_path);
return ok;
}- In
Dir.c:414:
// ---------------------------------------------------------------------------
i8 FileRemove(const char *path) {
if (!path) {
LOG_ERROR("FileRemove: NULL path");- In
Dir.c:416:
i8 FileRemove(const char *path) {
if (!path) {
LOG_ERROR("FileRemove: NULL path");
return 0;
}- In
Dir.c:421:
#if defined(_WIN32)
if (!DeleteFileA(path)) {
LOG_ERROR("FileRemove(\"{}\"): DeleteFileA failed (GetLastError={})", path, (i32)GetLastError());
return 0;
}- In
Dir.c:435:
# endif
if (ret < 0) {
LOG_SYS_ERROR(SYS_ERRNO(ret), "FileRemove(\"{}\")", path);
return 0;
}- In
Dir.c:444:
extern int unlink(const char *);
if (unlink(path) != 0) {
LOG_SYS_ERROR(SYS_ERRNO(-1), "FileRemove(\"{}\")", path);
return 0;
}
Last updated on