Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!utgpu!water!watmath!clyde!rutgers!ames!oliveb!pyramid!prls!philabs!micomvax!musocs!mcgill-vision!mouse From: mouse@mcgill-vision.UUCP Newsgroups: comp.unix.wizards Subject: Re: dup2 issue Message-ID: <759@mcgill-vision.UUCP> Date: Wed, 6-May-87 02:56:45 EDT Article-I.D.: mcgill-v.759 Posted: Wed May 6 02:56:45 1987 Date-Received: Thu, 14-May-87 01:32:33 EDT References: <1004@copper.TEK.COM> Distribution: world Organization: McGill University, Montreal Lines: 43 Keywords: dup2 In article <1004@copper.TEK.COM>, stevesu@copper.TEK.COM (Steve Summit) writes: > [what does dup2 do with two identical arguments? Question arises > from something like] > close(sv[1]); > close(0); > close(1); > close(2); > dup(sv[0]); > dup(sv[0]); > dup(sv[0]); > close(sv[0]); > This code fails if it is invoked with 0, 1, or 2 already closed, > I changed the code to > if(sv[0] != 0) > dup2(sv[0], 0); > if(sv[0] != 1) > dup2(sv[0], 1); > if(sv[0] != 2) > dup2(sv[0], 2); > if(sv[0] > 2) > close(sv[0]); > but I wondered if the first three if's were strictly necessary. Well, I would suggest you write it as if (sv[0] != fileno(stdin)) { dup2(sv[0],fileno(stdin)); close(sv[0]); } dup2(fileno(stdin),fileno(stdout)); dup2(fileno(stdin),fileno(stderr)); [this line to patch around stupid counterproductive 50% rule] [this line to patch around stupid counterproductive 50% rule] der Mouse (mouse@mcgill-vision.uucp)