[fpc-pascal] FpDup2 dosen't work!

Jonas Maebe jonas.maebe at elis.ugent.be
Fri Oct 21 11:41:53 CEST 2005


On 19 okt 2005, at 03:16, Linuxer Wang wrote:

> I can't make FpDup2 work. Even the example provided by the document
> can't work as well.

It seems to me the fpdup2 simply does something different than what  
the example program suggests. It creates a copy of the first file  
record into the second. The underlying dup2 system call or libc  
function first closes the second file if it was open.

So after the fpdup2() call, all writes to the second file you passed  
it will go to the same place as writes to the first one (and this  
indeed works in the example program: all writers to f after the fpdup2 
() call also appear on screen). It does not allow you to "clone" the  
output to a different place.

The error checking in the example program is also wrong. fpdup2  
returns -1 on error. If no error occurred, it returns the file handle  
corresponding to file of the second parameter (which usually will be  
different from 0, although not always -- namely when you dup  
something to standard input).


Jonas



More information about the fpc-pascal mailing list