This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/dup2.c

22 lines
413 B
C
Raw Permalink Normal View History

#include <fcntl.h>
#include <io.h>
void main()
{
int handle, dup_handle;
handle = open( "file",
O_WRONLY | O_CREAT | O_TRUNC | O_TEXT,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP );
if( handle != -1 ) {
dup_handle = 4;
if( dup2( handle, dup_handle ) != -1 ) {
/* process file */
close( dup_handle );
}
close( handle );
}
}