diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-03-13 23:48:07 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2013-03-13 23:48:07 +0400 |
commit | dcbfa25bc8903fbffb563c6e0f5c89d94ea27ed3 (patch) | |
tree | dd5944eb1da4ac16d7a1c54de9c7ee39054e4f8b | |
parent | 962865d19f4bd8639ac6c2064a3c82e5674e7802 (diff) |
Fix #34551: blender crash rendering with save buffers.
Problem was the new usage of access() on Windows, this doesn't accept X_OK. Also wrapped _waccess so that UTF-8 paths work.
-rw-r--r-- | intern/utfconv/utf_winfunc.c | 14 | ||||
-rw-r--r-- | intern/utfconv/utf_winfunc.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_fileops.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/BLI_winstuff.h | 3 | ||||
-rw-r--r-- | source/blender/blenlib/intern/fileops.c | 20 |
5 files changed, 36 insertions, 3 deletions
diff --git a/intern/utfconv/utf_winfunc.c b/intern/utfconv/utf_winfunc.c index 74e57894ccf..3d7fb11309a 100644 --- a/intern/utfconv/utf_winfunc.c +++ b/intern/utfconv/utf_winfunc.c @@ -75,6 +75,20 @@ int uopen(const char *filename, int oflag, int pmode) return f; } +int uaccess(const char *filename, int mode) +{ + int r = -1; + UTF16_ENCODE(filename); + + if (filename_16) { + r = _waccess(filename_16, mode); + } + + UTF16_UN_ENCODE(filename); + + return r; +} + int urename(const char *oldname, const char *newname ) { int r = -1; diff --git a/intern/utfconv/utf_winfunc.h b/intern/utfconv/utf_winfunc.h index e92e7953cfc..45f6844af5a 100644 --- a/intern/utfconv/utf_winfunc.h +++ b/intern/utfconv/utf_winfunc.h @@ -32,6 +32,7 @@ FILE * ufopen(const char * filename, const char * mode); int uopen(const char *filename, int oflag, int pmode); +int uaccess(const char *filename, int mode); int urename(const char *oldname, const char *newname ); char * u_alloc_getenv(const char *varname); diff --git a/source/blender/blenlib/BLI_fileops.h b/source/blender/blenlib/BLI_fileops.h index 217afb1ca21..b0e3f47b627 100644 --- a/source/blender/blenlib/BLI_fileops.h +++ b/source/blender/blenlib/BLI_fileops.h @@ -73,6 +73,7 @@ void BLI_free_filelist(struct direntry * filelist, unsigned int nrentries); FILE *BLI_fopen(const char *filename, const char *mode); void *BLI_gzopen(const char *filename, const char *mode); int BLI_open(const char *filename, int oflag, int pmode); +int BLI_access(const char *filename, int mode); bool BLI_file_is_writable(const char *file); bool BLI_file_touch(const char *file); diff --git a/source/blender/blenlib/BLI_winstuff.h b/source/blender/blenlib/BLI_winstuff.h index fe538fcb42a..20a4c3c274e 100644 --- a/source/blender/blenlib/BLI_winstuff.h +++ b/source/blender/blenlib/BLI_winstuff.h @@ -97,7 +97,8 @@ extern "C" { #ifdef _MSC_VER # define R_OK 4 # define W_OK 2 -# define X_OK 1 +// not accepted by access() on windows +//# define X_OK 1 # define F_OK 0 # define PATH_MAX 4096 #endif diff --git a/source/blender/blenlib/intern/fileops.c b/source/blender/blenlib/intern/fileops.c index bda67e2eb74..29280c36222 100644 --- a/source/blender/blenlib/intern/fileops.c +++ b/source/blender/blenlib/intern/fileops.c @@ -167,7 +167,7 @@ char *BLI_file_ungzip_to_mem(const char *from_file, int *size_r) bool BLI_file_is_writable(const char *filename) { bool writable; - if (access(filename, W_OK) == 0) { + if (BLI_access(filename, W_OK) == 0) { /* file exists and I can write to it */ writable = true; } @@ -179,7 +179,12 @@ bool BLI_file_is_writable(const char *filename) /* file doesn't exist -- check I can create it in parent directory */ char parent[FILE_MAX]; BLI_split_dirfile(filename, parent, NULL, sizeof(parent), 0); - writable = access(parent, X_OK | W_OK) == 0; +#ifdef WIN32 + /* windows does not have X_OK */ + writable = BLI_access(parent, W_OK) == 0; +#else + writable = BLI_access(parent, X_OK | W_OK) == 0; +#endif } return writable; } @@ -258,6 +263,11 @@ int BLI_open(const char *filename, int oflag, int pmode) return uopen(filename, oflag, pmode); } +int BLI_access(const char *filename, int mode) +{ + return uaccess(filename, mode); +} + int BLI_delete(const char *file, bool dir, bool recursive) { int err; @@ -597,6 +607,12 @@ int BLI_open(const char *filename, int oflag, int pmode) return open(filename, oflag, pmode); } +int BLI_access(const char *filename, int mode) +{ + return access(filename, mode); +} + + /** * Deletes the specified file or directory (depending on dir), optionally * doing recursive delete of directory contents. |