1 /****************************************************************************
2 *
3 *    The MIT License (MIT)
4 *
5 *    Copyright 2020 NXP
6 *    All Rights Reserved.
7 *
8 *    Permission is hereby granted, free of charge, to any person obtaining
9 *    a copy of this software and associated documentation files (the
10 *    'Software'), to deal in the Software without restriction, including
11 *    without limitation the rights to use, copy, modify, merge, publish,
12 *    distribute, sub license, and/or sell copies of the Software, and to
13 *    permit persons to whom the Software is furnished to do so, subject
14 *    to the following conditions:
15 *
16 *    The above copyright notice and this permission notice (including the
17 *    next paragraph) shall be included in all copies or substantial
18 *    portions of the Software.
19 *
20 *    THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
21 *    EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 *    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
23 *    IN NO EVENT SHALL VIVANTE AND/OR ITS SUPPLIERS BE LIABLE FOR ANY
24 *    CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 *    TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 *    SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *
28 *****************************************************************************/
29 
30 /* Bufferred reader interface */
31 #ifndef _BUFFERRED_READER_
32 #define _BUFFERRED_READER_
33 
34 typedef struct buffered_reader {
35     char *data_buf;
36     int size;
37     int index;
38     int is_valid;
39 } bufferred_reader_t;
40 
41 #define E_BUF_IO_OUT_OF_MEMORY      -10
42 #define E_BUF_IO_READ_ERROR         -11
43 #define E_BUF_INVALID_HANDLE        -12
44 #define E_BUF_IO_INVALID_PARAMETERS -13
45 
46 int is_buffered_handle_valid(bufferred_reader_t *fd);
47 int bufferred_fopen(bufferred_reader_t *fd, char *buf, int size);
48 int bufferred_ftell(bufferred_reader_t *fd);
49 int bufferred_fread(
50     void *ptr,
51     int size,
52     int nmemb,
53     bufferred_reader_t *fd
54 );
55 int bufferred_fseek(
56     bufferred_reader_t *fd,
57     int offset,
58     int direction
59 );
60 int bufferred_fclose(bufferred_reader_t *fd);
61 char *bufferred_fgets(char* buff, int len, bufferred_reader_t *fd);
62 
63 #endif //!_BUFFERRED_READER_
64