comparison th_ioctx.c @ 461:04320ca79407

Actually, use a inline function for ioctx atime updates.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 17 Feb 2018 23:42:49 +0200
parents 0a1a65503e0b
children 96d137a6b392
comparison
equal deleted inserted replaced
460:0a1a65503e0b 461:04320ca79407
9 #include "th_string.h" 9 #include "th_string.h"
10 #include "th_endian.h" 10 #include "th_endian.h"
11 #include <stdio.h> 11 #include <stdio.h>
12 12
13 13
14 #define TH_UPDATE_ATIME do { ctx->atime = time(NULL); } while (0) 14 static void th_io_update_atime(th_ioctx *ctx)
15 {
16 ctx->atime = time(NULL);
17 }
15 18
16 19
17 th_ioctx *th_io_new(const th_ioctx_ops *fops, const char *filename) 20 th_ioctx *th_io_new(const th_ioctx_ops *fops, const char *filename)
18 { 21 {
19 th_ioctx *ctx = th_malloc0(sizeof(th_ioctx)); 22 th_ioctx *ctx = th_malloc0(sizeof(th_ioctx));
151 } 154 }
152 155
153 156
154 int thferror(th_ioctx *ctx) 157 int thferror(th_ioctx *ctx)
155 { 158 {
156 TH_UPDATE_ATIME; 159 th_io_update_atime(ctx);
157 return ctx->fops->ferror(ctx); 160 return ctx->fops->ferror(ctx);
158 } 161 }
159 162
160 163
161 int thfseek(th_ioctx *ctx, const off_t offset, int whence) 164 int thfseek(th_ioctx *ctx, const off_t offset, int whence)
162 { 165 {
163 TH_UPDATE_ATIME; 166 th_io_update_atime(ctx);
164 return ctx->fops->fseek(ctx, offset, whence); 167 return ctx->fops->fseek(ctx, offset, whence);
165 } 168 }
166 169
167 170
168 off_t thfsize(th_ioctx *ctx) 171 off_t thfsize(th_ioctx *ctx)
169 { 172 {
170 TH_UPDATE_ATIME; 173 th_io_update_atime(ctx);
171 return ctx->fops->fsize(ctx); 174 return ctx->fops->fsize(ctx);
172 } 175 }
173 176
174 177
175 off_t thftell(th_ioctx *ctx) 178 off_t thftell(th_ioctx *ctx)
176 { 179 {
177 TH_UPDATE_ATIME; 180 th_io_update_atime(ctx);
178 return ctx->fops->ftell(ctx); 181 return ctx->fops->ftell(ctx);
179 } 182 }
180 183
181 184
182 BOOL thfeof(th_ioctx *ctx) 185 BOOL thfeof(th_ioctx *ctx)
183 { 186 {
184 TH_UPDATE_ATIME; 187 th_io_update_atime(ctx);
185 return ctx->fops->feof(ctx); 188 return ctx->fops->feof(ctx);
186 } 189 }
187 190
188 191
189 int thfgetc(th_ioctx *ctx) 192 int thfgetc(th_ioctx *ctx)
190 { 193 {
191 TH_UPDATE_ATIME; 194 th_io_update_atime(ctx);
192 return ctx->fops->fgetc(ctx); 195 return ctx->fops->fgetc(ctx);
193 } 196 }
194 197
195 198
196 int thfputc(int v, th_ioctx *ctx) 199 int thfputc(int v, th_ioctx *ctx)
197 { 200 {
198 TH_UPDATE_ATIME; 201 th_io_update_atime(ctx);
199 return ctx->fops->fputc(v, ctx); 202 return ctx->fops->fputc(v, ctx);
200 } 203 }
201 204
202 205
203 size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) 206 size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx)
204 { 207 {
205 TH_UPDATE_ATIME; 208 th_io_update_atime(ctx);
206 return ctx->fops->fread(ptr, size, nmemb, ctx); 209 return ctx->fops->fread(ptr, size, nmemb, ctx);
207 } 210 }
208 211
209 212
210 size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) 213 size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx)
211 { 214 {
212 TH_UPDATE_ATIME; 215 th_io_update_atime(ctx);
213 return ctx->fops->fwrite(ptr, size, nmemb, ctx); 216 return ctx->fops->fwrite(ptr, size, nmemb, ctx);
214 } 217 }
215 218
216 219
217 char *thfgets(char *str, int size, th_ioctx *ctx) 220 char *thfgets(char *str, int size, th_ioctx *ctx)