Invalid Sock is set to -1 instead 0 (stdin). Consequent error handling in fseek failu...
[profile/ivi/dlt-daemon.git] / src / shared / dlt_common.c
index 8047fcb..b7a865e 100755 (executable)
@@ -1484,7 +1484,7 @@ int dlt_file_read_header_raw(DltFile *file,int resync,int verbose)
         else
         {
             /* go back to last file position */
-            if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
                 return -1;
         }
     }
@@ -1664,9 +1664,20 @@ int dlt_file_open(DltFile *file,const char *filename,int verbose)
         return -1;
     }
 
-    fseek(file->handle,0,SEEK_END);
+    if (0 != fseek(file->handle,0,SEEK_END))
+    {
+        sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_END");
+        dlt_log(LOG_ERR, str);
+        return -1;
+    }
     file->file_length = ftell(file->handle);
-    fseek(file->handle,0,SEEK_SET);
+
+    if (0 != fseek(file->handle,0,SEEK_SET))
+    {
+        sprintf(str,"dlt_file_open: Seek failed to 0,SEEK_SET");
+        dlt_log(LOG_ERR, str);
+        return -1;
+    }
 
     if (verbose)
     {
@@ -1712,7 +1723,7 @@ int dlt_file_read(DltFile *file,int verbose)
     }
 
     /* set to end of last succesful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
-    if ( fseek(file->handle,file->file_position,SEEK_SET) < 0 )
+    if (0 !=  fseek(file->handle,file->file_position,SEEK_SET))
     {
         sprintf(str,"Seek failed to file_position %ld \n",file->file_position);
         dlt_log(LOG_ERR, str);
@@ -1740,7 +1751,7 @@ int dlt_file_read(DltFile *file,int verbose)
         if (dlt_file_read_header_extended(file, verbose)<0)
         {
             /* go back to last position in file */
-            if ( 0 != fseek(file->handle,file->file_position,SEEK_SET))
+            if (0 != fseek(file->handle,file->file_position,SEEK_SET))
             {
                 sprintf(str,"Seek to last file pos failed!\n");
                 dlt_log(LOG_ERR, str);
@@ -1782,11 +1793,16 @@ int dlt_file_read(DltFile *file,int verbose)
         /* skip additional header parameters and payload data */
         if (fseek(file->handle,file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize,SEEK_CUR))
         {
-            /* go back to last position in file */
-            fseek(file->handle,file->file_position,SEEK_SET);
+
             sprintf(str,"Seek failed to skip extra header and payload data from file of size %d!\n",
                     file->msg.headersize - sizeof(DltStorageHeader) - sizeof(DltStandardHeader) + file->msg.datasize);
             dlt_log(LOG_ERR, str);
+            /* go back to last position in file */
+            if (fseek(file->handle,file->file_position,SEEK_SET))
+            {
+                sprintf(str,"Seek back also failed!\n");
+                dlt_log(LOG_ERR, str);
+            }
             return -1;
         }
 
@@ -1840,7 +1856,7 @@ int dlt_file_read_raw(DltFile *file,int resync, int verbose)
     }
 
     /* set to end of last successful read message, because of conflicting calls to dlt_file_read and dlt_file_message */
-    if (fseek(file->handle,file->file_position,SEEK_SET) < 0)
+    if (0 != fseek(file->handle,file->file_position,SEEK_SET))
         return -1;
 
     /* get file position at start of DLT message */