Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/std/posix: test ftruncate via std.fs.File.setEndPos() #23260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rootbeer
Copy link
Contributor

@rootbeer rootbeer commented Mar 15, 2025

Add a test for std.fs.File's setEndPos (which is a simple wrapper around std.posix.ftruncate) to exercise some success and failure paths.

Explicitly check that the ftruncate length isn't negative when interpreted as a signed value. This avoids having to decode overloaded EINVAL errors.

Add errno handling to Windows path to map INVALID_PARAMETER to FileTooBig.

Fixes #22960

@squeek502
Copy link
Collaborator

Not super important, but might be nice to use testWithAllSupportedPathTypes

@rootbeer
Copy link
Contributor Author

Not super important, but might be nice to use testWithAllSupportedPathTypes

I thought about that, but I think its not necessary because the path of the file isn't relevant. setEndPos is implemented on ftruncate which just uses the open file descriptor, the path won't get parsed. It would be interesting to vary the file system that the tmpDir is put on, but I don't think we have much visibility or control over that...

@rootbeer
Copy link
Contributor Author

Oops, on MacOS it looks like you're allowed to create a 1PB file. Neat! I guess I'll make the test agnostic to this passing or failing ...

error: 'fs.test.test.setEndPos' failed: expected error.FileTooBig, found void
/Users/ci/zach2/_work/zig/zig/lib/std/testing.zig:50:9: 0x10320998f in expectError__anon_752262 (test)
        return error.TestExpectedError;
        ^
/Users/ci/zach2/_work/zig/zig/lib/std/fs/test.zig:1[438](https://github.com/ziglang/zig/actions/runs/13876305970/job/38829056211?pr=23260#step:3:439):5: 0x10320a9e7 in test.setEndPos (test)
    try testing.expectError(error.FileTooBig, f.setEndPos(0x4_0000_0000_0000));
    ^

@squeek502
Copy link
Collaborator

the path of the file isn't relevant.

Ah, true, it'd only be exercising Dir.openFile, nevermind then

@rootbeer rootbeer force-pushed the 22960-ftruncate-einval branch from 1d16c86 to 402b359 Compare March 15, 2025 23:18
Add a test for std.fs.File's `setEndPos` (which is a simple wrapper around
`std.posix.ftruncate`) to exercise some success and failure paths.

Explicitly check that the `ftruncate` length isn't negative when
interpreted as a signed value.  This avoids having to decode overloaded
`EINVAL` errors.

Add errno handling to Windows path to map INVALID_PARAMETER to FileTooBig.

Fixes ziglang#22960
@rootbeer rootbeer force-pushed the 22960-ftruncate-einval branch from 402b359 to 63fe688 Compare March 16, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ftruncate has unreachable error values that can be reached
2 participants