Skip to content

windows: File.pwrite/pread alters the file pointer #12783

Open
@kubkon

Description

@kubkon

Zig Version

0.10.0-dev.3922+b98b3252b

Steps to Reproduce

On POSIX-based OS, this succeeds. On Windows, this fails.

const std = @import("std");
const assert = std.debug.assert;

pub fn main() !void {
    const file = try std.fs.cwd().createFile("dummy", .{});
    defer file.close();

    try file.seekBy(10);
    const curr_pos = try file.getPos();
    assert(curr_pos == 10);
    try file.pwriteAll("\xaa", 0);
    assert(curr_pos == try file.getPos());
}

Expected Behavior

My question is: should we strive for File.pwrite/pread (and related) to be platform-independent? My gut is telling me yes but I want to see what others think about this.

Actual Behavior

Currently, File.pwrite/pread (and related) are platform-dependent.

Activity

added
questionNo questions on the issue tracker, please.
standard libraryThis issue involves writing Zig code for the standard library.
on Sep 8, 2022
added this to the 0.11.0 milestone on Sep 8, 2022
modified the milestones: 0.11.0, 0.12.0 on Apr 9, 2023
gooncreeper

gooncreeper commented on Mar 3, 2025

@gooncreeper

I would think that a majority of use cases for pread and pwrite would not also mix in seek-based I/O, since it is essentially an optimization to avoid seeking in the first place, so it could be worth leaving the file position unspecified.

added a commit that references this issue on Mar 16, 2025
b2d5027
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    os-windowsquestionNo questions on the issue tracker, please.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

      Participants

      @andrewrk@kubkon@gooncreeper

      Issue actions

        windows: File.pwrite/pread alters the file pointer · Issue #12783 · ziglang/zig