Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRay Molenkamp <github@lazydodo.com>2020-03-18 21:13:03 +0300
committerRay Molenkamp <github@lazydodo.com>2020-03-18 21:13:03 +0300
commit9a116c7c2d957e0e10a926eccc38dcb28cfec6e4 (patch)
tree620a9efd22d96e6fce9ec8cf8f1c6c0c2996b687 /source/blender/blenlib/intern/storage.c
parentac74a843d2775c834454ede9e3161e574f5b2e7c (diff)
Cleanup: 64 bit file IO on windows.
Unlike Linux where fseek/tell will be either 32 or 64 bit depending on the target platform, it will always be 32 bit on windows. We had some macro magic in BLI_winstuff.h that substituted them for 64 bit versions, but that is upsetting the system headers if they get included after BLI_winstuff.h which is problematic for D6811. This diff adds proper functions in blenlib and updates all calls that were using the BLI_winstuff.h header to gain 64 bit file IO. note: Anything that was using the 32 bit versions (ie not including BLI_winstuff.h) will still be using the 32 bit versions, which is perhaps a good code quality Friday project. Differential Revision: https://developer.blender.org/D7160 Reviewers: brecht dfelinto
Diffstat (limited to 'source/blender/blenlib/intern/storage.c')
-rw-r--r--source/blender/blenlib/intern/storage.c39
1 files changed, 33 insertions, 6 deletions
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);