Devika wrote:
> 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.

1. http://gcc.gnu.org/gcc-2.96.html
2. access to underlying filedescriptors was never part of C++ iostreams,
although GCC's C++ stdlibrary provided means for that.

> #include <ext/stdio_filebuf.h>
> typedef __gnu_cxx::stdio_filebuf FILEBUF;
> 
> 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.

What do you mean it is not getting typecasted properly? Are you aware of
the semantics of dynamic_cast?

Anyhow, I can see two solutions:
1. there is a complementary to stdio_filebuf which is a stream that you
should use instead of plain std::ofstream.
2. you could instantiate stdio_filebuf directly and pass a pointer to an
ostream's ctor. Above assumed stdio_ofstream is probably nothing
different, just that it wraps things up nicely.

BTW, did you even bother reading the intended topic of gnu.gcc.help? Shame
no you.

Uli

-- 
http://gcc.gnu.org/faq.html
http://parashift.com/c++-faq-lite/

_______________________________________________
Help-gplusplus mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-gplusplus

Reply via email to