Skip to content

Always cast pread, lseek etc. offsets to off_t. #1442

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

Merged
merged 2 commits into from
Apr 12, 2025

Conversation

sunfishcode
Copy link
Member

When calling libc functions that take off_t arguments, always cast to off_t. On platforms where this cast is a no-op, these casts should be optimized away. This eliminates the need for explicit cfgs for platforms which need the casts.

Fixes #1432.

When calling libc functions that take `off_t` arguments, always cast to
`off_t`. On platforms where this cast is a no-op, these casts should be
optimized away. This eliminates the need for explicit `cfg`s for
platforms which need the casts.

Fixes #1432.
let offset = offset as i64;
let len = len as i64;

// ESP-IDF and Vita don't support 64-bit offsets, for example.
let offset = offset.try_into().map_err(|_| io::Errno::OVERFLOW)?;

This comment was marked as resolved.

This comment was marked as resolved.

@kulp
Copy link

kulp commented Apr 9, 2025

Due to unrelated changes between v0.38.44 and v1.0.5, I cannot right now directly test the branch in the current MR, but I did successfully compile my project after cherry-picking 5dbcf91 plus an extra cast for len in fallocate. That is good enough for me personally.

Thanks!

@sunfishcode sunfishcode merged commit 4fbc05c into main Apr 12, 2025
51 checks passed
@sunfishcode sunfishcode deleted the sunfishcode/libc-offsets branch April 12, 2025 12:20
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.

Suggesting additional use of c::off_t inside seek/fallocate/pread/pwrite
2 participants