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:
authorCampbell Barton <ideasman42@gmail.com>2019-02-24 02:46:26 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-24 02:48:36 +0300
commit519982fd3ea0ab240029db5b095bbc31c6d0cb05 (patch)
treea5ac7472cb03bfe1046506b3535acf5dc29d440a /source/blender/blenloader
parent2f8d8b5e5e4b851258a369c0226e3eca49ab5b2c (diff)
Cleanup: de-duplicate readfile file opening
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readfile.c42
1 files changed, 19 insertions, 23 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index ca36deeaa80..df12a4f4321 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1248,30 +1248,36 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
return fd;
}
-/* cannot be called with relative paths anymore! */
-/* on each new library added, it now checks for the current FileData and expands relativeness */
-FileData *blo_filedata_from_file(const char *filepath, ReportList *reports)
+static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *reports)
{
- gzFile gzfile;
errno = 0;
- gzfile = BLI_gzopen(filepath, "rb");
-
+ gzFile gzfile = BLI_gzopen(filepath, "rb");
if (gzfile == (gzFile)Z_NULL) {
BKE_reportf(reports, RPT_WARNING, "Unable to open '%s': %s",
filepath, errno ? strerror(errno) : TIP_("unknown error reading file"));
return NULL;
}
- else {
- FileData *fd = filedata_new();
- fd->gzfiledes = gzfile;
- fd->read = fd_read_gzip_from_file;
- fd->seek = fd_seek_gzip_from_file;
+ FileData *fd = filedata_new();
+ fd->gzfiledes = gzfile;
+ fd->read = fd_read_gzip_from_file;
+ fd->seek = fd_seek_gzip_from_file;
+
+ return fd;
+}
+
+/* cannot be called with relative paths anymore! */
+/* on each new library added, it now checks for the current FileData and expands relativeness */
+FileData *blo_filedata_from_file(const char *filepath, ReportList *reports)
+{
+ FileData *fd = blo_filedata_from_file_open(filepath, reports);
+ if (fd != NULL) {
/* needed for library_append and read_libraries */
BLI_strncpy(fd->relabase, filepath, sizeof(fd->relabase));
return blo_decode_and_check(fd, reports);
}
+ return NULL;
}
/**
@@ -1280,24 +1286,14 @@ FileData *blo_filedata_from_file(const char *filepath, ReportList *reports)
*/
static FileData *blo_filedata_from_file_minimal(const char *filepath)
{
- gzFile gzfile;
- errno = 0;
- gzfile = BLI_gzopen(filepath, "rb");
-
- if (gzfile != (gzFile)Z_NULL) {
- FileData *fd = filedata_new();
- fd->gzfiledes = gzfile;
- fd->read = fd_read_gzip_from_file;
-
+ FileData *fd = blo_filedata_from_file_open(filepath, NULL);
+ if (fd != NULL) {
decode_blender_header(fd);
-
if (fd->flags & FD_FLAGS_FILE_OK) {
return fd;
}
-
blo_filedata_free(fd);
}
-
return NULL;
}