annotate th_ioctx_stdio.c @ 678:7e207f1023d9

Split stdio and memio stuff to separate files from th_stdio.c
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 29 Feb 2020 12:19:02 +0200
parents
children 49c818acbbbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
678
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Simple I/O abstraction and context handling layer
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2012-2020 Tecnic Software productions (TNSP)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "th_ioctx.h"
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include <stdio.h>
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #define CTX_FH ((FILE *) ctx->data)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 static int th_stdio_fopen(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 ctx->data = (void *) fopen(ctx->filename, ctx->mode);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 return (ctx->data != NULL) ? THERR_OK : THERR_FOPEN;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 static void th_stdio_fclose(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 if (CTX_FH != NULL)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 fclose(CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 ctx->data = NULL;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 static int th_stdio_ferror(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 return ctx->status;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 static off_t th_stdio_ftell(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 return ftello(CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 static int th_stdio_fseek(th_ioctx *ctx, const off_t pos, const int whence)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 int ret = fseeko(CTX_FH, pos, whence);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 static int th_stdio_freset(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 if (CTX_FH != NULL)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 return th_stdio_fseek(ctx, 0, SEEK_SET);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 else
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 return THERR_OK;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 static off_t th_stdio_fsize(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 off_t savePos, fileSize;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 // Check if the size is cached
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 if (ctx->size != 0)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 return ctx->size;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 // Get file size
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 if ((savePos = th_stdio_ftell(ctx)) < 0)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 return -1;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 if (th_stdio_fseek(ctx, 0, SEEK_END) != 0)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 return -1;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 if ((fileSize = th_stdio_ftell(ctx)) < 0)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 return -1;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 if (th_stdio_fseek(ctx, savePos, SEEK_SET) != 0)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 return -1;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 ctx->size = fileSize;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 return fileSize;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 static BOOL th_stdio_feof(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 return feof(CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 static int th_stdio_fgetc(th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95 int ret = fgetc(CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 static int th_stdio_fputc(int v, th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 int ret = fputc(v, CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 static size_t th_stdio_fread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 size_t ret = fread(ptr, size, nmemb, CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117 static size_t th_stdio_fwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 size_t ret = fwrite(ptr, size, nmemb, CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 static char * th_stdio_fgets(char *str, int size, th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 char *ret = fgets(str, size, CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 static int th_stdio_fputs(const char *str, th_ioctx *ctx)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 int ret = fputs(str, CTX_FH);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 static int th_stdio_vfprintf(th_ioctx *ctx, const char *fmt, va_list ap)
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 int ret = vfprintf(CTX_FH, fmt, ap);
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 ctx->status = th_get_error();
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 return ret;
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 }
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149 const th_ioctx_ops th_stdio_io_ops =
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 {
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 "stdio",
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 th_stdio_fopen,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 th_stdio_fclose,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 th_stdio_freset,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 th_stdio_ferror,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 th_stdio_fseek,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 th_stdio_fsize,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 th_stdio_ftell,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 th_stdio_feof,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162 th_stdio_fgetc,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163 th_stdio_fputc,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 th_stdio_fread,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 th_stdio_fwrite,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 th_stdio_fgets,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 th_stdio_fputs,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 th_stdio_vfprintf,
7e207f1023d9 Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 };