summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLode <lvandeve@gmail.com>2015-09-12 23:56:15 +0200
committerLode <lvandeve@gmail.com>2015-09-12 23:56:15 +0200
commiteb16d900b2e82c01ba9d81b376e7fd7419edd15b (patch)
tree2cd6ba8fcfdfdf49615c186089568e2a585d5329
parent3d1b5d685fca913bcf56753f12c4b538da6878e8 (diff)
parent10a41cc1b0ffcac1686f4e1c89a2f6c9a567a8fc (diff)
Merge branch 'master' of https://github.com/lvandeve/lodepng
-rw-r--r--lodepng.cpp6
-rw-r--r--lodepng.h2
2 files changed, 5 insertions, 3 deletions
diff --git a/lodepng.cpp b/lodepng.cpp
index ee87d04..fbcecb5 100644
--- a/lodepng.cpp
+++ b/lodepng.cpp
@@ -5941,10 +5941,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 */
@@ -6130,7 +6132,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;
}
diff --git a/lodepng.h b/lodepng.h
index 59f0dda..0f87bc2 100644
--- a/lodepng.h
+++ b/lodepng.h
@@ -857,7 +857,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 */