Function WriteFile [src]

Prototype

pub fn WriteFile( handle: HANDLE, bytes: []const u8, offset: ?u64, ) WriteFileError!usize

Parameters

handle: HANDLEbytes: []const u8offset: ?u64

Possible Errors

BrokenPipe
ConnectionResetByPeer

The specified network name is no longer available.

LockViolation

The process cannot access the file because another process has locked a portion of the file.

NotOpenForWriting
OperationAborted
SystemResources
Unexpected

Source

pub fn WriteFile( handle: HANDLE, bytes: []const u8, offset: ?u64, ) WriteFileError!usize { var bytes_written: DWORD = undefined; var overlapped_data: OVERLAPPED = undefined; const overlapped: ?*OVERLAPPED = if (offset) |off| blk: { overlapped_data = .{ .Internal = 0, .InternalHigh = 0, .DUMMYUNIONNAME = .{ .DUMMYSTRUCTNAME = .{ .Offset = @truncate(off), .OffsetHigh = @truncate(off >> 32), }, }, .hEvent = null, }; break :blk &overlapped_data; } else null; const adjusted_len = math.cast(u32, bytes.len) orelse maxInt(u32); if (kernel32.WriteFile(handle, bytes.ptr, adjusted_len, &bytes_written, overlapped) == 0) { switch (GetLastError()) { .INVALID_USER_BUFFER => return error.SystemResources, .NOT_ENOUGH_MEMORY => return error.SystemResources, .OPERATION_ABORTED => return error.OperationAborted, .NOT_ENOUGH_QUOTA => return error.SystemResources, .IO_PENDING => unreachable, .NO_DATA => return error.BrokenPipe, .INVALID_HANDLE => return error.NotOpenForWriting, .LOCK_VIOLATION => return error.LockViolation, .NETNAME_DELETED => return error.ConnectionResetByPeer, else => |err| return unexpectedError(err), } } return bytes_written; }