bytecodealliance / bytecodealliance/wasmtime

posix_fallocate truncates file on macOS

Open
#2,973 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Rust
Stars
18.6k
Forks
1.8k
Avg merge
1d 18h
Merged PRs (30d)
126

Description

### Test Case
```
#include
#include
#include
#include
#include
#include

int main() {
int fd = open("non_empty_file.txt", O_RDWR);
struct stat fs;

printf("Before fallocate:\n");
fstat(fd, &fs);
printf("size is: %lld\n", (long long) fs.st_size);

int r = posix_fallocate(fd, 0, 0);
printf("posix_fallocate returns %d\n", r);
if(r != 0) {
printf("error is: %s\n", strerror(r));
}

printf("After fallocate:\n");
fstat(fd, &fs);
printf("size is: %lld\n", (long long) fs.st_size);
}
```

```
non_empty_file.txt
Hello, this is a file with some text in it.
```
### Steps to Reproduce

Compile the C program with the clang from wasi-sdk and run it with wasmtime on macOS.

### Expected Results

For posix_fallocate(int fd, off_t offset, off_t len), POSIX manual says "If the size of the file is less than offset+len, then the file is increased to this size; otherwise the file size is left unchanged."

### Actual Results

When offset+len < file size, wasmtime will keep the file size unchanged on Linux(Ubuntu), but will truncate the file on macOS(Mojave).

### Versions and Environment

Wasmtime version or commit: 0.26.0

Operating system: Mac OS X 10.14.6

Architecture: x86

CC: @deian

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.