Note that there are some explanatory texts on larger screens.

plurals
  1. POConvert binary data file generated in windows to linux
    text
    copied!<p>I apologize ahead of time for my lack of c knowledge, as I am a native FORTRAN programmer. I was given some c code to debug which ingests a binary file and parses it into an input file containing several hundred records (871, to be exact) for a Fortran program that I'm working with. The problem is that these input binaries, and the associated c code, were created in a Windows environment. The parser reads through the binary until it reaches the end of the file:</p> <pre><code>SAGE_Lvl0_Packet GetNextPacket() { int i; SAGE_Lvl0_Packet inpkt; WORD rdbuf[128]; memset(rdbuf,0,sizeof(rdbuf)); fprintf(stdout,"Nbytes: %u\n",Nbytes);//returns 224 if((i = fread(rdbuf,Nbytes,1,Fp)) != 1) FileEnd = 1; else { if(FileType == 0) memcpy(&amp;(inpkt.CCSDS),rdbuf,Nbytes); else memcpy(&amp;inpkt,rdbuf,Nbytes); memcpy(&amp;CurrentPacket,&amp;inpkt,sizeof(inpkt)); } return inpkt; } </code></pre> <p>So when the code gets to packet 872, this snippet should return FileEnd = 1. Instead, the parser attempts to read a large amount of data from (near) the end of the file. This, I would think, would cause the program to crash (at least it would in Fortran. Would c just start reading the next portion of memory?) Fortunately, there is a CRC later on in the code that catches that the parser isn't reading correct data and exits gracefully. </p> <p>I assume the problem originates with the binary buffer size and value in a Windows binary being larger/different than that in Linux. If that is the case, is there an easy way to convert Windows' binaries to Linux either in c or Linux? If I'm wrong in my assumption, then perhaps I need to look over the code some more. BTW, a WORD is an unsigned short int, and a SAGE_Lvl0_Packet is a 3-tiered structure with a total of 106 WORDs.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload