f2 = fopen(filename, mode); if (!f2) goto fail; if (f2->fd == f->fd) f2->fd = -1; /* avoid closing in fclose */ #ifdef __wasilibc_unmodified_upstream // WASI has no dup else if (__dup3(f2->fd, f->fd, fl&O_CLOEXEC)<0) goto fail2; #else // WASI doesn't have dup3, but does have a way to renumber // an existing file descriptor. else { if (__wasilibc_fd_renumber(f2->fd, f->fd)<0) goto fail2; f2->fd = -1; /* avoid closing in fclose */ } #endif