Skip to content

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)
        DefaultAllocatorDeinit(&alloc);
    
        FileRemove(pe_path);
        FileRemove(pdb_path);
        return ok;
    
        FileRemove(pe_path);
        FileRemove(pdb_path);
        return ok;
    }
    // ---------------------------------------------------------------------------
    
    i8 FileRemove(const char *path) {
        if (!path) {
            LOG_ERROR("FileRemove: NULL path");
    i8 FileRemove(const char *path) {
        if (!path) {
            LOG_ERROR("FileRemove: NULL path");
            return 0;
        }
    #if defined(_WIN32)
        if (!DeleteFileA(path)) {
            LOG_ERROR("FileRemove(\"{}\"): DeleteFileA failed (GetLastError={})", path, (i32)GetLastError());
            return 0;
        }
    #    endif
        if (ret < 0) {
            LOG_SYS_ERROR(SYS_ERRNO(ret), "FileRemove(\"{}\")", path);
            return 0;
        }
        extern int unlink(const char *);
        if (unlink(path) != 0) {
            LOG_SYS_ERROR(SYS_ERRNO(-1), "FileRemove(\"{}\")", path);
            return 0;
        }
Last updated on