• Advertisement
Sign in to follow this  

strange read()/write() behaviour (windows vs. linux)

This topic is 3972 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This is really messed up.... I've been working on a resource file packing mechanism, and it works great, but I've noticed some... odd... behaviour when I ran it on Windows. I ran the exact same code on the exact same set of files, with the following differences: - The resource file in windows is exactly 1 byte larger than the one generated in Linux - I've verified that the two files are exactly identical, except for the one last byte appended by the windows code Now, this is where it gets weird: - When reading the resource file, both windows and linux can only handle the one generated in linux. The reason this is so weird is that since the files are exactly the same (except the last trailing byte), it should be able to read in the header information fine, which it does not. Is there something shady going on on the windows side? I'm using Dev-C++, fwiw. Thanks

Share this post


Link to post
Share on other sites
Advertisement
I'm sorry, my bad: The files do, in fact, differ NOT just at the end. I'm looking at my write code, and hopefully will find out what's causing this...

Quote:
are you reading and writing in binary mode?


I didn't think there was a non-binary way to use these APIs... Just writing a const void* to a file descripor... Definitely nothing in the man pages about it.

Here's how I open my file for write, though:

open(resourceFileName.c_str(), O_WRONLY | O_TRUNC | O_CREAT, S_IREAD | S_IWRITE);


Edit: yup, out of (seemingly) nowhere, it inserts a 0x0d just ONCE. I'll debug it some other time with toy data.... ugh...
More edit: In fact, it looks like the windows version is throwing in lots of padding here and there, just for the hell of it.

[Edited by - Replicon on April 8, 2007 9:03:16 PM]

Share this post


Link to post
Share on other sites
Read and write in binary mode. If you don't know what that means, look it up.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Read and write in binary mode. If you don't know what that means, look it up.


Heh yeah, I should probably switch it over to the fstream implementations of read/write and use ios::binary. I'm currently on the C API. Interestingly, there is an "O_BINARY" flag available using the libraries that come with Dev-C++, but my linux box doesn't define that flag. No wonder it doesn't show up on the man pages. So, I guess there's no choice - if I don't move it to fstream, the code won't be cross-platform, so the switch will happen sooner rather than later. Thanks for the tips.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement