Mail Archives: djgpp/1997/07/09/04:44:42
>`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
---------------------------------------------------------------------
- Raw text -