summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-12-05 16:04:43 -0500
committerRich Felker <dalias@aerifal.cx>2017-12-06 13:11:48 -0500
commit061843340fbf2493bb615e20e66f60c5d1ef0455 (patch)
tree0613a9ef9b70c5bd3653617b56cf7ca1a615325a /include
parent4000b0107ddd7fe733fa31d4f078c6fcd35851d6 (diff)
downloadmusl-061843340fbf2493bb615e20e66f60c5d1ef0455.tar.gz
implement the fopencookie extension to stdio
notes added by maintainer: this function is a GNU extension. it was chosen over the similar BSD function funopen because the latter depends on fpos_t being an arithmetic type as part of its public API, conflicting with our definition of fpos_t and with the intent that it be an opaque type. it was accepted for inclusion because, despite not being widely used, it is usually very difficult to extricate software using it from the dependency on it. calling pattern for the read and write callbacks is not likely to match glibc or other implementations, but should work with any reasonable callbacks. in particular the read function is never called without at least one byte being needed to satisfy its caller, so that spurious blocking is not introduced. contracts for what callbacks called from inside libc/stdio can do are always complicated, and at some point still need to be specified explicitly. at the very least, the callbacks must return or block indefinitely (they cannot perform nonlocal exits) and they should not make calls to stdio using their own FILE as an argument.
Diffstat (limited to 'include')
-rw-r--r--include/stdio.h14
1 files changed, 14 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
index 884d2e6a..2932c76f 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -182,6 +182,20 @@ int vasprintf(char **, const char *, __isoc_va_list);
#ifdef _GNU_SOURCE
char *fgets_unlocked(char *, int, FILE *);
int fputs_unlocked(const char *, FILE *);
+
+typedef ssize_t (cookie_read_function_t)(void *, char *, size_t);
+typedef ssize_t (cookie_write_function_t)(void *, const char *, size_t);
+typedef int (cookie_seek_function_t)(void *, off_t *, int);
+typedef int (cookie_close_function_t)(void *);
+
+typedef struct {
+ cookie_read_function_t *read;
+ cookie_write_function_t *write;
+ cookie_seek_function_t *seek;
+ cookie_close_function_t *close;
+} cookie_io_functions_t;
+
+FILE *fopencookie(void *, const char *, cookie_io_functions_t);
#endif
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)