From dca8ab254aa0a687c32009079d85e4d8f960b213 Mon Sep 17 00:00:00 2001 From: Christoph Lipka Date: Thu, 20 Dec 2018 14:58:19 +0100 Subject: Code beautification using uncrustify Signed-off-by: Christoph Lipka --- src/core_dump_handler/dlt_cdh_streamer.c | 99 ++++++++++++-------------------- 1 file changed, 38 insertions(+), 61 deletions(-) (limited to 'src/core_dump_handler/dlt_cdh_streamer.c') diff --git a/src/core_dump_handler/dlt_cdh_streamer.c b/src/core_dump_handler/dlt_cdh_streamer.c index 00b6d04..24bcde2 100644 --- a/src/core_dump_handler/dlt_cdh_streamer.c +++ b/src/core_dump_handler/dlt_cdh_streamer.c @@ -32,13 +32,12 @@ #include #include "dlt_cdh_streamer.h" -#define Z_CHUNK_SZ 1024*128 +#define Z_CHUNK_SZ 1024 * 128 #define Z_MODE_STR "wb1" -cdh_status_t stream_init(file_streamer_t* p_fs, const char* p_src_fname, const char* p_dst_fname) +cdh_status_t stream_init(file_streamer_t *p_fs, const char *p_src_fname, const char *p_dst_fname) { - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_init'"); return CDH_NOK; } @@ -46,17 +45,15 @@ cdh_status_t stream_init(file_streamer_t* p_fs, const char* p_src_fname, const c memset(p_fs, 0, sizeof(file_streamer_t)); /* Allow to not save the coredump */ - if (p_dst_fname == NULL) - { + if (p_dst_fname == NULL) { p_fs->gz_dst_file = 0; } - else - { - // Create output file + else { + /* Create output file */ p_fs->gz_dst_file = gzopen(p_dst_fname, Z_MODE_STR); - if (p_fs->gz_dst_file == Z_NULL) - { - //return CDH_NOK; + + if (p_fs->gz_dst_file == Z_NULL) { + /*return CDH_NOK; */ syslog(LOG_ERR, "Cannot open output filename <%s>. %s", p_dst_fname, strerror(errno)); p_fs->gz_dst_file = 0; @@ -66,23 +63,17 @@ cdh_status_t stream_init(file_streamer_t* p_fs, const char* p_src_fname, const c if (p_fs->gz_dst_file == Z_NULL) syslog(LOG_WARNING, "The coredump will be processed, but not written"); - // Open input file - if (p_src_fname == NULL) - { + /* Open input file */ + if (p_src_fname == NULL) { p_fs->stream = stdin; } - else - { - if ((p_fs->stream = fopen(p_src_fname, "rb")) == NULL) - { - syslog(LOG_ERR, "Cannot open filename <%s>. %s", p_src_fname, strerror(errno)); - return CDH_NOK; - } + else if ((p_fs->stream = fopen(p_src_fname, "rb")) == NULL) { + syslog(LOG_ERR, "Cannot open filename <%s>. %s", p_src_fname, strerror(errno)); + return CDH_NOK; } - // Allocate read buffer - if ((p_fs->read_buf = (unsigned char*) malloc(Z_CHUNK_SZ)) == NULL) - { + /* Allocate read buffer */ + if ((p_fs->read_buf = (unsigned char *)malloc(Z_CHUNK_SZ)) == NULL) { syslog(LOG_ERR, "Cannot allocate %d bytes for read buffer. %s", Z_CHUNK_SZ, strerror(errno)); return CDH_NOK; } @@ -90,29 +81,25 @@ cdh_status_t stream_init(file_streamer_t* p_fs, const char* p_src_fname, const c return CDH_OK; } -cdh_status_t stream_close(file_streamer_t* p_fs) +cdh_status_t stream_close(file_streamer_t *p_fs) { - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_close'"); return CDH_NOK; } - if (p_fs->gz_dst_file != NULL) - { + if (p_fs->gz_dst_file != NULL) { gzflush(p_fs->gz_dst_file, Z_FINISH); gzclose(p_fs->gz_dst_file); p_fs->gz_dst_file = NULL; } - if (p_fs->stream != NULL) - { + if (p_fs->stream != NULL) { fclose(p_fs->stream); p_fs->stream = NULL; } - if (p_fs->read_buf != NULL) - { + if (p_fs->read_buf != NULL) { free(p_fs->read_buf); p_fs->read_buf = NULL; } @@ -120,24 +107,21 @@ cdh_status_t stream_close(file_streamer_t* p_fs) return CDH_OK; } -cdh_status_t stream_read(file_streamer_t* p_fs, void* p_buf, unsigned int p_size) +cdh_status_t stream_read(file_streamer_t *p_fs, void *p_buf, unsigned int p_size) { unsigned int byte_read = 0; - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_read'"); return CDH_NOK; } - if (p_buf == NULL) - { + if (p_buf == NULL) { syslog(LOG_ERR, "Internal buffer pointer error in 'stream_read'"); return CDH_NOK; } - if ((byte_read = fread(p_buf, 1, p_size, p_fs->stream)) != p_size) - { + if ((byte_read = fread(p_buf, 1, p_size, p_fs->stream)) != p_size) { syslog(LOG_WARNING, "Cannot read %d bytes from src. %s", p_size, strerror(errno)); return CDH_NOK; } @@ -150,24 +134,22 @@ cdh_status_t stream_read(file_streamer_t* p_fs, void* p_buf, unsigned int p_size return CDH_OK; } -int stream_finish(file_streamer_t* p_fs) +int stream_finish(file_streamer_t *p_fs) { - if (p_fs == NULL || p_fs->stream == NULL) - { + if ((p_fs == NULL) || (p_fs->stream == NULL)) { syslog(LOG_ERR, "Internal pointer error in 'stream_move_ahead'"); return CDH_NOK; } - while (!feof(p_fs->stream)) - { + while (!feof(p_fs->stream)) { size_t read_bytes = fread(p_fs->read_buf, 1, Z_CHUNK_SZ, p_fs->stream); if (p_fs->gz_dst_file != NULL) gzwrite(p_fs->gz_dst_file, p_fs->read_buf, read_bytes); p_fs->offset += read_bytes; - if (ferror(p_fs->stream)) - { + + if (ferror(p_fs->stream)) { syslog(LOG_WARNING, "Error reading from the src stream: %s", strerror(errno)); return CDH_NOK; } @@ -176,12 +158,11 @@ int stream_finish(file_streamer_t* p_fs) return CDH_OK; } -int stream_move_to_offest(file_streamer_t* p_fs, unsigned int p_offset) +int stream_move_to_offest(file_streamer_t *p_fs, unsigned int p_offset) { int bytes_to_read = 0; - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_move_to_offest'"); return CDH_NOK; } @@ -191,23 +172,20 @@ int stream_move_to_offest(file_streamer_t* p_fs, unsigned int p_offset) return stream_move_ahead(p_fs, bytes_to_read); } -int stream_move_ahead(file_streamer_t* p_fs, unsigned int p_nbbytes) +int stream_move_ahead(file_streamer_t *p_fs, unsigned int p_nbbytes) { int bytes_to_read = p_nbbytes; - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_move_ahead'"); return CDH_NOK; } - while (bytes_to_read > 0) - { + while (bytes_to_read > 0) { size_t chunk_size = bytes_to_read > Z_CHUNK_SZ ? Z_CHUNK_SZ : bytes_to_read; size_t read_bytes = fread(p_fs->read_buf, 1, chunk_size, p_fs->stream); - if (read_bytes != chunk_size) - { + if (read_bytes != chunk_size) { syslog(LOG_WARNING, "Cannot move ahead by %d bytes from src. Read %lu bytes", p_nbbytes, read_bytes); return CDH_NOK; } @@ -223,10 +201,9 @@ int stream_move_ahead(file_streamer_t* p_fs, unsigned int p_nbbytes) return CDH_OK; } -unsigned int stream_get_offset(file_streamer_t* p_fs) +unsigned int stream_get_offset(file_streamer_t *p_fs) { - if (p_fs == NULL) - { + if (p_fs == NULL) { syslog(LOG_ERR, "Internal pointer error in 'stream_get_offset'"); return CDH_NOK; } -- cgit v1.2.1