<?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: Store C struct in binary file in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903299#M701966</link>
    <description>Thanx for the replies, I still had no time to check it, but I will (and also assign points of course).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Alex.</description>
    <pubDate>Mon, 23 May 2005 15:22:16 GMT</pubDate>
    <dc:creator>Alex Lavrov.</dc:creator>
    <dc:date>2005-05-23T15:22:16Z</dc:date>
    <item>
      <title>Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903296#M701963</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I'm looking for a standart way to store a C structure in a binary file. I never used this kind of thing and after some googling I still did not find the answer.&lt;BR /&gt;&lt;BR /&gt;Actually, I'm looking for some really low-level storage mechanism in binary files. I know there some nice programs like berkeley db, but it's not good enough because they are GPL or commercial. I'm not sure that the program I'm writing gonna be GPL and also I don't plan to pay any money.&lt;BR /&gt;&lt;BR /&gt;Thanx.</description>
      <pubDate>Sat, 21 May 2005 14:59:51 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903296#M701963</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-05-21T14:59:51Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903297#M701964</link>
      <description>Well, if you want low-level i/o that means file descriptors, read()'s, write()'s lseek()'s, open()'s and close()'es. The attached C code pasted from some of my standard routines should work and give you a very good idea of what is involved.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Sat, 21 May 2005 22:50:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903297#M701964</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2005-05-21T22:50:10Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903298#M701965</link>
      <description>If you want to stick to ANSI stdio (instead&lt;BR /&gt;of the POSIX read(), write(), etc.) you can&lt;BR /&gt;also use fread() and fwrite().  If you want&lt;BR /&gt;to be platform-independent you should&lt;BR /&gt;probably check out XDR too (man xdr).&lt;BR /&gt;&lt;BR /&gt;</description>
      <pubDate>Mon, 23 May 2005 14:35:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903298#M701965</guid>
      <dc:creator>Gregory Fruth</dc:creator>
      <dc:date>2005-05-23T14:35:41Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903299#M701966</link>
      <description>Thanx for the replies, I still had no time to check it, but I will (and also assign points of course).&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Alex.</description>
      <pubDate>Mon, 23 May 2005 15:22:16 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903299#M701966</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-05-23T15:22:16Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903300#M701967</link>
      <description>Thank you, it's exactly what I'm looking for.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;Alex.</description>
      <pubDate>Tue, 24 May 2005 07:17:03 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903300#M701967</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-05-24T07:17:03Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903301#M701968</link>
      <description>Alex, it's surprisingly simpler than you think - the source of the fwrite buffer would be the pointer to the memory structure you created.  Ditto for the fread function - just pass a pointer to the memory structure that you created it will load back what you wrote out from the previous fwrite.  &lt;BR /&gt;&lt;BR /&gt;Let's say your memory structure "mystruct" is already defined - and your file "MYFILE" is already opened .&lt;BR /&gt;&lt;BR /&gt;fwrite (&amp;amp;mystruct, (size_t)sizeof(mystruct),1,MYFILE);&lt;BR /&gt;&lt;BR /&gt;to get it back:&lt;BR /&gt;fread (&amp;amp;mystruct, (size_t)sizeof(mystruct),1,MYFILE);&lt;BR /&gt;&lt;BR /&gt;If you've created an array of these structures - you can save them all by setting your pointer to the first one - and passing the number of elements in your "array" as the third argument - then they'll all be passed.  &lt;BR /&gt;&lt;BR /&gt;Be aware that due to padding in some compilers, you could do this one compiler, and the padding could be off if you read back the same data file in another.  Doesn't always happen, it's just that you should check b/w compilers if that is necessary.&lt;BR /&gt;</description>
      <pubDate>Tue, 24 May 2005 08:07:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903301#M701968</guid>
      <dc:creator>TwoProc</dc:creator>
      <dc:date>2005-05-24T08:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Store C struct in binary file</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903302#M701969</link>
      <description>Thanx.</description>
      <pubDate>Tue, 24 May 2005 08:12:47 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/store-c-struct-in-binary-file/m-p/4903302#M701969</guid>
      <dc:creator>Alex Lavrov.</dc:creator>
      <dc:date>2005-05-24T08:12:47Z</dc:date>
    </item>
  </channel>
</rss>

