This is the mail archive of the libc-help@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with fstat() after fmemopen()


  Hi!

On Thu, Apr 16, 2009 at 12:42:13AM +0100, Alexander Lamaison wrote:
> I've been trying to use fmemopen() to open a string.  This is in order
> to pass it to a program that expects a FILE *.  However, I've found
> that calling fstat using the returned stream's file descriptor fails
> with errno 9, "Bad descriptor".  Other operations, such as reading and
> seeking, work fine.
> 
> fmemopen() returns a FILE whose fd is set to -2 (obviously invalid)
> which fstat() dislikes very much.  Is fstatting an fmemopened stream
> intended not to work?  If so, the documentation doesn't mention it at
> all.  Much of the appeal of using fmemopen to fake a real file seems
> to go away if the client program has to treat it specially.

  So what would you expect fileno() and the subsequent fstat() to
return? Nothing in the struct stat makes any sense whatsoever with
fmemopen(). I would just test if fileno() returns a valid file
descriptor.

-- 
				Petr "Pasky" Baudis
The average, healthy, well-adjusted adult gets up at seven-thirty
in the morning feeling just terrible. -- Jean Kerr


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]