[<<Previous Entry]
[^^Up^^]
[Next Entry>>]
[Menu]
[About The Guide]
dup2() Reassign a File Handle
#include <io.h> Required for declarations only
int dup2(handle1, handle2);
int handle1; Handle referring to open file
int handle2; Any handle value
dup2() causes 'handle2' to refer to the same file as 'handle1', which
is an already open file. Either file handle can be used to carry out
operations on the file, since all handles associated with a given file
use the same file pointer.
Returns: Zero if successful getting a new file handle, or -1 if
there is an error. On error, ERRNO is set to:
EBADF Invalid file handle
EMFILE Too many files open
Notes: In the example below, if file handle 3 is already open, it
will be closed first.
-------------------------------- Example ---------------------------------
These statements make file handle 3 refer to the same file as file
handle 1.
#include <io.h>
#include <stdlib.h>
int fh;
main()
{
fh = dup2(1,3);
if (fh == -1)
perror("error setting duplicate file handles");
}
See Also:
close()
creat()
open()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility.
Written by Dave Pearson