Mercurial > hg > th-libs
comparison th_ioctx.c @ 460:0a1a65503e0b
Use a macro for updating atime.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 17 Feb 2018 23:41:11 +0200 |
parents | 85fa3d333556 |
children | 04320ca79407 |
comparison
equal
deleted
inserted
replaced
459:7fca448847a3 | 460:0a1a65503e0b |
---|---|
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) | |
15 | |
16 | |
14 th_ioctx *th_io_new(const th_ioctx_ops *fops, const char *filename) | 17 th_ioctx *th_io_new(const th_ioctx_ops *fops, const char *filename) |
15 { | 18 { |
16 th_ioctx *ctx = th_malloc0(sizeof(th_ioctx)); | 19 th_ioctx *ctx = th_malloc0(sizeof(th_ioctx)); |
17 if (ctx == NULL) | 20 if (ctx == NULL) |
18 return NULL; | 21 return NULL; |
148 } | 151 } |
149 | 152 |
150 | 153 |
151 int thferror(th_ioctx *ctx) | 154 int thferror(th_ioctx *ctx) |
152 { | 155 { |
153 ctx->atime = time(NULL); | 156 TH_UPDATE_ATIME; |
154 return ctx->fops->ferror(ctx); | 157 return ctx->fops->ferror(ctx); |
155 } | 158 } |
156 | 159 |
157 | 160 |
158 int thfseek(th_ioctx *ctx, const off_t offset, int whence) | 161 int thfseek(th_ioctx *ctx, const off_t offset, int whence) |
159 { | 162 { |
160 ctx->atime = time(NULL); | 163 TH_UPDATE_ATIME; |
161 return ctx->fops->fseek(ctx, offset, whence); | 164 return ctx->fops->fseek(ctx, offset, whence); |
162 } | 165 } |
163 | 166 |
164 | 167 |
165 off_t thfsize(th_ioctx *ctx) | 168 off_t thfsize(th_ioctx *ctx) |
166 { | 169 { |
167 ctx->atime = time(NULL); | 170 TH_UPDATE_ATIME; |
168 return ctx->fops->fsize(ctx); | 171 return ctx->fops->fsize(ctx); |
169 } | 172 } |
170 | 173 |
171 | 174 |
172 off_t thftell(th_ioctx *ctx) | 175 off_t thftell(th_ioctx *ctx) |
173 { | 176 { |
174 ctx->atime = time(NULL); | 177 TH_UPDATE_ATIME; |
175 return ctx->fops->ftell(ctx); | 178 return ctx->fops->ftell(ctx); |
176 } | 179 } |
177 | 180 |
178 | 181 |
179 BOOL thfeof(th_ioctx *ctx) | 182 BOOL thfeof(th_ioctx *ctx) |
180 { | 183 { |
181 ctx->atime = time(NULL); | 184 TH_UPDATE_ATIME; |
182 return ctx->fops->feof(ctx); | 185 return ctx->fops->feof(ctx); |
183 } | 186 } |
184 | 187 |
185 | 188 |
186 int thfgetc(th_ioctx *ctx) | 189 int thfgetc(th_ioctx *ctx) |
187 { | 190 { |
188 ctx->atime = time(NULL); | 191 TH_UPDATE_ATIME; |
189 return ctx->fops->fgetc(ctx); | 192 return ctx->fops->fgetc(ctx); |
190 } | 193 } |
191 | 194 |
192 | 195 |
193 int thfputc(int v, th_ioctx *ctx) | 196 int thfputc(int v, th_ioctx *ctx) |
194 { | 197 { |
195 ctx->atime = time(NULL); | 198 TH_UPDATE_ATIME; |
196 return ctx->fops->fputc(v, ctx); | 199 return ctx->fops->fputc(v, ctx); |
197 } | 200 } |
198 | 201 |
199 | 202 |
200 size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) | 203 size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) |
201 { | 204 { |
202 ctx->atime = time(NULL); | 205 TH_UPDATE_ATIME; |
203 return ctx->fops->fread(ptr, size, nmemb, ctx); | 206 return ctx->fops->fread(ptr, size, nmemb, ctx); |
204 } | 207 } |
205 | 208 |
206 | 209 |
207 size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) | 210 size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) |
208 { | 211 { |
209 ctx->atime = time(NULL); | 212 TH_UPDATE_ATIME; |
210 return ctx->fops->fwrite(ptr, size, nmemb, ctx); | 213 return ctx->fops->fwrite(ptr, size, nmemb, ctx); |
211 } | 214 } |
212 | 215 |
213 | 216 |
214 char *thfgets(char *str, int size, th_ioctx *ctx) | 217 char *thfgets(char *str, int size, th_ioctx *ctx) |