Message-Id: <3.0.1.32.19970709094816.00593c68@mailhost.sm.ic.ac.uk> Date: Wed, 09 Jul 1997 09:48:16 +0100 To: djgpp AT delorie DOT com From: Paul Dixon

Subject: Re: interesting redir behavior Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Precedence: bulk >`redir' relies on the fact that when you close handle x, the next open reuses that handle. If this is false in OpenDOS, the redirected file will remain empty. > >It would be interesting to see whether this is indeed the problem. Can >you compile `redir' (in src/utils/redir.c from djlsr201.zip) with -g, >step into it with a debugger and see what does `open' after `close' >return? The redir code does indeed include several blocks of form if ( condition ) { close(x); if (open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666 ) != x) fatal( "....cut...." ); argc--; argv++; } but the assumption made (that the old handle will be immediately reused) cannot be portable as it is based on no set standard. Wouldnt a revision of the code to use dup2(), as if ( condition ) { int newhandle = open( argv[2], O_WRONLY | O_CREAT | O_TRUNC, 0666 ); if ((newhandle < 0) || (dup2(newhandle, x) != x)) fatal( "....cut...." ); close(newhandle); argc--; argv++; } be guaranteed to work portably regardless of underlying handle allocation strategy? -------------------------------------------------------------------- Paul Dixon Email: p DOT dixon AT ic DOT ac DOT uk Software Engineer tel: +44 (171) 725 1098 Academic Dept of Paediatrics fax: +44 (171) 725 6284 St Mary's Hospital Medical School (a constituent college of Imperial College of Science, Technology & Medicine) Norfolk Place, London W2 1PG, UK ---------------------------------------------------------------------