This is the mail archive of the
libc-help@sourceware.org
mailing list for the glibc project.
Re: Problem with fstat() after fmemopen()
- From: Petr Baudis <pasky at suse dot cz>
- To: Alexander Lamaison <awl03 at doc dot ic dot ac dot uk>
- Cc: libc-help at sourceware dot org
- Date: Thu, 16 Apr 2009 10:25:03 +0200
- Subject: Re: Problem with fstat() after fmemopen()
- References: <9c3275a90904151642n7a13cf06w6e1834b849d37f1a@mail.gmail.com>
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