Skip to content

Commit

Permalink
port: linux: run clang-format on files
Browse files Browse the repository at this point in the history
No substantive changes were made in this commit. It merely applies the
clang-format rules to these files.

Signed-off-by: Mike Szczys <[email protected]>
  • Loading branch information
szczys committed Sep 9, 2024
1 parent e0b0d06 commit eed44de
Show file tree
Hide file tree
Showing 2 changed files with 152 additions and 106 deletions.
85 changes: 49 additions & 36 deletions port/linux/fw_update_linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,22 @@
#define DOWNLOADED_FILE_NAME "downloaded.bin"

#define FW_UPDATE_RETURN_IF_NEGATIVE(expr) \
do { \
int retval = (expr); \
if (retval < 0) { \
return retval; \
} \
do \
{ \
int retval = (expr); \
if (retval < 0) \
{ \
return retval; \
} \
} while (0)

static FILE* _download_fp;
static FILE* _current_fp;
static uint8_t* _filebuf;
static FILE *_download_fp;
static FILE *_current_fp;
static uint8_t *_filebuf;
static bool _initialized;

bool fw_update_is_pending_verify(void) {
bool fw_update_is_pending_verify(void)
{
return false;
}

Expand All @@ -39,54 +42,61 @@ void fw_update_reboot(void) {}
void fw_update_cancel_rollback(void) {}

#if ENABLE_DOWNLOAD_TO_FILE
enum golioth_status fw_update_handle_block(
const uint8_t* block,
size_t block_size,
size_t offset,
size_t total_size) {
if (!_download_fp) {
enum golioth_status fw_update_handle_block(const uint8_t *block,
size_t block_size,
size_t offset,
size_t total_size)
{
if (!_download_fp)
{
_download_fp = fopen(DOWNLOADED_FILE_NAME, "w");
}
GLTH_LOGD(
TAG,
"block_size 0x%08lX, offset 0x%08lX, total_size 0x%08lX",
block_size,
offset,
total_size);
GLTH_LOGD(TAG,
"block_size 0x%08lX, offset 0x%08lX, total_size 0x%08lX",
block_size,
offset,
total_size);
fwrite(block, block_size, 1, _download_fp);
return GOLIOTH_OK;
}
#else
enum golioth_status fw_update_handle_block(
const uint8_t* block,
size_t block_size,
size_t offset,
size_t total_size) {
enum golioth_status fw_update_handle_block(const uint8_t *block,
size_t block_size,
size_t offset,
size_t total_size)
{
return GOLIOTH_OK;
}
#endif

void fw_update_post_download(void) {
if (_download_fp) {
void fw_update_post_download(void)
{
if (_download_fp)
{
fclose(_download_fp);
_download_fp = NULL;
}
if (_current_fp) {
if (_current_fp)
{
fclose(_current_fp);
_current_fp = NULL;
}
}

enum golioth_status fw_update_validate(void) {
enum golioth_status fw_update_validate(void)
{
return GOLIOTH_OK;
}

enum golioth_status fw_update_change_boot_image(void) {
enum golioth_status fw_update_change_boot_image(void)
{
return GOLIOTH_OK;
}

void fw_update_end(void) {
if (_filebuf) {
void fw_update_end(void)
{
if (_filebuf)
{
free(_filebuf);
_filebuf = NULL;
}
Expand All @@ -98,23 +108,26 @@ void fw_update_end(void) {
//
// On error, a negative value is returned
// On success, the number of bytes read is returned.
int read_file(const char* filepath, uint8_t** filebuf) {
int read_file(const char *filepath, uint8_t **filebuf)
{
int fd = open(filepath, O_RDONLY, 0);
FW_UPDATE_RETURN_IF_NEGATIVE(fd);

int filesize = lseek(fd, 0, SEEK_END);
FW_UPDATE_RETURN_IF_NEGATIVE(filesize);

*filebuf = malloc(filesize + 1);
if (!*filebuf) {
if (!*filebuf)
{
GLTH_LOGE(TAG, "Failed to allocate");
return -1;
}

FW_UPDATE_RETURN_IF_NEGATIVE(lseek(fd, 0, SEEK_SET));

int bytes_read = read(fd, *filebuf, filesize);
if (bytes_read != filesize) {
if (bytes_read != filesize)
{
GLTH_LOGE(TAG, "Failed to read entire file");
return -1;
}
Expand Down
Loading

0 comments on commit eed44de

Please sign in to comment.