diff options
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_fileops.h | 4 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_winstuff.h | 7 | ||||
-rw-r--r-- | source/blender/blenlib/intern/storage.c | 39 |
3 files changed, 37 insertions, 13 deletions
diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index d908c47b400..8596a60bc6a 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -70,6 +70,10 @@ typedef struct stat BLI_stat_t; int BLI_fstat(int fd, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); int BLI_stat(const char *path, BLI_stat_t *buffer) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int64_t BLI_ftell(FILE *stream) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); +int BLI_fseek(FILE *stream, int64_t offset, int whence); +int64_t BLI_lseek(int fd, int64_t offset, int whence); + #ifdef WIN32 int BLI_wstat(const wchar_t *path, BLI_stat_t *buffer); #endif diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index eddb69e84ec..08d29a328b4 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -80,13 +80,6 @@ extern "C" { typedef unsigned int mode_t; -/* use functions that take a 64 bit offset for files larger than 4GB */ -#include <stdio.h> -#define fseek(stream, offset, origin) _fseeki64(stream, offset, origin) -#define ftell(stream) _ftelli64(stream) -#define lseek(fd, offset, origin) _lseeki64(fd, offset, origin) -#define tell(fd) _telli64(fd) - #ifndef _SSIZE_T_ # define _SSIZE_T_ /* python uses HAVE_SSIZE_T */ diff --git a/source/blender/blenlib/intern/storage.c b/source/blender/blenlib/intern/storage.c index 7743ced1344..de16960eb85 100644 --- a/source/blender/blenlib/intern/storage.c +++ b/source/blender/blenlib/intern/storage.c @@ -175,6 +175,33 @@ double BLI_dir_free_space(const char *dir) #endif } +int64_t BLI_ftell(FILE *stream) +{ +#ifdef WIN32 + return _ftelli64(stream); +#else + return ftell(stream); +#endif +} + +int BLI_fseek(FILE *stream, int64_t offset, int whence) +{ +#ifdef WIN32 + return _fseeki64(stream, offset, whence); +#else + return fseek(stream, offset, whence); +#endif +} + +int64_t BLI_lseek(int fd, int64_t offset, int whence) +{ +#ifdef WIN32 + return _lseeki64(fd, offset, whence); +#else + return lseek(fd, offset, whence); +#endif +} + /** * Returns the file size of an opened file descriptor. */ @@ -383,15 +410,15 @@ static void *file_read_data_as_mem_impl(FILE *fp, if (S_ISDIR(st.st_mode)) { return NULL; } - if (fseek(fp, 0L, SEEK_END) == -1) { + if (BLI_fseek(fp, 0L, SEEK_END) == -1) { return NULL; } /* Don't use the 'st_size' because it may be the symlink. */ - const long int filelen = ftell(fp); + const long int filelen = BLI_ftell(fp); if (filelen == -1) { return NULL; } - if (fseek(fp, 0L, SEEK_SET) == -1) { + if (BLI_fseek(fp, 0L, SEEK_SET) == -1) { return NULL; } @@ -519,9 +546,9 @@ LinkNode *BLI_file_read_as_lines(const char *name) return NULL; } - fseek(fp, 0, SEEK_END); - size = (size_t)ftell(fp); - fseek(fp, 0, SEEK_SET); + BLI_fseek(fp, 0, SEEK_END); + size = (size_t)BLI_ftell(fp); + BLI_fseek(fp, 0, SEEK_SET); if (UNLIKELY(size == (size_t)-1)) { fclose(fp); |