3 ms·
Maybe this can still be worked around by copying the target fd first so it can be closed after fdup()ing the source fd, e.g. // Assume x and y are open fds and
by finnw 15y ago
Maybe this can still be worked around by copying the target fd first so it can be closed after fdup()ing the source fd, e.g.
// Assume x and y are open fds and we want to replace y with a copy of x
z = open("/dev/null", O_RDONLY); // Guarantees no other thread is using z
dup2(y, z);
dup2(x, y);
close(z);
- saurik 15y agoHah! (You don't actually need that open("/dev/null") trick, though: you can just use dup(). ;P)