Page MenuHome

stat-fixes-11-24-2012-2.patch

stat-fixes-11-24-2012-2.patch

Index: source/blender/blenkernel/intern/anim.c
===================================================================
--- source/blender/blenkernel/intern/anim.c (revision 52516)
+++ source/blender/blenkernel/intern/anim.c (working copy)
@@ -32,6 +32,7 @@
#include <stdio.h>
#include <math.h>
#include <string.h>
+#include <stddef.h>
#include "MEM_guardedalloc.h"
Index: source/blender/blenkernel/intern/group.c
===================================================================
--- source/blender/blenkernel/intern/group.c (revision 52516)
+++ source/blender/blenkernel/intern/group.c (working copy)
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <string.h>
#include <math.h>
+#include <stddef.h>
#include "MEM_guardedalloc.h"
Index: source/blender/blenlib/BLI_fileops.h
===================================================================
--- source/blender/blenlib/BLI_fileops.h (revision 52516)
+++ source/blender/blenlib/BLI_fileops.h (working copy)
@@ -42,9 +42,17 @@
#include "BLI_fileops_types.h"
-/* for size_t (needed on windows) */
-#include <stddef.h>
+#ifdef WIN32
+typedef __int64 bli_off_t;
+#else
+typedef off_t bli_off_t;
+#endif
+/* this weirdo pops up in two places ... */
+#ifndef WIN32
+#define O_BINARY 0
+#endif
+
struct gzFile;
/* Common */
@@ -79,10 +87,10 @@
int BLI_file_touch(const char *file);
int BLI_file_gzip(const char *from, const char *to);
-char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r);
+char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r); /* assumes unzipped files are less than 2GiB */
-size_t BLI_file_descriptor_size(int file);
-size_t BLI_file_size(const char *file);
+bli_off_t BLI_file_descriptor_size(int file);
+bli_off_t BLI_file_size(const char *file);
/* compare if one was last modified before the other */
int BLI_file_older(const char *file1, const char *file2);
@@ -91,12 +99,7 @@
struct LinkNode *BLI_file_read_as_lines(const char *file);
void BLI_file_free_lines(struct LinkNode *lines);
-/* this weirdo pops up in two places ... */
-#if !defined(WIN32)
-# ifndef O_BINARY
-# define O_BINARY 0
-# endif
-#else
+#ifdef WIN32
void BLI_get_short_name(char short_name[256], const char *filename);
#endif
@@ -105,4 +108,3 @@
#endif
#endif
-
Index: source/blender/blenlib/BLI_fileops_types.h
===================================================================
--- source/blender/blenlib/BLI_fileops_types.h (revision 52516)
+++ source/blender/blenlib/BLI_fileops_types.h (working copy)
@@ -33,12 +33,29 @@
* \brief Some types for dealing with directories.
*/
+#include <sys/types.h>
#include <sys/stat.h>
-#if defined(WIN32) && !defined(FREE_WINDOWS)
+#ifdef WIN32
+
+#ifdef _MSC_VER
typedef unsigned int mode_t;
#endif
+# ifdef _USE_32BIT_TIME_T
+# error The _USE_32BIT_TIME_T option and BLI_fileops are not compatible.
+# endif
+
+/* Use stat, wstat, and fstat to make a small and consistent API for
+ all Windows build systems. _stati64 is used because it has 64-bit time and
+ file size, and is available in all versions of MSVCRT with 64-bit support */
+# define stat _stati64 /* use only as struct, never as function */
+# define wstat _wstati64 /* use only as function, takes UTF16 path */
+# define fstat _fstati64 /* use only as function, takes file descriptor */
+
+#endif
+
+
struct ImBuf;
struct direntry {
@@ -46,13 +63,7 @@
mode_t type;
char *relname;
char *path;
-#if (defined(WIN32) || defined(WIN64)) && !defined(__MINGW32__) && (_MSC_VER >= 1500)
- struct _stat64 s;
-#elif defined(__MINGW32__)
- struct _stati64 s;
-#else
- struct stat s;
-#endif
+ struct stat s;
unsigned int flags;
char size[16];
char mode1[4];
@@ -74,4 +85,3 @@
};
#endif /* __BLI_FILEOPS_TYPES_H__ */
-
Index: source/blender/blenlib/BLI_winstuff.h
===================================================================
--- source/blender/blenlib/BLI_winstuff.h (revision 52516)
+++ source/blender/blenlib/BLI_winstuff.h (working copy)
@@ -94,10 +94,6 @@
/* defines for using ISO C++ conformant names */
#define snprintf _snprintf
-#ifndef FREE_WINDOWS
-typedef unsigned int mode_t;
-#endif
-
/* use functions that take a 64 bit offset for files larger than 4GB */
#ifndef FREE_WINDOWS
# include <stdio.h>
Index: source/blender/blenlib/intern/bpath.c
===================================================================
--- source/blender/blenlib/intern/bpath.c (revision 52516)
+++ source/blender/blenlib/intern/bpath.c (working copy)
@@ -236,7 +236,7 @@
if (S_ISREG(status.st_mode)) { /* is file */
if (strncmp(filename, de->d_name, FILE_MAX) == 0) { /* name matches */
/* open the file to read its size */
- size = status.st_size;
+ size = (int)status.st_size; /* assumes files can't be bigger than 2GiB */
if ((size > 0) && (size > *filesize)) { /* find the biggest file */
*filesize = size;
BLI_strncpy(filename_new, path, FILE_MAX);
Index: source/blender/blenlib/intern/storage.c
===================================================================
--- source/blender/blenlib/intern/storage.c (revision 52516)
+++ source/blender/blenlib/intern/storage.c (working copy)
@@ -31,7 +31,6 @@
* \ingroup bli
*/
-
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
@@ -260,22 +259,7 @@
memset(&files[actnum], 0, sizeof(struct direntry));
files[actnum].relname = dlink->name;
files[actnum].path = BLI_strdupcat(dirname, dlink->name);
-// use 64 bit file size, only needed for WIN32 and WIN64.
-// Excluding other than current MSVC compiler until able to test
-#ifdef WIN32
- {
- wchar_t *name_16 = alloc_utf16_from_8(dlink->name, 0);
-#if (defined(WIN32) || defined(WIN64)) && (_MSC_VER >= 1500)
- _wstat64(name_16, &files[actnum].s);
-#elif defined(__MINGW32__)
- _stati64(dlink->name, &files[actnum].s);
-#endif
- free(name_16);
- }
-
-#else
- stat(dlink->name, &files[actnum].s);
-#endif
+ BLI_stat(dlink->name, &files[actnum].s);
files[actnum].type = files[actnum].s.st_mode;
files[actnum].flags = 0;
totnum++;
@@ -309,11 +293,7 @@
char size[250];
static const char *types[8] = {"---", "--x", "-w-", "-wx", "r--", "r-x", "rw-", "rwx"};
int num, mode;
-#ifdef WIN32
- __int64 st_size;
-#else
- off_t st_size;
-#endif
+ bli_off_t st_size;
struct direntry *file;
struct tm *tm;
@@ -441,74 +421,63 @@
}
-size_t BLI_file_descriptor_size(int file)
+bli_off_t BLI_file_descriptor_size(int file)
{
- struct stat buf;
-
- if (file <= 0) return (-1);
- fstat(file, &buf); /* CHANGE */
- return (buf.st_size);
+ struct stat st;
+ return ((file > 0) && (fstat(file, &st) == 0)) ? (st.st_size) : (-1);
}
-size_t BLI_file_size(const char *path)
+bli_off_t BLI_file_size(const char *path)
{
- int size, file = BLI_open(path, O_BINARY | O_RDONLY, 0);
-
+ bli_off_t size;
+
+ int file = BLI_open(path, O_BINARY | O_RDONLY, 0);
+
if (file == -1)
return -1;
-
+
size = BLI_file_descriptor_size(file);
+
close(file);
+
return size;
}
int BLI_exists(const char *name)
{
-#if defined(WIN32)
-#ifndef __MINGW32__
- struct _stat64i32 st;
-#else
- struct _stati64 st;
-#endif
- /* in Windows stat doesn't recognize dir ending on a slash
- * To not break code where the ending slash is expected we
- * don't mess with the argument name directly here - elubie */
- wchar_t *tmp_16 = alloc_utf16_from_8(name, 0);
- int len, res;
- len = wcslen(tmp_16);
- if (len > 3 && (tmp_16[len - 1] == L'\\' || tmp_16[len - 1] == L'/') ) tmp_16[len - 1] = '\0';
-#ifndef __MINGW32__
- res = _wstat(tmp_16, &st);
-#else
- res = _wstati64(tmp_16, &st);
-#endif
- free(tmp_16);
- if (res == -1) return(0);
-#else
struct stat st;
- if (stat(name, &st)) return(0);
-#endif
- return(st.st_mode);
+ return (BLI_stat(name, &st) == 0) ? (st.st_mode) : (0);
}
+int BLI_stat(const char *path, struct stat *st)
+{
#ifdef WIN32
-int BLI_stat(const char *path, struct stat *buffer)
-{
- int r;
+ int len, retval;
UTF16_ENCODE(path);
- r = _wstat(path_16, buffer);
+
+ /* _wstat doesn't recognize path ending with a slash */
+
+ len = wcslen(path_16);
+
+ if (len > 3 && (path_16[len - 1] == L'\\' || path_16[len - 1] == L'/'))
+ path_16[len - 1] = L'\0';
+
+ retval = wstat(path_16, st);
+
UTF16_UN_ENCODE(path);
- return r;
-}
+
+ /* if (retval == 0)
+ printf("stat: %s (%lu)\n", path, st->st_size); */
+
+ return retval;
#else
-int BLI_stat(const char *path, struct stat *buffer)
-{
- return stat(path, buffer);
+ return stat(path, st);
+#endif
}
-#endif
+
/* would be better in fileops.c except that it needs stat.h so add here */
int BLI_is_dir(const char *file)
{
@@ -570,23 +539,13 @@
/** is file1 older then file2 */
int BLI_file_older(const char *file1, const char *file2)
{
-#ifdef WIN32
- struct _stat st1, st2;
+ struct stat st1, st2;
- UTF16_ENCODE(file1);
- UTF16_ENCODE(file2);
-
- if (_wstat(file1_16, &st1)) return 0;
- if (_wstat(file2_16, &st2)) return 0;
+ if (BLI_stat(file1, &st1) != 0)
+ return 0;
- UTF16_UN_ENCODE(file2);
- UTF16_UN_ENCODE(file1);
-#else
- struct stat st1, st2;
+ if (BLI_stat(file2, &st2) != 0)
+ return 0;
- if (stat(file1, &st1)) return 0;
- if (stat(file2, &st2)) return 0;
-#endif
return (st1.st_mtime < st2.st_mtime);
}
-
Index: source/blender/blenloader/intern/runtime.c
===================================================================
--- source/blender/blenloader/intern/runtime.c (revision 52516)
+++ source/blender/blenloader/intern/runtime.c (working copy)
@@ -96,19 +96,24 @@
BlendFileData *BLO_read_runtime(const char *path, ReportList *reports)
{
- BlendFileData *bfd = NULL;
- size_t actualsize;
- int fd, datastart;
+ int actualsize;
+ int fd, datastart;
char buf[8];
fd = BLI_open(path, O_BINARY | O_RDONLY, 0);
if (fd == -1) {
BKE_reportf(reports, RPT_ERROR, "Unable to open '%s': %s", path, strerror(errno));
+ return NULL;
+ }
+
+ actualsize = (int)BLI_file_descriptor_size(fd); /* assumes file cannot be bigger than 2GiB */
+
+ if (actualsize == -1) {
+ BKE_reportf(reports, RPT_ERROR, "Unable to stat '%s': %s", path, strerror(errno));
goto cleanup;
}
-
- actualsize = BLI_file_descriptor_size(fd);
lseek(fd, -12, SEEK_END);
@@ -118,25 +123,24 @@
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (problem seeking)", path);
goto cleanup;
}
- else if (read(fd, buf, 8) != 8) {
+
+ if (read(fd, buf, 8) != 8) {
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (truncated header)", path);
goto cleanup;
}
- else if (memcmp(buf, "BRUNTIME", 8) != 0) {
+
+ if (memcmp(buf, "BRUNTIME", 8) != 0) {
BKE_reportf(reports, RPT_ERROR, "Unable to read '%s' (not a blend file)", path);
goto cleanup;
}
- else {
- //printf("starting to read runtime from %s at datastart %d\n", path, datastart);
- lseek(fd, datastart, SEEK_SET);
- bfd = blo_read_blendafterruntime(fd, path, actualsize - datastart, reports);
- fd = -1; // file was closed in blo_read_blendafterruntime()
- }
-
+
+ /* printf("starting to read runtime from %s at datastart %d\n", path, datastart); */
+ lseek(fd, datastart, SEEK_SET);
+ /* file will be closed in blo_read_blendafterruntime() */
+ return blo_read_blendafterruntime(fd, path, actualsize - datastart, reports);
+
cleanup:
- if (fd != -1)
- close(fd);
-
- return bfd;
+ close(fd);
+
+ return NULL;
}
-
Index: source/blender/editors/interface/resources.c
===================================================================
--- source/blender/editors/interface/resources.c (revision 52516)
+++ source/blender/editors/interface/resources.c (working copy)
@@ -32,6 +32,7 @@
#include <math.h>
#include <stdlib.h>
#include <string.h>
+#include <stddef.h>
#include "MEM_guardedalloc.h"
Index: source/blender/editors/render/render_preview.c
===================================================================
--- source/blender/editors/render/render_preview.c (revision 52516)
+++ source/blender/editors/render/render_preview.c (working copy)
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <math.h>
#include <string.h>
+#include <stddef.h>
#ifndef WIN32
#include <unistd.h>
Index: source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- source/blender/editors/sculpt_paint/paint_image.c (revision 52516)
+++ source/blender/editors/sculpt_paint/paint_image.c (working copy)
@@ -33,6 +33,7 @@
#include <string.h>
#include <stdio.h>
#include <math.h>
+#include <stddef.h>
#include "MEM_guardedalloc.h"
Index: source/blender/editors/space_outliner/outliner_draw.c
===================================================================
--- source/blender/editors/space_outliner/outliner_draw.c (revision 52516)
+++ source/blender/editors/space_outliner/outliner_draw.c (working copy)
@@ -29,6 +29,8 @@
* \ingroup spoutliner
*/
+#include <stddef.h>
+
#include "DNA_armature_types.h"
#include "DNA_group_types.h"
#include "DNA_lamp_types.h"
Index: source/blender/imbuf/intern/thumbs.c
===================================================================
--- source/blender/imbuf/intern/thumbs.c (revision 52516)
+++ source/blender/imbuf/intern/thumbs.c (working copy)
@@ -284,7 +284,7 @@
/* exception, skip images over 100mb */
if (source == THB_SOURCE_IMAGE) {
- const size_t size = BLI_file_size(path);
+ const bli_off_t size = BLI_file_size(path);
if (size != -1 && size > THUMB_SIZE_MAX) {
// printf("file too big: %d, skipping %s\n", (int)size, path);
return NULL;

File Metadata

Mime Type
text/x-diff
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
c0/05/3cbcfdf29bb87df459c885fdf1a1

Event Timeline