Function unlinkZ [src]

Same as unlink except the parameter is null terminated.

Prototype

pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void

Parameters

file_path: [*:0]const u8

Possible Errors

AccessDenied

In WASI, this error may occur when the file descriptor does not hold the required rights to unlink a resource by path relative to it.

BadPathName

On Windows, file paths cannot contain these characters: '/', '*', '?', '"', '<', '>', '|'

FileBusy
FileNotFound
FileSystem
InvalidUtf8

WASI-only; file paths must be valid UTF-8.

InvalidWtf8

Windows-only; file paths provided by the user must be valid WTF-8. https://simonsapin.github.io/wtf-8/

IsDir
NameTooLong
NetworkNotFound

On Windows, \\server or \\server\share was not found.

NotDir
PermissionDenied
ReadOnlyFileSystem
SymLinkLoop
SystemResources
Unexpected UnexpectedError

The Operating System returned an undocumented error code.

This error is in theory not possible, but it would be better to handle this error than to invoke undefined behavior.

When this error code is observed, it usually means the Zig Standard Library needs a small patch to add the error code to the error set for the respective function.

Source

pub fn unlinkZ(file_path: [*:0]const u8) UnlinkError!void { if (native_os == .windows) { const file_path_w = try windows.cStrToPrefixedFileW(null, file_path); return unlinkW(file_path_w.span()); } else if (native_os == .wasi and !builtin.link_libc) { return unlink(mem.sliceTo(file_path, 0)); } switch (errno(system.unlink(file_path))) { .SUCCESS => return, .ACCES => return error.AccessDenied, .PERM => return error.PermissionDenied, .BUSY => return error.FileBusy, .FAULT => unreachable, .INVAL => unreachable, .IO => return error.FileSystem, .ISDIR => return error.IsDir, .LOOP => return error.SymLinkLoop, .NAMETOOLONG => return error.NameTooLong, .NOENT => return error.FileNotFound, .NOTDIR => return error.NotDir, .NOMEM => return error.SystemResources, .ROFS => return error.ReadOnlyFileSystem, .ILSEQ => |err| if (native_os == .wasi) return error.InvalidUtf8 else return unexpectedErrno(err), else => |err| return unexpectedErrno(err), } }