diff options
author | Lode Vandevenne <lvandeve@users.noreply.github.com> | 2015-09-12 23:15:13 +0200 |
---|---|---|
committer | Lode Vandevenne <lvandeve@users.noreply.github.com> | 2015-09-12 23:15:13 +0200 |
commit | 10a41cc1b0ffcac1686f4e1c89a2f6c9a567a8fc (patch) | |
tree | f17041a5dcf9464e0473919bca635c9dd4a4e8df | |
parent | 0bceffb6eca66fe405c59f5c58c6ef2ff1be4add (diff) | |
parent | 4db007c3b1b8f793efecd4b4ac046147ee0d2485 (diff) |
Merge pull request #14 from cosinekitty/savefile-return-code
encode() returns error code if save_file() cannot open output file.
-rw-r--r-- | lodepng.cpp | 6 | ||||
-rw-r--r-- | lodepng.h | 2 |
2 files changed, 5 insertions, 3 deletions
diff --git a/lodepng.cpp b/lodepng.cpp index 326b952..f2a7b23 100644 --- a/lodepng.cpp +++ b/lodepng.cpp @@ -5938,10 +5938,12 @@ void load_file(std::vector<unsigned char>& buffer, const std::string& filename) } /*write given buffer to the file, overwriting the file, it doesn't append to it.*/ -void save_file(const std::vector<unsigned char>& buffer, const std::string& filename) +unsigned save_file(const std::vector<unsigned char>& buffer, const std::string& filename) { std::ofstream file(filename.c_str(), std::ios::out|std::ios::binary); + if(!file) return 79; file.write(buffer.empty() ? 0 : (char*)&buffer[0], std::streamsize(buffer.size())); + return 0; } #endif /* LODEPNG_COMPILE_DISK */ @@ -6127,7 +6129,7 @@ unsigned encode(const std::string& filename, { std::vector<unsigned char> buffer; unsigned error = encode(buffer, in, w, h, colortype, bitdepth); - if(!error) save_file(buffer, filename); + if(!error) error = save_file(buffer, filename); return error; } @@ -855,7 +855,7 @@ void load_file(std::vector<unsigned char>& buffer, const std::string& filename); Save the binary data in an std::vector to a file on disk. The file is overwritten without warning. */ -void save_file(const std::vector<unsigned char>& buffer, const std::string& filename); +unsigned save_file(const std::vector<unsigned char>& buffer, const std::string& filename); #endif /* LODEPNG_COMPILE_DISK */ #endif /* LODEPNG_COMPILE_PNG */ |