1
0
mirror of https://github.com/anestisb/android-unpackbootimg.git synced 2024-05-16 16:49:31 +00:00

Check if output file could be opened, create directory if needed

This commit is contained in:
ValdikSS 2021-11-05 16:16:45 +03:00
parent c50df57f1b
commit 9972c07f79

View File

@ -31,12 +31,22 @@ int read_padding(FILE* f, unsigned itemsize, int pagesize)
return count;
}
void write_string_to_file(const char* file, const char* string)
int write_string_to_file(const char* file, const char* string)
{
// Try to create a directory first.
char* fcopy = strdup(file);
mkdir(dirname(fcopy), 0777);
free(fcopy);
FILE* f = fopen(file, "w");
if (!f) {
printf("File %s can't be opened.\n", file);
return 1;
}
fwrite(string, strlen(string), 1, f);
fwrite("\n", 1, 1, f);
fclose(f);
return 0;
}
const char *detect_hash_type(const struct boot_img_hdr *hdr)