annotate th_ioctx.h @ 771:c17eadc60c3d

Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 20 Feb 2023 23:33:45 +0200
parents 8eca15bde07d
children 1959ba53e9dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
2 * Simple I/O abstraction and context handling layer
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
726
29e44a58bc73 Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 722
diff changeset
4 * (C) Copyright 2012-2022 Tecnic Software productions (TNSP)
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
653
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
8 /// @file
3c9205d52376 Doxygen fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 650
diff changeset
9 /// @brief Simple I/O abstraction and context handling layer
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #ifndef TH_IOCTX_H
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define TH_IOCTX_H
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "th_util.h"
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
14 #include <time.h>
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
92
40568456eb5b Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 72
diff changeset
16
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #ifdef __cplusplus
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 extern "C" {
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #endif
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
22 //
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
23 // Typedefs and structures
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
24 //
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
25 struct th_ioctx_t;
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
26 struct th_ioctx_t_ops;
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
27
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
28
436
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
29 /** I/O context structure
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
30 */
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
31 typedef struct th_ioctx_t
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 {
436
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
33 char *filename; ///< Context filename, if any. May be NULL.
769
8eca15bde07d Rename some th_ioctx members.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
34 bool fn_allocated; ///< true if filename is allocated, false if "const"
436
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
35 char *mode; ///< Context's stdio open "mode", may also be NULL.
769
8eca15bde07d Rename some th_ioctx members.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
36 bool md_allocated; ///< true if mode string is allocated, false if "const"
8eca15bde07d Rename some th_ioctx members.
Matti Hamalainen <ccr@tnsp.org>
parents: 735
diff changeset
37 bool ctx_allocated; ///< true if this structure has been allocated
650
24cbab6e88c6 Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
38
436
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
39 void *data; ///< Internal data
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
40 time_t atime; ///< Last access time
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
41 int64_t size; ///< Size in bytes
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
42 int status; ///< Status
9148bc3fa838 Begin adding Doxygen documentation for some things. Very rudimentary, and
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
43 size_t line; ///< Line number
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
675
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
45 // Mem data
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
46 size_t maxSize; ///< Maximum size (0 = no limit)
716
7aee25fbc504 Improve few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
47 size_t memSize; ///< Current size of data "used"
7aee25fbc504 Improve few comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 700
diff changeset
48 size_t memAlloc; ///< Amount actually allocated for data (>= memSize)
675
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
49 size_t minAlloc; ///< Minimum allocation increase (0 = default)
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
50 off_t memOffset; ///< Current offset in data
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
51 uint8_t *memData; ///< Pointer to data
735
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
52 bool memFree; ///< true = free the allocated memory on thfclose(), false = no
31bc1ed07cf5 Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
Matti Hamalainen <ccr@tnsp.org>
parents: 726
diff changeset
53 bool memWrite; ///< true = memory can be written to / expanded etc. false = no
675
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
54
fb4093ad1f7b Add MemIO ioctx functionality.
Matti Hamalainen <ccr@tnsp.org>
parents: 653
diff changeset
55 // Message functions
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
56 void (*error)(struct th_ioctx_t *ctx, const int err, const char *msg);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
57 void (*msg)(struct th_ioctx_t *ctx, const int level, const char *msg);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
58
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
59 const struct th_ioctx_t_ops *fops; ///< Pointer to I/O ops struct to be used with this context
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
60 } th_ioctx_t;
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
61
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
62
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
63 typedef struct th_ioctx_t_ops
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
64 {
616
594f197f7005 Slight improvements to the almost non-existing Doxygen documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 577
diff changeset
65 char *name; ///< Name of this I/O ops definition
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
66
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
67 int (*fopen)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
68 void (*fclose)(th_ioctx_t *ctx);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
69
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
70 int (*freset)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
71 int (*ferror)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
72 int (*fseek)(th_ioctx_t *ctx, const off_t, const int whence);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
73 off_t (*fsize)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
74 off_t (*ftell)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
75 bool (*feof)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
76 int (*fgetc)(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
77 int (*fputc)(int, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
78 size_t (*fread)(void *ptr, const size_t, const size_t, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
79 size_t (*fwrite)(const void *ptr, const size_t, const size_t, th_ioctx_t *ctx);
208
3635415a2d03 More work on th_ioctx stuff and wrappers.
Matti Hamalainen <ccr@tnsp.org>
parents: 204
diff changeset
80
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
81 char * (*fgets)(char *str, int size, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
82 int (*fputs)(const char *str, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
83 int (*vfprintf)(th_ioctx_t *ctx, const char *fmt, va_list ap);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
84
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
85 } th_ioctx_t_ops;
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
86
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
87
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
88 //
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
89 // Some basic iops
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
90 //
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
91 extern const th_ioctx_t_ops th_stdio_io_ops, th_mem_io_ops;
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
92
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
95 //
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
96 // I/O context management functions
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
97 //
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
98 th_ioctx_t * th_io_new(const th_ioctx_t_ops *fops, const char *filename, const char *mode);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
99 int th_io_fopen(th_ioctx_t **pctx, const th_ioctx_t_ops *fops, const char *filename, const char *mode);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
100 int th_io_reopen(th_ioctx_t *ctx, const char *mode);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
101 void th_io_close(th_ioctx_t *ctx);
650
24cbab6e88c6 Remove th_io_free(), merge the functionality to th_io_close(). Add flags
Matti Hamalainen <ccr@tnsp.org>
parents: 616
diff changeset
102
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
103 void th_io_init_stdio(th_ioctx_t *ctx, FILE *fh);
72
43df05a632cb Break I/O context API, add function pointers to init/open/new functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
104
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
105 bool th_io_set_handlers(th_ioctx_t *ctx,
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
106 void (*error)(th_ioctx_t *, const int, const char *msg),
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
107 void (*msg)(th_ioctx_t *, const int, const char *msg));
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
108
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
109 int th_io_error_v(th_ioctx_t *ctx, const int err, const char *fmt, va_list ap);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
110 void th_io_msg_v(th_ioctx_t *ctx, const int level, const char *fmt, va_list ap);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
111 int th_io_error(th_ioctx_t *ctx, const int err, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
112 TH_ATTR_PRINTF_FMT(3, 4);
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
113 void th_io_msg(th_ioctx_t *ctx, const int level, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
114 TH_ATTR_PRINTF_FMT(3, 4);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
115
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
117 //
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
118 // Basic I/O operations
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
119 //
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
120 int thfopen(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
121 void thfclose(th_ioctx_t *ctx);
686
dfc2c9f0577f Add functions thfopen(ctx) and thfclose(ctx) to th_ioctx.
Matti Hamalainen <ccr@tnsp.org>
parents: 677
diff changeset
122
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
123 int thfreset(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
124 int thferror(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
125 int thfseek(th_ioctx_t *ctx, const off_t, const int whence);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
126 off_t thfsize(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
127 off_t thftell(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
128 bool thfeof(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
129 int thfgetc(th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
130 int thfputc(int ch, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
131 size_t thfread(void *ptr, const size_t, const size_t, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
132 size_t thfwrite(const void *, const size_t, const size_t, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
133 char * thfgets(char *ptr, int size, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
134 int thfputs(const char *ptr, th_ioctx_t *ctx);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
135 int thvfprintf(th_ioctx_t *ctx, const char *fmt, va_list ap);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
136 int thfprintf(th_ioctx_t *ctx, const char *fmt, ...)
577
70d44ba005ac Define a helper macro for __attribute__ ((__format__ (__printf__, 2, 3)))
Matti Hamalainen <ccr@tnsp.org>
parents: 570
diff changeset
137 TH_ATTR_PRINTF_FMT(2, 3);
72
43df05a632cb Break I/O context API, add function pointers to init/open/new functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 67
diff changeset
138
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
139 bool thfread_str(th_ioctx_t *ctx, void *ptr, const size_t len);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
140 bool thfread_u8(th_ioctx_t *ctx, uint8_t *);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
141 bool thfwrite_str(th_ioctx_t *ctx, const void *ptr, const size_t len);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
142 bool thfwrite_u8(th_ioctx_t *ctx, const uint8_t);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
143
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
144
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
145 //
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
146 // Endian-handling file read/write routines
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
147 //
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
148 bool thfwrite_ne16(th_ioctx_t *ctx, const uint16_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
149 bool thfwrite_ne32(th_ioctx_t *ctx, const uint32_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
150 bool thfwrite_ne64(th_ioctx_t *ctx, const uint64_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
151 bool thfread_ne16(th_ioctx_t *ctx, uint16_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
152 bool thfread_ne32(th_ioctx_t *ctx, uint32_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
153 bool thfread_ne64(th_ioctx_t *ctx, uint64_t *v);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
154
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
155 bool thfwrite_le16(th_ioctx_t *ctx, const uint16_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
156 bool thfwrite_le32(th_ioctx_t *ctx, const uint32_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
157 bool thfwrite_le64(th_ioctx_t *ctx, const uint64_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
158 bool thfread_le16(th_ioctx_t *ctx, uint16_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
159 bool thfread_le32(th_ioctx_t *ctx, uint32_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
160 bool thfread_le64(th_ioctx_t *ctx, uint64_t *v);
202
b392293047da Refactor I/O contexts. Breaks API and all that.
Matti Hamalainen <ccr@tnsp.org>
parents: 129
diff changeset
161
771
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
162 bool thfwrite_be16(th_ioctx_t *ctx, const uint16_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
163 bool thfwrite_be32(th_ioctx_t *ctx, const uint32_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
164 bool thfwrite_be64(th_ioctx_t *ctx, const uint64_t v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
165 bool thfread_be16(th_ioctx_t *ctx, uint16_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
166 bool thfread_be32(th_ioctx_t *ctx, uint32_t *v);
c17eadc60c3d Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
Matti Hamalainen <ccr@tnsp.org>
parents: 769
diff changeset
167 bool thfread_be64(th_ioctx_t *ctx, uint64_t *v);
67
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 #ifdef __cplusplus
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 }
d94af48cef7b Added new module, a simple I/O context helper.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172 #endif
129
aa2d608fb3f3 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 92
diff changeset
173 #endif // TH_IOCTX_H