Mercurial > hg > th-libs
annotate th_ioctx_stdio.c @ 691:49c818acbbbe
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 09 Mar 2020 16:22:01 +0200 |
parents | 7e207f1023d9 |
children | 4ca6a3b30fe8 |
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 { |
691 | 54 return th_stdio_fseek(ctx, 0, SEEK_SET); |
678
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
58 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
|
59 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 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
|
61 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
62 // 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
|
63 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
|
64 return ctx->size; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 // Get file size |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
67 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
|
68 return -1; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
69 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
70 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
|
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 ((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
|
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 (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
|
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 ctx->size = fileSize; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
80 return fileSize; |
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 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 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
|
85 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
86 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
|
87 } |
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 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 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
|
91 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
92 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
|
93 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
|
94 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
98 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
|
99 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
100 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
|
101 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
|
102 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
103 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
105 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 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
|
107 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 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
|
109 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
|
110 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
111 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 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
|
115 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 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
|
117 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
|
118 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
120 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
121 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
122 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
|
123 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 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
|
125 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
|
126 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
127 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
128 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
129 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
130 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
|
131 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
132 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
|
133 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
|
134 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
135 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
136 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
137 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 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
|
139 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 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
|
141 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
|
142 return ret; |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 } |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
146 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
|
147 { |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
148 "stdio", |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 th_stdio_fopen, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 th_stdio_fclose, |
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_freset, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
154 th_stdio_ferror, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 th_stdio_fseek, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 th_stdio_fsize, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
157 th_stdio_ftell, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
158 th_stdio_feof, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
159 th_stdio_fgetc, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 th_stdio_fputc, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 th_stdio_fread, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 th_stdio_fwrite, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
163 |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
164 th_stdio_fgets, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
165 th_stdio_fputs, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
166 th_stdio_vfprintf, |
7e207f1023d9
Split stdio and memio stuff to separate files from th_stdio.c
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
167 }; |