1/* Copyright (C) 1991-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
17
18#ifndef __cookie_io_functions_t_defined
19#define __cookie_io_functions_t_defined 1
20
21#include <bits/types.h>
22
23/* Functions to do I/O and file management for a stream. */
24
25/* Read NBYTES bytes from COOKIE into a buffer pointed to by BUF.
26 Return number of bytes read. */
27typedef __ssize_t cookie_read_function_t (void *__cookie, char *__buf,
28 size_t __nbytes);
29
30/* Write NBYTES bytes pointed to by BUF to COOKIE. Write all NBYTES bytes
31 unless there is an error. Return number of bytes written. If
32 there is an error, return 0 and do not write anything. If the file
33 has been opened for append (__mode.__append set), then set the file
34 pointer to the end of the file and then do the write; if not, just
35 write at the current file pointer. */
36typedef __ssize_t cookie_write_function_t (void *__cookie, const char *__buf,
37 size_t __nbytes);
38
39/* Move COOKIE's file position to *POS bytes from the
40 beginning of the file (if W is SEEK_SET),
41 the current position (if W is SEEK_CUR),
42 or the end of the file (if W is SEEK_END).
43 Set *POS to the new file position.
44 Returns zero if successful, nonzero if not. */
45typedef int cookie_seek_function_t (void *__cookie, __off64_t *__pos, int __w);
46
47/* Close COOKIE. */
48typedef int cookie_close_function_t (void *__cookie);
49
50/* The structure with the cookie function pointers.
51 The tag name of this struct is _IO_cookie_io_functions_t to
52 preserve historic C++ mangled names for functions taking
53 cookie_io_functions_t arguments. That name should not be used in
54 new code. */
55typedef struct _IO_cookie_io_functions_t
56{
57 cookie_read_function_t *read; /* Read bytes. */
58 cookie_write_function_t *write; /* Write bytes. */
59 cookie_seek_function_t *seek; /* Seek/tell file position. */
60 cookie_close_function_t *close; /* Close file. */
61} cookie_io_functions_t;
62
63#endif
64