Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions test/wasi/c/ftruncate.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include <sys/stat.h>
#include <assert.h>
#include <fcntl.h>
#include <unistd.h>

#define BASE_DIR "/tmp"
#define OUTPUT_DIR BASE_DIR "/testdir"
#define PATH OUTPUT_DIR "/output.txt"

int main(void) {
struct stat st;
int fd;

(void)st;
assert(0 == mkdir(OUTPUT_DIR, 0755));

fd = open(PATH, O_CREAT | O_WRONLY, 0666);
assert(fd != -1);

/* Verify that the file is initially empty. */
assert(0 == fstat(fd, &st));
assert(st.st_size == 0);
assert(0 == lseek(fd, 0, SEEK_CUR));

/* Increase the file size using ftruncate(). */
assert(0 == ftruncate(fd, 500));
assert(0 == fstat(fd, &st));
assert(st.st_size == 500);
assert(0 == lseek(fd, 0, SEEK_CUR));

/* Truncate the file using ftruncate(). */
assert(0 == ftruncate(fd, 300));
assert(0 == fstat(fd, &st));
assert(st.st_size == 300);
assert(0 == lseek(fd, 0, SEEK_CUR));

assert(0 == close(fd));
return 0;
}
1 change: 1 addition & 0 deletions test/wasi/test-wasi.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ if (process.argv[2] === 'wasi-child') {
runWASI({ test: 'exitcode', exitCode: 120 });
runWASI({ test: 'fd_prestat_get_refresh' });
runWASI({ test: 'freopen', stdout: `hello from input2.txt${EOL}` });
runWASI({ test: 'ftruncate' });
runWASI({ test: 'getentropy' });

// Tests that are currently unsupported on IBM i PASE.
Expand Down
Binary file added test/wasi/wasm/ftruncate.wasm
Binary file not shown.