From d3f62e237096e79c215cb728e8105e82c4e6e7dd Mon Sep 17 00:00:00 2001 From: Dinh Cong Toan Date: Wed, 26 May 2021 13:29:49 +0700 Subject: Apply uncrustify for src/daemon/* and src/lib/* Apply uncrustify for src/daemon/* and src/lib/* Signed-off-by: KHANH LUONG HONG DUY --- src/lib/dlt_filetransfer.c | 143 +++++++++++++++++++++++++++------------------ 1 file changed, 86 insertions(+), 57 deletions(-) (limited to 'src/lib/dlt_filetransfer.c') diff --git a/src/lib/dlt_filetransfer.c b/src/lib/dlt_filetransfer.c index bd196ea..7508790 100644 --- a/src/lib/dlt_filetransfer.c +++ b/src/lib/dlt_filetransfer.c @@ -101,18 +101,21 @@ uint32_t getFilesize(const char *file, int *ok) */ void stringHash(const char *str, uint32_t *hash) { - if (!str || !hash) + if (!str || !hash) { return; + } unsigned int len = strlen(str); unsigned int i = 0; - if (len <= 0) + if (len <= 0) { return; + } - for (i = 0; i < len; i++) + for (i = 0; i < len; i++) { *hash = 53 * *hash + str[i]; + } } @@ -130,8 +133,7 @@ uint32_t getFileSerialNumber(const char *file, int *ok) if (-1 == stat(file, &st)) { *ok = 0; ret = 0; - } - else { + } else { *ok = 1; ret = st.st_ino; ret = ret << (sizeof(ret) * 8) / 2; @@ -217,8 +219,9 @@ int checkUserBufferForFreeSpace() dlt_user_check_buffer(&total_size, &used_size); - if ((total_size - used_size) < (total_size / 2)) + if ((total_size - used_size) < (total_size / 2)) { return -1; + } return 1; } @@ -240,27 +243,30 @@ void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filenam int ok = 0; uint32_t fserial = getFileSerialNumber(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFileSerialNumber for: "), DLT_STRING(filename)); + } uint32_t fsize = getFilesize(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), DLT_STRING(filename)); + } char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_errorMessage, error in getFilesize for: "), DLT_STRING(filename)); + } int package_count = dlt_user_log_file_packagesCount(fileContext, filename); @@ -276,8 +282,7 @@ void dlt_user_log_file_errorMessage(DltContext *fileContext, const char *filenam DLT_UINT(BUFFER_SIZE), DLT_STRING("FLER") ); - } - else { + } else { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("FLER"), DLT_INT(errorCode), @@ -304,28 +309,31 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) uint32_t fsize = getFilesize(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting size of file:"), DLT_STRING(filename)); + } uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting serial number of file:"), DLT_STRING(filename)); + } char creationdate[50]; getFileCreationDate2(filename, &ok, creationdate); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_infoAbout, Error getting creation date of file:"), DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLIF"), @@ -333,12 +341,12 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) DLT_STRING("filename"), DLT_STRING(filename), DLT_STRING("file size in bytes"), DLT_UINT(fsize), DLT_STRING("file creation date"), DLT_STRING(creationdate), - DLT_STRING("number of packages"), DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), + DLT_STRING("number of packages"), + DLT_UINT(dlt_user_log_file_packagesCount(fileContext, filename)), DLT_STRING("FLIF") ); return 0; - } - else { + } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_INFO_ABOUT); return DLT_FILETRANSFER_ERROR_INFO_ABOUT; } @@ -356,21 +364,28 @@ int dlt_user_log_file_infoAbout(DltContext *fileContext, const char *filename) * @param timeout Timeout in ms to wait between some logs. Important that the FIFO of dlt will not be flooded with to many messages in a short period of time. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_complete(DltContext *fileContext, const char *filename, int deleteFlag, int timeout) +int dlt_user_log_file_complete(DltContext *fileContext, + const char *filename, + int deleteFlag, + int timeout) { if (!isFile(filename)) { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_COMPLETE); return DLT_FILETRANSFER_ERROR_FILE_COMPLETE; } - if (dlt_user_log_file_header(fileContext, filename) != 0) + if (dlt_user_log_file_header(fileContext, filename) != 0) { return DLT_FILETRANSFER_ERROR_FILE_COMPLETE1; + } - if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, timeout) != 0) + if (dlt_user_log_file_data(fileContext, filename, DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES, + timeout) != 0) { return DLT_FILETRANSFER_ERROR_FILE_COMPLETE2; + } - if (dlt_user_log_file_end(fileContext, filename, deleteFlag) != 0) + if (dlt_user_log_file_end(fileContext, filename, deleteFlag) != 0) { return DLT_FILETRANSFER_ERROR_FILE_COMPLETE3; + } return 0; } @@ -405,17 +420,16 @@ int dlt_user_log_file_packagesCount(DltContext *fileContext, const char *filenam if (filesize < BUFFER_SIZE) { return packages; - } - else { + } else { packages = filesize / BUFFER_SIZE; - if (filesize % BUFFER_SIZE == 0) + if (filesize % BUFFER_SIZE == 0) { return packages; - else + } else { return packages + 1; + } } - } - else { + } else { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("Error in: dlt_user_log_file_packagesCount, !isFile"), @@ -443,24 +457,31 @@ int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header_alias, Error getting serial number of file:"), + DLT_STRING( + "dlt_user_log_file_header_alias, Error getting serial number of file:"), DLT_STRING(filename)); + } uint32_t fsize = getFilesize(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header_alias, Error getting size of file:"), DLT_STRING(filename)); + DLT_STRING( + "dlt_user_log_file_header_alias, Error getting size of file:"), + DLT_STRING(filename)); + } char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header_alias, Error getting creation date of file:"), + DLT_STRING( + "dlt_user_log_file_header_alias, Error getting creation date of file:"), DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), @@ -474,8 +495,7 @@ int dlt_user_log_file_header_alias(DltContext *fileContext, const char *filename ); return 0; - } - else { + } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } @@ -498,24 +518,31 @@ int dlt_user_log_file_header(DltContext *fileContext, const char *filename) uint32_t fserialnumber = getFileSerialNumber(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header, Error getting serial number of file:"), DLT_STRING(filename)); + DLT_STRING( + "dlt_user_log_file_header, Error getting serial number of file:"), + DLT_STRING(filename)); + } uint32_t fsize = getFilesize(filename, &ok); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("dlt_user_log_file_header, Error getting size of file:"), DLT_STRING(filename)); + } char fcreationdate[50]; getFileCreationDate2(filename, &ok, fcreationdate); - if (!ok) + if (!ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, - DLT_STRING("dlt_user_log_file_header, Error getting creation date of file:"), DLT_STRING(filename)); + DLT_STRING( + "dlt_user_log_file_header, Error getting creation date of file:"), + DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLST"), @@ -529,8 +556,7 @@ int dlt_user_log_file_header(DltContext *fileContext, const char *filename) ); return 0; - } - else { + } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_HEAD); return DLT_FILETRANSFER_ERROR_FILE_HEAD; } @@ -544,7 +570,10 @@ int dlt_user_log_file_header(DltContext *fileContext, const char *filename) * @param timeout Timeout to wait between dlt logs. Important because the dlt FIFO should not be flooded. Default is defined by MIN_TIMEOUT. The given timeout in ms can not be smaller than MIN_TIMEOUT. * @return Returns 0 if everything was okey. If there was a failure a value < 0 will be returned. */ -int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int packageToTransfer, int timeout) +int dlt_user_log_file_data(DltContext *fileContext, + const char *filename, + int packageToTransfer, + int timeout) { FILE *file; int pkgNumber; @@ -561,7 +590,8 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa if (((packageToTransfer != DLT_FILETRANSFER_TRANSFER_ALL_PACKAGES) && (packageToTransfer > - dlt_user_log_file_packagesCount(fileContext, filename))) || (packageToTransfer <= 0)) { + dlt_user_log_file_packagesCount(fileContext, + filename))) || (packageToTransfer <= 0)) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("Error at dlt_user_log_file_data: packageToTransfer out of scope"), DLT_STRING("packageToTransfer:"), @@ -592,7 +622,6 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa fclose (file); return -1; - } readBytes = fread(buffer, sizeof(char), BUFFER_SIZE, file); @@ -600,10 +629,11 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) + if (1 != ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), @@ -614,9 +644,7 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa ); doTimeout(timeout); - - } - else { + } else { pkgNumber = 0; while (!feof(file)) { @@ -629,10 +657,11 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) + if (1 != ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLDA"), @@ -650,9 +679,7 @@ int dlt_user_log_file_data(DltContext *fileContext, const char *filename, int pa fclose(file); return 0; - - } - else { + } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_DATA); return DLT_FILETRANSFER_ERROR_FILE_DATA; } @@ -674,10 +701,11 @@ int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int del int ok; uint32_t fserial = getFileSerialNumber(filename, &ok); - if (1 != ok) + if (1 != ok) { DLT_LOG(*fileContext, DLT_LOG_ERROR, DLT_STRING("failed to get FileSerialNumber for: "), DLT_STRING(filename)); + } DLT_LOG(*fileContext, DLT_LOG_INFO, DLT_STRING("FLFI"), @@ -687,14 +715,15 @@ int dlt_user_log_file_end(DltContext *fileContext, const char *filename, int del if (deleteFlag) { if (doRemoveFile(filename) != 0) { - dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); + dlt_user_log_file_errorMessage(fileContext, + filename, + DLT_FILETRANSFER_ERROR_FILE_END); return -1; } } return 0; - } - else { + } else { dlt_user_log_file_errorMessage(fileContext, filename, DLT_FILETRANSFER_ERROR_FILE_END); return DLT_FILETRANSFER_ERROR_FILE_END; } -- cgit v1.2.1