mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-28 00:02:28 +00:00
Implement __zipos_dup (#972)
* Implement __zipos_dup Makes ZiposHandle reference-counted by an `rc` field in a union with its freelist `next` pointer. The functions `__zipos_free` and `__zipos_keep` function as incref/decref for it. Adds `__zipos_postdup` to fix metadata on file descriptors after dup-like operations, and adds zipos support to `sys_dup_nt` + `sys_close_nt`. * Remove noop __zipos_postdup rc is never a zipos file because it is always a previously unused file descriptor. fd is never a zipos file because that case has been handled above by __zipos_fcntl.
This commit is contained in:
parent
6556dd2673
commit
d1a745c17c
11 changed files with 138 additions and 39 deletions
|
@ -70,14 +70,17 @@ int dup3(int oldfd, int newfd, int flags) {
|
|||
rc = einval(); // NetBSD doesn't do this
|
||||
} else if (oldfd < 0 || newfd < 0) {
|
||||
rc = ebadf();
|
||||
} else if (__isfdkind(oldfd, kFdZip)) {
|
||||
rc = enotsup();
|
||||
} else if (!IsWindows()) {
|
||||
rc = sys_dup3(oldfd, newfd, flags);
|
||||
if (rc != -1 && __isfdkind(newfd, kFdZip) && !__vforked) {
|
||||
_weaken(__zipos_free)(
|
||||
(struct ZiposHandle *)(intptr_t)g_fds.p[newfd].handle);
|
||||
bzero(g_fds.p + newfd, sizeof(*g_fds.p));
|
||||
if (__isfdkind(oldfd, kFdZip) || __isfdkind(newfd, kFdZip)) {
|
||||
if (__vforked) {
|
||||
return enotsup();
|
||||
}
|
||||
rc = sys_dup3(oldfd, newfd, flags);
|
||||
if (rc != -1) {
|
||||
_weaken(__zipos_postdup)(oldfd, newfd);
|
||||
}
|
||||
} else {
|
||||
rc = sys_dup3(oldfd, newfd, flags);
|
||||
}
|
||||
} else {
|
||||
rc = sys_dup_nt(oldfd, newfd, flags, -1);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue