HP C - dup2(file_desc1,file_desc2) question: implicit CLOSE?



Hello,

I am using dup2 (file_desc, fileno(stdout)) to redirect a program's
output to a file. After some time, or after some amount of output has
been written (whatever comes first), the program opens a new output
file, and repeats above dup2 (...) statement to route the output to a
new file. The redirection works fine, all output appears in the correct
files just as expected.

But: After a while, the program is left with an increasing number of
open output files. The reason for this is clearly that I did not CLOSE
the output files, and the fix is trivial.

The C documentation states "If file_desc2 is connected to an open file,
that file is closed".

>>From this, I would expect that an previous output file is closed
implicitely with the next dup2(...), and so on. My program obviously
does not behave like this. Am I wrong with this expectation?

Compaq C++ V6.5-046 for OpenVMS Alpha V8.2

Kind regards,
-Uli

.



Relevant Pages

  • HP C - dup2(file_desc1,file_desc2) question: implicit CLOSE?
    ... I am using dup2 ) to redirect a program's ... the program opens a new output ... Am I wrong with this expectation? ...
    (comp.os.vms)
  • Re: HP C - dup2(file_desc1,file_desc2) question: implicit CLOSE?
    ... > I am using dup2 ) to redirect a program's ... > been written, the program opens a new output ... You could try the fcntl equivalent and see if the behavior is any ...
    (comp.os.vms)
  • Re: onmouseover in IE6 / XP combination?
    ... Although it seems that I have not explained my real problem well enough:) ... > redirect, then opens fine. ... This is normal, due to the redirect, the error sits elsewhere ... I can hardly open my site telling visitors they have to tweak their system for visiting, ...
    (microsoft.public.windowsxp.general)
  • Re: Using Office 2007 with redirected folders
    ... Regarding the Administator account, I have not set up a specific OU, because ... GPO: Redirect Folders ... The Open File dialog opens and immediately closes when I press Ctrl ...
    (microsoft.public.windows.server.general)
  • file redirect .... 98
    ... I am able to redirect local file.I meant when user opens file says "1.txt" ... But same thing i want to do on network file.I meant if user tries to open ...
    (microsoft.public.development.device.drivers)