libc: add support for custom streams with fopencookie()

This commit adds support for custom stream via fopencookie function.
The function allows the programmer the create his own custom stream
for IO operations and hook his custom functions to it.

This is a non POSIX interface defined in Standard C library and implemented
according to it. The only difference is in usage of off_t instead of
off64_t. Programmer can use 64 bits offset if CONFIG_FS_LARGEFILE is
enabled. In that case off_t is defined as int64_t (int32_t otherwise).

Field fs_fd is removed from file_struct and fs_cookie is used instead
as a shared variable for file descriptor or user defined cookie.

The interface will be useful for future fmemopen implementation.

Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
Michal Lenc
2023-08-27 21:33:44 +02:00
committed by Xiang Xiao
parent 083c87b39a
commit 0a107ca6d9
18 changed files with 347 additions and 49 deletions
+5
View File
@@ -244,6 +244,11 @@ int dprintf(int fd, FAR const IPTR char *fmt, ...) printf_like(2, 3);
int vdprintf(int fd, FAR const IPTR char *fmt, va_list ap)
printf_like(2, 0);
/* Custom stream operation fopencookie. */
FAR FILE *fopencookie(FAR void *cookie, FAR const char *mode,
cookie_io_functions_t io_funcs);
/* Operations on paths */
FAR FILE *tmpfile(void) fopen_like;