|
18 | 18 | #define GGUF_MAX_STRING_LENGTH (1024*1024*1024) |
19 | 19 | #define GGUF_MAX_ARRAY_ELEMENTS (1024*1024*1024) |
20 | 20 |
|
| 21 | +#ifdef _WIN32 |
| 22 | +# define gguf_ftell _ftelli64 |
| 23 | +# define gguf_fseek _fseeki64 |
| 24 | +#else |
| 25 | +# define gguf_ftell ftello |
| 26 | +# define gguf_fseek fseeko |
| 27 | +#endif |
| 28 | + |
21 | 29 | template <typename T> |
22 | 30 | struct type_to_gguf_type; |
23 | 31 |
|
@@ -319,22 +327,22 @@ struct gguf_reader { |
319 | 327 |
|
320 | 328 | // remaining bytes in the file |
321 | 329 | uint64_t nbytes_remain() const { |
322 | | - const long cur = ftell(file); |
| 330 | + const int64_t cur = gguf_ftell(file); |
323 | 331 | if (cur < 0) { |
324 | 332 | return 0; |
325 | 333 | } |
326 | | - if (fseek(file, 0, SEEK_END) != 0) { |
327 | | - fseek(file, cur, SEEK_SET); |
| 334 | + if (gguf_fseek(file, 0, SEEK_END) != 0) { |
| 335 | + gguf_fseek(file, cur, SEEK_SET); |
328 | 336 |
|
329 | 337 | return 0; |
330 | 338 | } |
331 | | - const long end = ftell(file); |
| 339 | + const int64_t end = gguf_ftell(file); |
332 | 340 | if (end < 0) { |
333 | | - fseek(file, cur, SEEK_SET); |
| 341 | + gguf_fseek(file, cur, SEEK_SET); |
334 | 342 |
|
335 | 343 | return 0; |
336 | 344 | } |
337 | | - fseek(file, cur, SEEK_SET); |
| 345 | + gguf_fseek(file, cur, SEEK_SET); |
338 | 346 | return static_cast<uint64_t>(end - cur); |
339 | 347 | } |
340 | 348 | }; |
@@ -671,14 +679,14 @@ struct gguf_context * gguf_init_from_file_impl(FILE * file, struct gguf_init_par |
671 | 679 | GGML_ASSERT(int64_t(ctx->info.size()) == n_tensors); |
672 | 680 |
|
673 | 681 | // we require the data section to be aligned, so take into account any padding |
674 | | - if (fseek(file, GGML_PAD(ftell(file), ctx->alignment), SEEK_SET) != 0) { |
| 682 | + if (gguf_fseek(file, GGML_PAD(gguf_ftell(file), ctx->alignment), SEEK_SET) != 0) { |
675 | 683 | GGML_LOG_ERROR("%s: failed to seek to beginning of data section\n", __func__); |
676 | 684 | gguf_free(ctx); |
677 | 685 | return nullptr; |
678 | 686 | } |
679 | 687 |
|
680 | 688 | // store the current file offset - this is where the data section starts |
681 | | - ctx->offset = ftell(file); |
| 689 | + ctx->offset = gguf_ftell(file); |
682 | 690 |
|
683 | 691 | // compute the total size of the data section, taking into account the alignment |
684 | 692 | { |
|
0 commit comments