3

Possible Duplicate:
what’s the differences between r and rb in fopen

I was designing a zip-unzip utility in C. The zipping and unzipping worked well if the input files were .c or .txt files. But if I gave any other file as input it did not unzip. I added the b flag when reading and writing files. Since then it has worked perfectly. What is the significance of b? I know that it is for binary read/write. Can someone please share the details of what happens at system level? I am working on Linux.

Community
  • 1
  • 1
Parth Shah
  • 573
  • 1
  • 6
  • 17
  • 2
    The "b" flag is guaranteed to make no difference on Linux. http://pubs.opengroup.org/onlinepubs/009695399/functions/fopen.html: "The character `'b'` shall have no effect, but is allowed for ISO C standard conformance". – Steve Jessop Oct 16 '12 at 09:42
  • No difference on Linux and any other POSIX compliant system, to be precise. – January Oct 16 '12 at 09:51
  • @Steve Jessop, yes - but that doesn't mean you should omit it if you're working with binary files. Other systems (esp. Windows) still respect it. – Roddy Oct 16 '12 at 09:56
  • Exactly. I did not add the flag and my utility could not unzip **mp3** or **pdf** files. – Parth Shah Oct 16 '12 at 10:03
  • @Roddy: Yes mate I know. I am looking for a better and more elaborate answer. – Parth Shah Oct 16 '12 at 10:04
  • @Roddy: true, but it means that the presence or not of `b` cannot explain the different behavior that the questioner observed on Linux, "did not unzip" vs "worked perfectly". – Steve Jessop Oct 16 '12 at 10:05

0 Answers0