summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorSaya Sugiura <ssugiura@jp.adit-jv.com>2019-09-25 14:42:15 +0900
committerSaya Sugiura <39760799+ssugiura@users.noreply.github.com>2020-07-06 10:04:07 +0900
commit55ad53d1db08c00f75f6c5100fe9ede7c5e123fe (patch)
treeb8a21f5a8875d352357368ecfbaff0e88d2effaa /src/shared
parent9647f1f4cd5795cb38f8ab266a9315514bfb0310 (diff)
downloadDLT-daemon-55ad53d1db08c00f75f6c5100fe9ede7c5e123fe.tar.gz
shared: Read DLT header until it's found
Current dlt_file_read_header() function which is used for e.g. dlt-convert, dlt-sortbytimestamp, etc. stops finding DLT header if it's not available in the next file position. It is improved to read the header in a loop until it's found. Signed-off-by: Saya Sugiura <ssugiura@jp.adit-jv.com>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/dlt_common.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/src/shared/dlt_common.c b/src/shared/dlt_common.c
index e046cc4..d2471ee 100644
--- a/src/shared/dlt_common.c
+++ b/src/shared/dlt_common.c
@@ -1152,22 +1152,40 @@ DltReturnValue dlt_file_read_header(DltFile *file, int verbose)
if (file == NULL)
return DLT_RETURN_WRONG_PARAMETER;
- /* load header from file */
- if (fread(file->msg.headerbuffer, sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1, file->handle) != 1) {
- if (!feof(file->handle))
- dlt_log(LOG_WARNING, "Cannot read header from file!\n");
+ /* Loop until storage header is found */
+ while (1) {
+ /* load header from file */
+ if (fread(file->msg.headerbuffer,
+ sizeof(DltStorageHeader) + sizeof(DltStandardHeader), 1,
+ file->handle) != 1) {
+ if (!feof(file->handle))
+ dlt_log(LOG_WARNING, "Cannot read header from file!\n");
+ else
+ dlt_log(LOG_DEBUG, "Reached end of file\n");
- return DLT_RETURN_ERROR;
- }
- /* set ptrs to structures */
- file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer;
- file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer + sizeof(DltStorageHeader));
+ return DLT_RETURN_ERROR;
+ }
- /* check id of storage header */
- if (dlt_check_storageheader(file->msg.storageheader) != DLT_RETURN_TRUE) {
- dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n");
- return DLT_RETURN_ERROR;
+ /* set ptrs to structures */
+ file->msg.storageheader = (DltStorageHeader *)file->msg.headerbuffer;
+ file->msg.standardheader = (DltStandardHeader *)(file->msg.headerbuffer +
+ sizeof(DltStorageHeader));
+
+ /* check id of storage header */
+ if (dlt_check_storageheader(file->msg.storageheader) != DLT_RETURN_TRUE) {
+ /* Shift the position back to the place where it stared to read + 1 */
+ if (fseek(file->handle,
+ 1 - (sizeof(DltStorageHeader) + sizeof(DltStandardHeader)),
+ SEEK_CUR) < 0) {
+ dlt_log(LOG_WARNING, "DLT storage header pattern not found!\n");
+ return DLT_RETURN_ERROR;
+ }
+ }
+ else {
+ /* storage header is found */
+ break;
+ }
}
/* calculate complete size of headers */