diff options
author | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:10:42 +0300 |
---|---|---|
committer | Bastien Montagne <montagne29@wanadoo.fr> | 2015-06-29 18:10:42 +0300 |
commit | 58d6cbba6da31db8dc8a2b42d528b9a353081904 (patch) | |
tree | 04b57a2f809c6f08d84a082edf061f3ece631860 /source/blender/blenlib/intern/winstuff_dir.c | |
parent | 94549adec4b6857fb6ec4cf77606da51ff7c26b7 (diff) | |
parent | 295d0c52a26730edc6d4ed1276e4051cce006be5 (diff) |
Merge branch 'master' into temp-ghash-setopstemp-ghash-setops
Diffstat (limited to 'source/blender/blenlib/intern/winstuff_dir.c')
-rw-r--r-- | source/blender/blenlib/intern/winstuff_dir.c | 40 |
1 files changed, 28 insertions, 12 deletions
diff --git a/source/blender/blenlib/intern/winstuff_dir.c b/source/blender/blenlib/intern/winstuff_dir.c index b20da9ce959..bde0734a740 100644 --- a/source/blender/blenlib/intern/winstuff_dir.c +++ b/source/blender/blenlib/intern/winstuff_dir.c @@ -44,6 +44,22 @@ #include "BLI_utildefines.h" #include "utfconv.h" +#define PATH_SUFFIX "\\*" +#define PATH_SUFFIX_LEN 2 + +/* keep local to this file */ +struct __dirstream { + HANDLE handle; + WIN32_FIND_DATAW data; + char path[MAX_PATH + PATH_SUFFIX_LEN]; + long dd_loc; + long dd_size; + char dd_buf[4096]; + void *dd_direct; + + struct dirent direntry; +}; + /* Note: MinGW (FREE_WINDOWS) has opendir() and _wopendir(), and only the * latter accepts a path name of wchar_t type. Rather than messing up with * extra #ifdef's here and there, Blender's own implementations of opendir() @@ -54,25 +70,25 @@ DIR *opendir(const char *path) { wchar_t *path_16 = alloc_utf16_from_8(path, 0); + int path_len; + DIR *newd = NULL; - if (GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) { - DIR *newd = MEM_mallocN(sizeof(DIR), "opendir"); - + if ((GetFileAttributesW(path_16) & FILE_ATTRIBUTE_DIRECTORY) && + ((path_len = strlen(path)) < (sizeof(newd->path) - PATH_SUFFIX_LEN))) + { + newd = MEM_mallocN(sizeof(DIR), "opendir"); newd->handle = INVALID_HANDLE_VALUE; - sprintf(newd->path, "%s\\*", path); - + memcpy(newd->path, path, path_len); + memcpy(newd->path + path_len, PATH_SUFFIX, PATH_SUFFIX_LEN + 1); + newd->direntry.d_ino = 0; newd->direntry.d_off = 0; newd->direntry.d_reclen = 0; newd->direntry.d_name = NULL; - - free(path_16); - return newd; - } - else { - free(path_16); - return NULL; } + + free(path_16); + return newd; } static char *BLI_alloc_utf_8_from_16(wchar_t *in16, size_t add) |