/*-------------------------------------------------------------------*/ /* testdupout.c */ /* The dup system call. */ /*-------------------------------------------------------------------*/ #include #include #include int main(int argc, char *argv[]) { int iFd; int iRet; iFd = creat("tempfile", 0644); if (iFd == -1) {perror(argv[0]); return 1; } iRet = close(1); if (iRet == -1) {perror(argv[0]); return 1; } iRet = dup(iFd); if (iRet == -1) {perror(argv[0]); return 1; } iRet = close(iFd); if (iRet == -1) {perror(argv[0]); return 1; } printf("somedata\n"); return 0; } /* Sample execution: --> gcc -Wall -ansi -pedantic -o testdupout testdupout.c --> testdupout --> cat tempfile somedata --> */