On Thu, Oct 7, 2010 at 3:02 AM, narendra babu <[email protected]> wrote:
> Hello all ,
>
> I have 2 questions on endian neutral  :
>
> 1)I'm  dont need C++ Object Serialization per-se but I intend to write a few 
> C structures to disk (file.bin) -
> The written data structure on-disk should be portable across different 
> platform architectures (small/big endian)

If you use a character buffer C struct then it is endian neutral. Then
when you read back the structure by doing a cast using
this code:

                                struct mydata *nw_struct;
                                  nw_struct = malloc(sizeof(mydata);
                                 memcpy((struct mydata *) &nw_struct,
buf, sizeof(struct mydata));

                                  Now you can send and receive from
across the network in an Endian neutral fashion.
                                  If you have longs or shorts inside
the struct, just use htonl(), htons() and vice versa.

                       This will surely work.

> Would someone know where I can find some library and/or sample code to write 
> portable C data structure to a disk storage.
> at least some guidelines and pointers / examples would be nice.

You have the code to achieve it.

See above.

> 2) if have solaris code which genrates binary file and i have read it from 
> Linux program .
>

On Sparc architecture? No problem. It will work. I have done that.

> so any specific thing i need to take care so that i can read big endian 
> generated from soalris   from Linux program which is on little endian
>

Nothing more than what I wrote above.

Endianness does not hurt when you use unsigned char buffers.

-Girish
-- 
Gayatri Hitech

http://gayatri-hitech.com
[email protected]



 
Thanks Girish for your inputs ,
 
 
One more input in need from you is  as i mentioned i have solaris generated big 
endian binary file and i need to read the same big endian file in Linux which 
is little endian or on intel machine .
 
So is there anyway i can read big endian file in linux and process it and write 
the binary in big endian .
 
The reason why i am asking is becos i need to maintain the existing solaris 
code and i need to use linux to read and generate the big endian binary so 
that  solaris code can read the big endian file genarted by Linux 
 
in simple words i need to read/write the binary file which in bigendian from 
linux .
 
also i am mostly looking for disk i/o not much of network i/o
 
Thanks
N


_______________________________________________
ILUGC Mailing List:
http://www.ae.iitm.ac.in/mailman/listinfo/ilugc

Reply via email to