In article <c1**************************@posting.google.com >,
Markus Dehmann <ma*******@gmx.de> wrote:
Does anyone know how to implement this so that it can also be used on
non-GNU systems? Only read access would be okay.
FILE *fmemopen (void *buf, size_t size, const char *opentype)
{
FILE *f;
assert(strcmp(opentype, "r") == 0);
f = tmpfile();
fwrite(buf, 1, size, f);
rewind(f);
return f;
}
On any particular implementation you may be able to work out how to
manually construct a FILE object that does what you want. For example,
on the system I'm using FILE is a struct which in part contains this:
/* operations */
void *_cookie; /* cookie passed to io functions */
int (*_close) __P((void *));
int (*_read) __P((void *, char *, int));
fpos_t (*_seek) __P((void *, fpos_t, int));
int (*_write) __P((void *, const char *, int));
I imagine that it would work if you set the cookie to the address of
your buffer and provided suitable functions for _read etc.
But of course if you want your code to be portable, you will have
to work this out for every system you care about.
-- Richard