Mercurial > hg > dmlib
comparison src/dmres.c @ 1106:f8e9f6b2a41a
Hmm .. back out the Sint64 changes for now.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 04 Mar 2015 00:40:15 +0200 |
parents | fd1ccfc62ceb |
children | 043b5942fdb6 |
comparison
equal
deleted
inserted
replaced
1105:62ccecea1317 | 1106:f8e9f6b2a41a |
---|---|
170 { | 170 { |
171 return f->error; | 171 return f->error; |
172 } | 172 } |
173 | 173 |
174 | 174 |
175 static Sint64 dm_stdio_ftell(DMResource * f) | 175 static off_t dm_stdio_ftell(DMResource * f) |
176 { | 176 { |
177 return DM_FTELL64(f->fh); | 177 return ftello(f->fh); |
178 } | 178 } |
179 | 179 |
180 | 180 |
181 static int dm_stdio_fseek(DMResource *f, const Sint64 pos, const int whence) | 181 static int dm_stdio_fseek(DMResource *f, const off_t pos, const int whence) |
182 { | 182 { |
183 int ret = DM_FSEEK64(f->fh, pos, whence); | 183 int ret = fseeko(f->fh, pos, whence); |
184 f->error = dmGetErrno(); | 184 f->error = dmGetErrno(); |
185 return ret; | 185 return ret; |
186 } | 186 } |
187 | 187 |
188 | 188 |
202 // Check if the size is cached | 202 // Check if the size is cached |
203 if (f->rawSize != 0) | 203 if (f->rawSize != 0) |
204 return f->rawSize; | 204 return f->rawSize; |
205 | 205 |
206 // Get file size | 206 // Get file size |
207 savePos = dm_stdio_ftell(f); | 207 if ((savePos = dm_stdio_ftell(f)) < 0) |
208 return -1; | |
209 | |
208 if (dm_stdio_fseek(f, 0, SEEK_END) != 0) | 210 if (dm_stdio_fseek(f, 0, SEEK_END) != 0) |
209 return -1; | 211 return -1; |
210 | 212 |
211 fileSize = dm_stdio_ftell(f); | 213 if ((fileSize = dm_stdio_ftell(f)) < 0) |
214 return -1; | |
215 | |
212 if (dm_stdio_fseek(f, savePos, SEEK_SET) != 0) | 216 if (dm_stdio_fseek(f, savePos, SEEK_SET) != 0) |
213 return -1; | 217 return -1; |
214 | 218 |
215 f->rawSize = fileSize; | 219 f->rawSize = fileSize; |
216 return fileSize; | 220 return fileSize; |
447 handle->filename); | 451 handle->filename); |
448 goto out; | 452 goto out; |
449 } | 453 } |
450 | 454 |
451 // Seek to entry | 455 // Seek to entry |
452 if (DM_FSEEK64(handle->lib->packFile->file, node->offset, SEEK_SET) != 0) | 456 if (fseeko(handle->lib->packFile->file, node->offset, SEEK_SET) != 0) |
453 { | 457 { |
454 ret = dmErrorDBG(DMERR_FSEEK, | 458 ret = dmErrorDBG(DMERR_FSEEK, |
455 "Could not seek node position in PACK file.\n"); | 459 "Could not seek node position in PACK file.\n"); |
456 goto out; | 460 goto out; |
457 } | 461 } |
535 { | 539 { |
536 return f->error; | 540 return f->error; |
537 } | 541 } |
538 | 542 |
539 | 543 |
540 static int dm_mem_fseek(DMResource * f, const Sint64 offset, const int whence) | 544 static int dm_mem_fseek(DMResource * f, const off_t offset, const int whence) |
541 { | 545 { |
542 off_t newPos; | 546 off_t newPos; |
543 | 547 |
544 // Calculate the new position | 548 // Calculate the new position |
545 switch (whence) | 549 switch (whence) |
575 { | 579 { |
576 return f->rawSize; | 580 return f->rawSize; |
577 } | 581 } |
578 | 582 |
579 | 583 |
580 static Sint64 dm_mem_ftell(DMResource * f) | 584 static off_t dm_mem_ftell(DMResource * f) |
581 { | 585 { |
582 return f->rawOffset; | 586 return f->rawOffset; |
583 } | 587 } |
584 | 588 |
585 | 589 |
884 { | 888 { |
885 f->atime = time(NULL); | 889 f->atime = time(NULL); |
886 return f->fops->ferror(f); | 890 return f->fops->ferror(f); |
887 } | 891 } |
888 | 892 |
889 int dmfseek(DMResource * f, Sint64 offset, int whence) | 893 int dmfseek(DMResource * f, const off_t offset, int whence) |
890 { | 894 { |
891 f->atime = time(NULL); | 895 f->atime = time(NULL); |
892 return f->fops->fseek(f, offset, whence); | 896 return f->fops->fseek(f, offset, whence); |
893 } | 897 } |
894 | 898 |