mirror of
https://github.com/bluekitchen/btstack.git
synced 2025-01-07 19:01:06 +00:00
posix: check if file was opened successfully
This commit is contained in:
parent
bec5f683aa
commit
8300a979e2
@ -148,6 +148,10 @@ static void put_link_key(bd_addr_t bd_addr, link_key_t link_key, link_key_type_t
|
|||||||
char * link_key_type_str = link_key_type_to_str(link_key_type);
|
char * link_key_type_str = link_key_type_to_str(link_key_type);
|
||||||
|
|
||||||
FILE * wFile = fopen(keypath,"w+");
|
FILE * wFile = fopen(keypath,"w+");
|
||||||
|
if (wFile == NULL){
|
||||||
|
log_error("failed to create file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
fwrite(link_key_str, strlen(link_key_str), 1, wFile);
|
fwrite(link_key_str, strlen(link_key_str), 1, wFile);
|
||||||
fwrite(link_key_type_str, strlen(link_key_type_str), 1, wFile);
|
fwrite(link_key_type_str, strlen(link_key_type_str), 1, wFile);
|
||||||
fclose(wFile);
|
fclose(wFile);
|
||||||
@ -160,6 +164,7 @@ static int read_link_key(const char * path, link_key_t link_key, link_key_type_t
|
|||||||
char link_key_type_str[2];
|
char link_key_type_str[2];
|
||||||
|
|
||||||
FILE * rFile = fopen(path,"r+");
|
FILE * rFile = fopen(path,"r+");
|
||||||
|
if (rFile == NULL) return 0;
|
||||||
size_t objects_read = fread(link_key_str, LINK_KEY_STR_LEN, 1, rFile );
|
size_t objects_read = fread(link_key_str, LINK_KEY_STR_LEN, 1, rFile );
|
||||||
if (objects_read == 1){
|
if (objects_read == 1){
|
||||||
link_key_str[LINK_KEY_STR_LEN] = 0;
|
link_key_str[LINK_KEY_STR_LEN] = 0;
|
||||||
|
@ -232,6 +232,10 @@ static int btstack_tlv_posix_read_db(btstack_tlv_posix_t * self){
|
|||||||
if (!self->file){
|
if (!self->file){
|
||||||
// create truncate file
|
// create truncate file
|
||||||
self->file = fopen(self->db_path,"w+");
|
self->file = fopen(self->db_path,"w+");
|
||||||
|
if (!self->file) {
|
||||||
|
log_error("failed to create file");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
memset(header, 0, sizeof(header));
|
memset(header, 0, sizeof(header));
|
||||||
strcpy((char *)header, btstack_tlv_header_magic);
|
strcpy((char *)header, btstack_tlv_header_magic);
|
||||||
fwrite(header, 1, sizeof(header), self->file);
|
fwrite(header, 1, sizeof(header), self->file);
|
||||||
|
Loading…
Reference in New Issue
Block a user