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
2 changes: 1 addition & 1 deletion system/lib/libc/musl/src/stdio/__stdio_close.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ weak_alias(dummy, __aio_close);
int __stdio_close(FILE *f)
{
#ifdef __EMSCRIPTEN__
return __wasi_fd_close(__aio_close(f->fd));
return __wasi_syscall_ret(__wasi_fd_close(__aio_close(f->fd)));
#else
return syscall(SYS_close, __aio_close(f->fd));
#endif
Expand Down
14 changes: 14 additions & 0 deletions test/test_files.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,26 @@
// found in the LICENSE file.

#include <assert.h>
#include <errno.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>

void test_fclose() {
FILE* f = fopen("temp.txt", "w");
int fd = fileno(f);
// Close the underlying FD, which should then cause fclose to
// fail.
int ret = close(fd);
assert(ret == 0);
ret = fclose(f);
printf("fclose error: %s\n", strerror(errno));
assert(ret == EOF);
}

// Reading
void test_reading() {
FILE *file = fopen("somefile.binary", "rb");
Expand Down Expand Up @@ -161,6 +174,7 @@ void test_tempfiles() {
}

int main() {
test_fclose();
test_reading();
test_stdstreams();
test_writing();
Expand Down