diff --git a/examples/example_util.c b/examples/example_util.c index 65655fd0..4cd2ce07 100644 --- a/examples/example_util.c +++ b/examples/example_util.c @@ -54,6 +54,24 @@ int ExUtilReadFile(const char* const file_name, return 1; } +int ExUtilWriteFile(const char* const file_name, + const uint8_t* data, size_t data_size) { + int ok; + FILE* out; + + if (file_name == NULL || data == NULL) { + return 0; + } + out = fopen(file_name, "wb"); + if (out == NULL) { + fprintf(stderr, "Error! Cannot open output file '%s'\n", file_name); + return 0; + } + ok = (fwrite(data, data_size, 1, out) == 1); + fclose(out); + return ok; +} + #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" #endif diff --git a/examples/example_util.h b/examples/example_util.h index 54d1ebe2..7b30dbe1 100644 --- a/examples/example_util.h +++ b/examples/example_util.h @@ -23,6 +23,10 @@ extern "C" { int ExUtilReadFile(const char* const file_name, const uint8_t** data, size_t* data_size); +// Write a data segment into a file named 'file_name'. Returns true if ok. +int ExUtilWriteFile(const char* const file_name, + const uint8_t* data, size_t data_size); + #if defined(__cplusplus) || defined(c_plusplus) } // extern "C" #endif