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 15:42:05 +0300
committerCampbell Barton <ideasman42@gmail.com>2019-02-24 15:42:05 +0300
commit20dfa8aa2856a4cd35e76010dcd5023d4c7dbe82 (patch)
tree8e29b6d1366b95b08c8523aa325f8772103f17ff /source/blender/blenloader
parent6bab905c9d40a1cdddd15701cd3364534eae0a87 (diff)
readfile: minor changes to support other compression formats
Allow different readers to re-use the file descriptor.
Diffstat (limited to 'source/blender/blenloader')
-rw-r--r--source/blender/blenloader/intern/readfile.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 6fc96c88d2d..bb7ff4efaa5 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -1271,28 +1271,20 @@ static FileData *blo_decode_and_check(FileData *fd, ReportList *reports)
return fd;
}
-static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *reports)
+static FileData *blo_filedata_from_file_descriptor(const char *filepath, ReportList *reports, int file)
{
FileDataReadFn *read_fn = NULL;
FileDataSeekFn *seek_fn = NULL; /* Optional. */
- int file = -1;
gzFile gzfile = (gzFile)Z_NULL;
char header[7];
/* Regular file. */
errno = 0;
- file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
- if (file == -1) {
- BKE_reportf(reports, RPT_WARNING, "Unable to open '%s': %s",
- filepath, errno ? strerror(errno) : TIP_("unknown error reading file"));
- return NULL;
- }
- else if (read(file, header, sizeof(header)) != sizeof(header)) {
+ if (read(file, header, sizeof(header)) != sizeof(header)) {
BKE_reportf(reports, RPT_WARNING, "Unable to read '%s': %s",
filepath, errno ? strerror(errno) : TIP_("insufficient content"));
- close(file);
return NULL;
}
else {
@@ -1304,10 +1296,6 @@ static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *r
read_fn = fd_read_data_from_file;
seek_fn = fd_seek_data_from_file;
}
- else {
- close(file);
- file = -1;
- }
/* Gzip file. */
errno = 0;
@@ -1324,6 +1312,8 @@ static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *r
else {
/* 'seek_fn' is too slow for gzip, don't set it. */
read_fn = fd_read_gzip_from_file;
+ /* Caller must close. */
+ file = -1;
}
}
@@ -1343,6 +1333,22 @@ static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *r
return fd;
}
+static FileData *blo_filedata_from_file_open(const char *filepath, ReportList *reports)
+{
+ errno = 0;
+ const int file = BLI_open(filepath, O_BINARY | O_RDONLY, 0);
+ if (file == -1) {
+ BKE_reportf(reports, RPT_WARNING, "Unable to open '%s': %s",
+ filepath, errno ? strerror(errno) : TIP_("unknown error reading file"));
+ return NULL;
+ }
+ FileData *fd = blo_filedata_from_file_descriptor(filepath, reports, file);
+ if ((fd == NULL) || (fd->filedes == -1)) {
+ close(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)