Skip to content

Commit

Permalink
Set MMapFile invalid when mmap failed.
Browse files Browse the repository at this point in the history
Print more info when failed to open EXR.
  • Loading branch information
syoyo committed Jun 4, 2023
1 parent 66f0aa1 commit 9211991
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
7 changes: 4 additions & 3 deletions test_tinyexr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
#include <vector>

// Uncomment if you want to use system provided zlib.
// #define TINYEXR_USE_MINIZ (0)
// #include <zlib.h>
//#define TINYEXR_USE_MINIZ (0)
//#include <zlib.h>

#define TINYEXR_IMPLEMENTATION
#include "tinyexr.h"
Expand Down Expand Up @@ -216,7 +216,7 @@ int test_main(int argc, char** argv) {

int ret = IsEXR(input_filename);
if (ret != TINYEXR_SUCCESS) {
fprintf(stderr, "Header err. code %d\n", ret);
fprintf(stderr, "File not found or given file is not a EXR format. code %d\n", ret);
exit(-1);
}

Expand All @@ -230,6 +230,7 @@ int test_main(int argc, char** argv) {
FreeEXRErrorMessage(err);
return ret;
}

// SaveAsPFM("output.pfm", width, height, image);
ret = SaveEXR(image, width, height, 4 /* =RGBA*/,
1 /* = save as fp16 format */, "output.exr", &err);
Expand Down
3 changes: 3 additions & 0 deletions tinyexr.h
Original file line number Diff line number Diff line change
Expand Up @@ -6737,6 +6737,7 @@ struct MemoryMappedFile {
data = reinterpret_cast<unsigned char *>(
mmap(0, size, PROT_READ, MAP_SHARED, posix_descriptor, 0));
if (data == MAP_FAILED) {
data = nullptr;
return;
}
#else
Expand All @@ -6761,11 +6762,13 @@ struct MemoryMappedFile {
size = static_cast<size_t>(ftell_result);
if (fseek(fp, 0, SEEK_SET) != 0) {
fclose(fp);
size = 0;
return;
}

data = reinterpret_cast<unsigned char *>(malloc(size));
if (!data) {
size = 0;
fclose(fp);
return;
}
Expand Down

0 comments on commit 9211991

Please sign in to comment.