NAME
fd_copy, fd_copy2, fd_move, fd_move2 - copy/move file descriptors
SYNOPSIS
#include <limb/djbunix.h>
int fd_copy(int to, int from) int fd_copy2(int to1, int from1, int to2, int from2) int fd_move(int to, int from) int fd_move2(int to1, int from1, int to2, int from2)
DESCRIPTION
The fd_copy() function duplicates the file descriptor from into file
descriptor to, so that both refer to the same open file, that cannot be
interrupted by signals.
The fd_copy2() function is similar to fd_copy() but duplicating file
descriptor from1 to file descriptor to1 and file descriptor from2 to file
descriptor to2.
Either both file descriptors will be copied, or none will have been.
The fd_move() function is similar to fd_copy(3) but closing from
afterwards.
The fd_move2() function is similar to fd_move() but moving file descriptor
from1 to file descriptor to1 and file descriptor from2 to file
descriptor to2.
Either both file descriptors will be moved, or none will have been.
It is supported to "re-use" file descriptors, e.g. to2 can be from1 and/or
from2 can be to1, as long as it makes sense.
RETURN VALUE
These functions return 0 on success. Otherwise they return -1 and set errno to
indicate the error.
ERRORS
The fd_copy(), fd_copy2() and fd_move2() functions may fail if :
EINVAL
File descriptors are invalid, e.g. from and to are the same for
fd_copy(); to1 and from2 are the same for fd_copy2(), from1 and
from2 are the same and to1 and to2 are the same for fd_move2()...
These functions may also fail and set errno for any of the errors specified
for dup2(3), except for EINTR.