/* Copyright (c) 2001-2004 by SoftIntegration, Inc. All Rights Reserved */
/* a sample program that returns a duplicate an open file descriptor*/
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>

int main() {
    int fildes,fildes2,fid;
    
    /* open file for reading only */
    if((fildes = open("dup2.c",O_RDONLY)) == -1){
      printf("cannot open file\n");
      exit(1);
    }
    fid =dup2(fildes,fildes2);
    if(fid >= 0)
        printf("Successful duplication of a file descriptor.\n");
    close(fildes2);
}
