Skip to content

Writing to a file open with read permissions panics instead of returning error #3880

@DanB91

Description

@DanB91

Hi,

Running macOS Catalina and zig 0.5.0+5874cb04b.

On macOS Catalina, When calling f.write() on a file opened with File.openRead(), zig panics on EBADF, which in has a comment saying "always a race condition" and does not return an error. This is a single-threaded program. EBADF seems to be the proper error for writing to a file open for reading and is not a race condition:

[EBADF] fildes is not a valid file descriptor open for writing.

This seems to be related to this bug but not 100% sure.
Here is the error trace:

reached unreachable code
lib/zig/std/os.zig:497:22: 0x105207854 in _std.os.write
            EBADF => unreachable, // Always a race condition.
                     ^
lib/zig/std/fs/file.zig:296:24: 0x105203992 in _std.fs.file.File.write
        return os.write(self.handle, bytes);
                       ^
prog.zig:48:16: 0x105210cc3 in _main.0 
        f.write(bytes[0..]) 
               ^

Please let me know if you need anything else from me

Metadata

Metadata

Assignees

No one assigned

    Labels

    breakingImplementing this issue could cause existing code to no longer compile or have different behavior.bugObserved behavior contradicts documented or intended behaviorcontributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.standard libraryThis issue involves writing Zig code for the standard library.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions