aboutsummaryrefslogtreecommitdiff
path: root/test/wasi/c/stat.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/wasi/c/stat.c')
-rw-r--r--test/wasi/c/stat.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/test/wasi/c/stat.c b/test/wasi/c/stat.c
new file mode 100644
index 0000000000..fd3854937b
--- /dev/null
+++ b/test/wasi/c/stat.c
@@ -0,0 +1,53 @@
+#include <sys/stat.h>
+
+#include <assert.h>
+#include <fcntl.h>
+#include <time.h>
+#include <unistd.h>
+
+#define BASE_DIR "/tmp"
+#define OUTPUT_DIR BASE_DIR "/testdir"
+#define PATH OUTPUT_DIR "/output.txt"
+#define SIZE 500
+
+int main(void) {
+ struct stat st;
+ int fd;
+ int ret;
+ off_t pos;
+
+ (void)st;
+ ret = mkdir(OUTPUT_DIR, 0755);
+ assert(ret == 0);
+
+ fd = open(PATH, O_CREAT | O_WRONLY, 0666);
+ assert(fd != -1);
+
+ pos = lseek(fd, SIZE - 1, SEEK_SET);
+ assert(pos == SIZE - 1);
+
+ ret = (int)write(fd, "", 1);
+ assert(ret == 1);
+
+ ret = fstat(fd, &st);
+ assert(ret == 0);
+ assert(st.st_size == SIZE);
+
+ ret = close(fd);
+ assert(ret == 0);
+
+ ret = access(PATH, R_OK);
+ assert(ret == 0);
+
+ ret = stat(PATH, &st);
+ assert(ret == 0);
+ assert(st.st_size == SIZE);
+
+ ret = unlink(PATH);
+ assert(ret == 0);
+
+ ret = stat(PATH, &st);
+ assert(ret == -1);
+
+ return 0;
+}