<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: DEC C RTL skips *some* bytes when reading binary files in Operating System - OpenVMS</title>
    <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726398#M33507</link>
    <description>The problem is that the C RTL opens any non-STMLF file by default in record mode, so RMS is gobbling the data before the fopen mode ("rb") applies.  Try adding a "ctx=stm" as an additional, argument to the fopen() call.&lt;BR /&gt;It's still non-portable, but it is less involved that writing separate routines.</description>
    <pubDate>Wed, 08 Feb 2006 21:44:27 GMT</pubDate>
    <dc:creator>David Jones_21</dc:creator>
    <dc:date>2006-02-08T21:44:27Z</dc:date>
    <item>
      <title>DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726393#M33502</link>
      <description>Hello specialists,&lt;BR /&gt;&lt;BR /&gt;I am trying to read binary files, e.g., a .BMP file saved to VMS from a PC using PATHWORKS. I am doing fine (i.e., can successfully process a whole file) unless I hit a byte with a value of 0x0B: after this byte, I loose synchronization with the data stream by missing zero bytes. This happens with fgetc as well as with fread, so I am afraid the problem may be somewhere deep inside the RTL - or, am I doing something wrong?&lt;BR /&gt;&lt;BR /&gt;I am using...&lt;BR /&gt;&lt;BR /&gt;HN01$ cc/ver&lt;BR /&gt;DEC C V6.0-001 on OpenVMS Alpha V7.3-2  &lt;BR /&gt;HN01$&lt;BR /&gt;&lt;BR /&gt;(Too old? - If you can point me to a more recent version that fixes my problem, I'll happily consider this a valid and good answer.)&lt;BR /&gt;&lt;BR /&gt;Please compare the output of my attached C program that dumps the first 64 bytes of a file once using fgetc and once using fread...&lt;BR /&gt;&lt;BR /&gt;HN01$ r readbin&lt;BR /&gt;42 4d 3e 1a 00 00 00 00 00 00 3e 00 00 00 28 00 &lt;BR /&gt;00 00 fb 00 00 00 d0 00 00 00 01 00 01 00 00 00 &lt;BR /&gt;00 00 00 1a 00 00 13 0b 13 0b 02 00 00 00 00 00 &lt;BR /&gt;00 00 00 00 00 00 ff ff ff 00 ff ff ff ff ff ff &lt;BR /&gt;&lt;BR /&gt;42 4d 3e 1a 00 00 00 00 00 00 3e 00 00 00 28 00 &lt;BR /&gt;00 00 fb 00 00 00 d0 00 00 00 01 00 01 00 00 00 &lt;BR /&gt;00 00 00 1a 00 00 13 0b 13 0b 02 00 00 00 00 00 &lt;BR /&gt;00 00 00 00 00 00 ff ff ff 00 ff ff ff ff ff ff &lt;BR /&gt;HN01$&lt;BR /&gt;&lt;BR /&gt;... to the (partial, but corresponding) output of a DUMP/BYTE command:&lt;BR /&gt;&lt;BR /&gt; 00 28 00 00 00 3E 00 00 00 00 00 00 1A 3E 4D 42 BM&amp;gt;.......&amp;gt;...(. 000000&lt;BR /&gt; 00 00 00 01 00 01 00 00 00 D0 00 00 00 FB 00 00 ..Ã»... ......... 000010&lt;BR /&gt; 00 02 00 00 0B 13 00 00 0B 13 00 00 1A 00 00 00 ................ 000020&lt;BR /&gt; FF FF 00 FF FF FF 00 00 00 00 00 00 00 00 00 00 ................ 000030&lt;BR /&gt;&lt;BR /&gt;(To create a similar file for your own test, save a .BMP with a resolution of 72 dots per inch. This will be stored as 2,835 dots per meter, which is 0B13 in hex.)&lt;BR /&gt;&lt;BR /&gt;Any ideas? - Thanks in advance!&lt;BR /&gt;&lt;BR /&gt;Andreas</description>
      <pubDate>Tue, 07 Feb 2006 14:16:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726393#M33502</guid>
      <dc:creator>Andreas Freiherr</dc:creator>
      <dc:date>2006-02-07T14:16:57Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726394#M33503</link>
      <description>&lt;BR /&gt;What is the file record format? DIR/FUL&lt;BR /&gt;or WRITE SYS$OUTPUT F$FILE(file,"RFM")&lt;BR /&gt;&lt;BR /&gt;I'm guessing is is STM instead of STMLF.&lt;BR /&gt;The 0B = VT would then be a record terminator.&lt;BR /&gt;Try SET FILE/ATTR=RFM=UDF&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h71000.www7.hp.com/doc/731FINAL/4523/4523pro_007.html#rms_record_format_field" target="_blank"&gt;http://h71000.www7.hp.com/doc/731FINAL/4523/4523pro_007.html#rms_record_format_field&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;FAB$C_STM&lt;BR /&gt;Indicates stream record format. Records are delimited by FF, VT, LF, or CR LF, and all leading zeros are ignored. This format applies to sequential files only and cannot be used with the block spanning option. &lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Tue, 07 Feb 2006 14:30:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726394#M33503</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-02-07T14:30:48Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726395#M33504</link>
      <description>Wel..... Inquiring minds want to know... &lt;BR /&gt;Was the file in question marked a 'STREAM' or 'STM'?&lt;BR /&gt;&lt;BR /&gt;That is a nice name for a nasty file format.&lt;BR /&gt;It was really is only there for a compatibilty with RSTS for which the need expired more than 2 decades ago (imho).&lt;BR /&gt;&lt;BR /&gt;The only RMS record format which comes closed to stream-of-bytes is the 'UNDEFINED' or UDF format. Unfortunately some generic tools barf on this files, instead of just taking a buffer full at a time and deal with it.&lt;BR /&gt;&lt;BR /&gt;Therefor one is often forced to claim 'STREAM_LF' and the next best, but not entirely correct description of the record format.&lt;BR /&gt;&lt;BR /&gt;hth,&lt;BR /&gt;Hein.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Feb 2006 08:38:32 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726395#M33504</guid>
      <dc:creator>Hein van den Heuvel</dc:creator>
      <dc:date>2006-02-08T08:38:32Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726396#M33505</link>
      <description>Hein,&lt;BR /&gt;&lt;BR /&gt;You're right, the record format is STM. However, does this matter when the file is opened for BINARY access (my demo program says fopen ("test", --&amp;gt;"rb"&amp;lt;--, "dna=.bmp"))?&lt;BR /&gt;&lt;BR /&gt;You're of course right, 0B is the vertical tab control character, but I know I am able to read other terminators (CR, LF, etc.) without any problem.&lt;BR /&gt;&lt;BR /&gt;Also, remember that the VT gets through, but I am loosing the following NULs, even though I successfully read several NULs before from the same file!&lt;BR /&gt;&lt;BR /&gt;I tried fread with the complete header declared as a struct, and lost the same bytes from the file. In this case, no *character* processing should be involved, right?&lt;BR /&gt;&lt;BR /&gt;If terminators like these cannot be read this way, then what do I need to do instead? - It might be interesting to see how PATHWORKS reads this .BMP file back when I open it from the PC, because this *does* work.&lt;BR /&gt;&lt;BR /&gt;Andreas&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Feb 2006 09:31:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726396#M33505</guid>
      <dc:creator>Andreas Freiherr</dc:creator>
      <dc:date>2006-02-08T09:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726397#M33506</link>
      <description>Hein, Everybody,&lt;BR /&gt;&lt;BR /&gt;after some off-forum communication, I conducted some additional tests with different record format settings on the same file, in which I had stored different sequences that might cause effects, involving NULs (ASCII 00), LF (ASCII 10 = 0A hex), VT (11 = 0B), FF (12 = 0C), and CR (13 = 0D):&lt;BR /&gt;&lt;BR /&gt;0A 00: if stored in file, is read as...&lt;BR /&gt;... 0A only with STM,&lt;BR /&gt;... 0A 00 with STMCR,&lt;BR /&gt;... 0A 00 with STMLF, UDF, and VAR records&lt;BR /&gt;&lt;BR /&gt;0B 00: similar to 0A 00&lt;BR /&gt;&lt;BR /&gt;0C 00: similar to 0A 00&lt;BR /&gt;&lt;BR /&gt;0D 00: read as...&lt;BR /&gt;... 0D 00 with STM&lt;BR /&gt;... 00 only (CR dropped) with STMCR&lt;BR /&gt;... 0D 00 with STMLF, UDF, and VAR records&lt;BR /&gt;&lt;BR /&gt;0D 0A 00: read as...&lt;BR /&gt;... (nothing, all 3 bytes dropped) with STM&lt;BR /&gt;... 0A 00 (CR dropped) with STMCR&lt;BR /&gt;... 0D 0A 00 with STMLF, UDF, and VAR.&lt;BR /&gt;&lt;BR /&gt;All tests were run with "rb" as the mode in fopen.&lt;BR /&gt;&lt;BR /&gt;This tells me that line terminators are handled even if binary access is requested. I am tempted to consider the "b" in the mode string a no-op.&lt;BR /&gt;&lt;BR /&gt;The STMLF, UDF, and VAR formats behave identically (surprised me), except that the record length field is hidden when VAR is used (no surprise).&lt;BR /&gt;&lt;BR /&gt;Another observation is that suppression of leading NULs occurs only with certain record formats and is not directly related to recognition of a line terminator.&lt;BR /&gt;&lt;BR /&gt;There was no visible difference in behaviour between fgetc and fread (so what good is fread, other than saving me coding a loop?)&lt;BR /&gt;&lt;BR /&gt;To me, these results don't make sense, so it's probably best to rewrite part of my program, following Hein's suggestion and using native VMS I/O routines. Bye, bye, portability!&lt;BR /&gt;</description>
      <pubDate>Wed, 08 Feb 2006 12:42:31 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726397#M33506</guid>
      <dc:creator>Andreas Freiherr</dc:creator>
      <dc:date>2006-02-08T12:42:31Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726398#M33507</link>
      <description>The problem is that the C RTL opens any non-STMLF file by default in record mode, so RMS is gobbling the data before the fopen mode ("rb") applies.  Try adding a "ctx=stm" as an additional, argument to the fopen() call.&lt;BR /&gt;It's still non-portable, but it is less involved that writing separate routines.</description>
      <pubDate>Wed, 08 Feb 2006 21:44:27 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726398#M33507</guid>
      <dc:creator>David Jones_21</dc:creator>
      <dc:date>2006-02-08T21:44:27Z</dc:date>
    </item>
    <item>
      <title>Re: DEC C RTL skips *some* bytes when reading binary files</title>
      <link>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726399#M33508</link>
      <description>David,&lt;BR /&gt;&lt;BR /&gt;You're absolutely right: "ctx=stm" does the trick.&lt;BR /&gt;&lt;BR /&gt;And, for portability, it's far easier to toggle the presence of this argument in fopen than to use a layer of I/O routines on top of the RTL or RMS.&lt;BR /&gt;&lt;BR /&gt;Case closed, thanks!</description>
      <pubDate>Thu, 09 Feb 2006 14:05:11 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-openvms/dec-c-rtl-skips-some-bytes-when-reading-binary-files/m-p/3726399#M33508</guid>
      <dc:creator>Andreas Freiherr</dc:creator>
      <dc:date>2006-02-09T14:05:11Z</dc:date>
    </item>
  </channel>
</rss>

