Skip to content

DirRemove

Description

Remove an empty directory. Direct syscall (rmdir on Linux x86_64 / Darwin, unlinkat(... AT_REMOVEDIR) on Linux aarch64, RemoveDirectoryA on Windows). The directory must be empty; populated directories require recursive removal via DirRemoveAll.

Parameters

Name Direction Description
path in Path of the directory. Prefer Str *; Zstr accepted.

Success

Returns 1; the directory is gone.

Failure

Returns 0; logs the failing syscall.

Usage example (Cross-references)

Usage examples (Cross-references)
    i8 dir_remove(Zstr path) {
        if (!path) {
            LOG_FATAL("DirRemove: NULL path");
        }
    #if PLATFORM_WINDOWS
    #if PLATFORM_WINDOWS
        if (!RemoveDirectoryA(path)) {
            LOG_ERROR("DirRemove(\"{}\"): RemoveDirectoryA failed (GetLastError={})", path, (i32)GetLastError());
            return 0;
        }
    #    endif
        if (ret < 0) {
            LOG_SYS_ERROR(ErrnoOf(ret), "DirRemove(\"{}\")", path);
            return 0;
        }
    #else
    #    error                                                                                                             \
            "DirRemove: no direct-syscall path. Add MISRA_SYS_rmdir / MISRA_SYS_unlinkat numbers in _Syscall.h for this arch."
    #endif
    }
            return 0;
        }
        return DirRemove(path);
    }
Last updated on