mirror of
https://github.com/flipperdevices/flipperzero-firmware.git
synced 2025-12-13 13:29:50 +04:00
Api Symbols: replace asserts with checks (#3507)
* Api Symbols: replace asserts with checks * Api Symbols: replace asserts with checks part 2 * Update no args function signatures with void, to help compiler to track incorrect usage * More unavoidable void * Update PVS config and code to make it happy * Format sources * nfc: fix checks * dead code cleanup & include fixes Co-authored-by: gornekich <n.gorbadey@gmail.com> Co-authored-by: hedger <hedger@users.noreply.github.com> Co-authored-by: hedger <hedger@nanode.su>
This commit is contained in:
@@ -16,8 +16,9 @@
|
||||
#define S_API_PROLOGUE FuriApiLock lock = api_lock_alloc_locked();
|
||||
|
||||
#define S_FILE_API_PROLOGUE \
|
||||
furi_check(file); \
|
||||
Storage* storage = file->storage; \
|
||||
furi_assert(storage);
|
||||
furi_check(storage);
|
||||
|
||||
#define S_API_EPILOGUE \
|
||||
furi_check( \
|
||||
@@ -92,6 +93,8 @@ bool storage_file_open(
|
||||
const char* path,
|
||||
FS_AccessMode access_mode,
|
||||
FS_OpenMode open_mode) {
|
||||
furi_check(file);
|
||||
|
||||
bool result;
|
||||
FuriEventFlag* event = furi_event_flag_alloc();
|
||||
FuriPubSubSubscription* subscription = furi_pubsub_subscribe(
|
||||
@@ -198,6 +201,8 @@ size_t storage_file_read(File* file, void* buff, size_t to_read) {
|
||||
}
|
||||
|
||||
size_t storage_file_write(File* file, const void* buff, size_t to_write) {
|
||||
furi_check(file);
|
||||
|
||||
size_t total = 0;
|
||||
|
||||
const size_t max_chunk = UINT16_MAX;
|
||||
@@ -276,6 +281,8 @@ bool storage_file_eof(File* file) {
|
||||
}
|
||||
|
||||
bool storage_file_exists(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
bool exist = false;
|
||||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(storage, path, &fileinfo);
|
||||
@@ -288,6 +295,9 @@ bool storage_file_exists(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
bool storage_file_copy_to_file(File* source, File* destination, size_t size) {
|
||||
furi_check(source);
|
||||
furi_check(destination);
|
||||
|
||||
uint8_t* buffer = malloc(FILE_BUFFER_SIZE);
|
||||
|
||||
while(size) {
|
||||
@@ -328,6 +338,8 @@ static bool storage_dir_open_internal(File* file, const char* path) {
|
||||
}
|
||||
|
||||
bool storage_dir_open(File* file, const char* path) {
|
||||
furi_check(file);
|
||||
|
||||
bool result;
|
||||
FuriEventFlag* event = furi_event_flag_alloc();
|
||||
FuriPubSubSubscription* subscription = furi_pubsub_subscribe(
|
||||
@@ -402,6 +414,8 @@ bool storage_dir_rewind(File* file) {
|
||||
}
|
||||
|
||||
bool storage_dir_exists(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
bool exist = false;
|
||||
FileInfo fileinfo;
|
||||
FS_Error error = storage_common_stat(storage, path, &fileinfo);
|
||||
@@ -415,6 +429,7 @@ bool storage_dir_exists(Storage* storage, const char* path) {
|
||||
/****************** COMMON ******************/
|
||||
|
||||
FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t* timestamp) {
|
||||
furi_check(storage);
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {
|
||||
@@ -430,6 +445,8 @@ FS_Error storage_common_timestamp(Storage* storage, const char* path, uint32_t*
|
||||
}
|
||||
|
||||
FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* fileinfo) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
.cstat = {
|
||||
@@ -444,6 +461,8 @@ FS_Error storage_common_stat(Storage* storage, const char* path, FileInfo* filei
|
||||
}
|
||||
|
||||
FS_Error storage_common_remove(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
.path = {
|
||||
@@ -457,6 +476,7 @@ FS_Error storage_common_remove(Storage* storage, const char* path) {
|
||||
}
|
||||
|
||||
FS_Error storage_common_rename(Storage* storage, const char* old_path, const char* new_path) {
|
||||
furi_check(storage);
|
||||
FS_Error error;
|
||||
|
||||
do {
|
||||
@@ -557,6 +577,8 @@ static FS_Error
|
||||
}
|
||||
|
||||
FS_Error storage_common_copy(Storage* storage, const char* old_path, const char* new_path) {
|
||||
furi_check(storage);
|
||||
|
||||
FS_Error error;
|
||||
|
||||
FileInfo fileinfo;
|
||||
@@ -650,6 +672,8 @@ static FS_Error
|
||||
}
|
||||
|
||||
FS_Error storage_common_merge(Storage* storage, const char* old_path, const char* new_path) {
|
||||
furi_check(storage);
|
||||
|
||||
FS_Error error;
|
||||
const char* new_path_tmp = NULL;
|
||||
FuriString* new_path_next = NULL;
|
||||
@@ -718,6 +742,8 @@ FS_Error storage_common_merge(Storage* storage, const char* old_path, const char
|
||||
}
|
||||
|
||||
FS_Error storage_common_mkdir(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
.path = {
|
||||
@@ -735,6 +761,8 @@ FS_Error storage_common_fs_info(
|
||||
const char* fs_path,
|
||||
uint64_t* total_space,
|
||||
uint64_t* free_space) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {
|
||||
@@ -751,6 +779,8 @@ FS_Error storage_common_fs_info(
|
||||
}
|
||||
|
||||
void storage_common_resolve_path_and_ensure_app_directory(Storage* storage, FuriString* path) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {
|
||||
@@ -764,6 +794,8 @@ void storage_common_resolve_path_and_ensure_app_directory(Storage* storage, Furi
|
||||
}
|
||||
|
||||
FS_Error storage_common_migrate(Storage* storage, const char* source, const char* dest) {
|
||||
furi_check(storage);
|
||||
|
||||
if(!storage_common_exists(storage, source)) {
|
||||
return FSE_OK;
|
||||
}
|
||||
@@ -778,6 +810,8 @@ FS_Error storage_common_migrate(Storage* storage, const char* source, const char
|
||||
}
|
||||
|
||||
bool storage_common_exists(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
FileInfo file_info;
|
||||
return storage_common_stat(storage, path, &file_info) == FSE_OK;
|
||||
}
|
||||
@@ -787,6 +821,8 @@ bool storage_common_equivalent_path(
|
||||
const char* path1,
|
||||
const char* path2,
|
||||
bool truncate) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
|
||||
SAData data = {
|
||||
@@ -810,23 +846,25 @@ const char* storage_error_get_desc(FS_Error error_id) {
|
||||
}
|
||||
|
||||
FS_Error storage_file_get_error(File* file) {
|
||||
furi_check(file != NULL);
|
||||
furi_check(file);
|
||||
return file->error_id;
|
||||
}
|
||||
|
||||
int32_t storage_file_get_internal_error(File* file) {
|
||||
furi_check(file != NULL);
|
||||
furi_check(file);
|
||||
return file->internal_error_id;
|
||||
}
|
||||
|
||||
const char* storage_file_get_error_desc(File* file) {
|
||||
furi_check(file != NULL);
|
||||
furi_check(file);
|
||||
return filesystem_api_error_get_desc(file->error_id);
|
||||
}
|
||||
|
||||
/****************** Raw SD API ******************/
|
||||
|
||||
FS_Error storage_sd_format(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDFormat);
|
||||
@@ -835,6 +873,8 @@ FS_Error storage_sd_format(Storage* storage) {
|
||||
}
|
||||
|
||||
FS_Error storage_sd_unmount(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDUnmount);
|
||||
@@ -843,6 +883,8 @@ FS_Error storage_sd_unmount(Storage* storage) {
|
||||
}
|
||||
|
||||
FS_Error storage_sd_mount(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDMount);
|
||||
@@ -851,6 +893,8 @@ FS_Error storage_sd_mount(Storage* storage) {
|
||||
}
|
||||
|
||||
FS_Error storage_sd_info(Storage* storage, SDInfo* info) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {
|
||||
.sdinfo = {
|
||||
@@ -862,6 +906,8 @@ FS_Error storage_sd_info(Storage* storage, SDInfo* info) {
|
||||
}
|
||||
|
||||
FS_Error storage_sd_status(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
S_API_PROLOGUE;
|
||||
SAData data = {};
|
||||
S_API_MESSAGE(StorageCommandSDStatus);
|
||||
@@ -870,6 +916,8 @@ FS_Error storage_sd_status(Storage* storage) {
|
||||
}
|
||||
|
||||
File* storage_file_alloc(Storage* storage) {
|
||||
furi_check(storage);
|
||||
|
||||
File* file = malloc(sizeof(File));
|
||||
file->type = FileTypeClosed;
|
||||
file->storage = storage;
|
||||
@@ -880,14 +928,18 @@ File* storage_file_alloc(Storage* storage) {
|
||||
}
|
||||
|
||||
bool storage_file_is_open(File* file) {
|
||||
furi_check(file);
|
||||
return (file->type != FileTypeClosed);
|
||||
}
|
||||
|
||||
bool storage_file_is_dir(File* file) {
|
||||
furi_check(file);
|
||||
return (file->type == FileTypeOpenDir);
|
||||
}
|
||||
|
||||
void storage_file_free(File* file) {
|
||||
furi_check(file);
|
||||
|
||||
if(storage_file_is_open(file)) {
|
||||
if(storage_file_is_dir(file)) {
|
||||
storage_dir_close(file);
|
||||
@@ -901,13 +953,13 @@ void storage_file_free(File* file) {
|
||||
}
|
||||
|
||||
FuriPubSub* storage_get_pubsub(Storage* storage) {
|
||||
furi_assert(storage);
|
||||
furi_check(storage);
|
||||
return storage->pubsub;
|
||||
}
|
||||
|
||||
bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
furi_assert(storage);
|
||||
furi_assert(path);
|
||||
furi_check(storage);
|
||||
furi_check(path);
|
||||
FileInfo fileinfo;
|
||||
bool result = false;
|
||||
FuriString* fullname;
|
||||
@@ -967,12 +1019,16 @@ bool storage_simply_remove_recursive(Storage* storage, const char* path) {
|
||||
} //-V773
|
||||
|
||||
bool storage_simply_remove(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
FS_Error result;
|
||||
result = storage_common_remove(storage, path);
|
||||
return result == FSE_OK || result == FSE_NOT_EXIST;
|
||||
}
|
||||
|
||||
bool storage_simply_mkdir(Storage* storage, const char* path) {
|
||||
furi_check(storage);
|
||||
|
||||
FS_Error result;
|
||||
result = storage_common_mkdir(storage, path);
|
||||
return result == FSE_OK || result == FSE_EXIST;
|
||||
@@ -985,6 +1041,8 @@ void storage_get_next_filename(
|
||||
const char* fileextension,
|
||||
FuriString* nextfilename,
|
||||
uint8_t max_len) {
|
||||
furi_check(storage);
|
||||
|
||||
FuriString* temp_str;
|
||||
uint16_t num = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user