ExUtilWriteFile() to write memory segment to file

Change-Id: I4a93358e55ba5527667e017e178009251f64560e
This commit is contained in:
Urvang Joshi 2012-11-07 14:41:15 -08:00
parent 74356eb558
commit e9a15a37cf
2 changed files with 22 additions and 0 deletions

View File

@ -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

View File

@ -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