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()


2009/4/16 Petr Baudis <pasky@suse.cz>:

> ?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.

The program I'm passing the FILE* to is calling fstat() in order to
determine the file size (st.st_size).  This is a sensible value even
for a fmemopened file.  The standard mentions this field being valid
for two types of memory object though I'm not sure if that relates:
http://www.opengroup.org/onlinepubs/009695399/basedefs/sys/stat.h.html.

You're right, that fileno() doesn't return a valid file descriptor. I
had expected fmemopen() to do something more sophisticated in order to
fake-up a file such that it would have a valid descriptor and client
code would not need to be changed.

Maybe the documentation should be updated to mention that functions
requiring file descriptors won't work with the result of fmemopen()?

Many thanks.

Alex


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