help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: not able to get fd of ofstream using stdio_filebuf


From: Rolf Magnus
Subject: Re: not able to get fd of ofstream using stdio_filebuf
Date: Mon, 28 Mar 2005 12:54:52 +0200

Devika wrote:

> Hi,
> 
> I want to call fcntl function for which I need fd().
> The code part is smthing like :
> 
> ofstream osf("somefile" , ios::app);
> 
> filebuf * fb ;
> fb = osf.rdbuf();
> 
> fcntl(fb -> fd(), F_SETLKW, &cfLock);
> 
> Now this code was working fine with gcc 2.96 but now it[gcc 3.2.3] says
> no matching function for fd() since the function fd() of basic_filebuf
> has been removed in gcc 3.2.3. and they have provided new extension
> stdio_filebuf.

Yes. That's because the C++ standard forbids basic_filebuf to provide any
member functions that are not explicitly mentioned in the standard.

> I tried following thing:
> 
> #include <ext/stdio_filebuf.h>
> typedef __gnu_cxx::stdio_filebuf FILEBUF;

This shouldn't compile. stdio_filebuf is a template.

> 
> 
> ofstream osf("somefile" , ios::app);
> FILEBUF *fb ;
> fb = dynamic_cast<FILEBUF *>(osf.rdbuf());
> 
> ...But its not getting typecasted properly and i m getting segment
> fault.

You cannot just take a basic_filebuf and use it as if it were an
stdio_filebuf. It actually has to be one. Your dynamic_cast probably
returns a null pointer, since the conversion failed.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]