Add funopen() function

This is a wrapper over the glibc fopencookie() function.

We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
because seekfn() there wrongly uses fpos_t, assuming it's an integral
type, and any code using that on a system where fpos_t is a struct
(such as GNU-based systems or NetBSD) will fail to build. In which case,
as the code has to be modified anyway, we might just as well use the
correct declaration.
This commit is contained in:
Guillem Jover
2013-10-21 05:07:56 +02:00
parent 86cbff385a
commit f41fdcf186
10 changed files with 538 additions and 1 deletions

View File

@@ -46,6 +46,23 @@ const char *fmtcheck(const char *, const char *);
char *fgetln(FILE *fp, size_t *lenp);
/*
* Note: We diverge from the FreeBSD, OpenBSD and DragonFlyBSD declarations,
* because seekfn() there wrongly uses fpos_t, assuming it's an integral
* type, and any code using that on a system where fpos_t is a struct
* (such as GNU-based systems or NetBSD) will fail to build. In which case,
* as the code has to be modified anyway, we might just as well use the
* correct declaration here.
*/
FILE *funopen(const void *cookie,
int (*readfn)(void *cookie, char *buf, int size),
int (*writefn)(void *cookie, const char *buf, int size),
off_t (*seekfn)(void *cookie, off_t offset, int whence),
int (*closefn)(void *cookie));
#define fropen(cookie, fn) funopen(cookie, fn, NULL, NULL, NULL)
#define fwopen(cookie, fn) funopen(cookie, NULL, fn, NULL, NULL)
int fpurge(FILE *fp);
__END_DECLS