/*------------------------------------------------------------------*/ /* testdupin.c */ /* Author: Bob Dondero */ /* The dup system call. */ /*------------------------------------------------------------------*/ #include #include #include #include enum {BUFFER_LENGTH = 100}; int main(int argc, char *argv[]) { int iFd; int iRet; char pcBuffer[BUFFER_LENGTH]; iFd = open("tempfile", O_RDONLY); if (iFd == -1) {perror(argv[0]); return EXIT_FAILURE; } iRet = close(0); if (iRet == -1) {perror(argv[0]); return EXIT_FAILURE; } iRet = dup(iFd); if (iRet == -1) {perror(argv[0]); return EXIT_FAILURE; } iRet = close(iFd); if (iRet == -1) {perror(argv[0]); return EXIT_FAILURE; } scanf("%s", pcBuffer); /* Print the data to verify that the scanf worked. */ printf("%s\n", pcBuffer); return 0; } /*------------------------------------------------------------------*/ /* Sample execution: $ gcc -Wall -ansi -pedantic testdupin.c -o testdupin $ testdupin somedata */