dup
Returns a file handle that refers to the same open file as handle (supported only for NetWare 4.x and above)
#include <unistd.h>
int dup (
int handle);
When an error occurs, a value of -1 is returned. Otherwise, the return value is a nonnegative integer that is the file handle.
If an error occurs, errno can be set to:
The dup function duplicates a file handle by returning a file handle that refers to the same open file as handle. Since both handles reference the same file, either handle can be used for operations on the file.
NOTE:For an example of how to reverse the effect of redirecting stdin, see the example for fdopen.