Date: Mon, 24 Jul 2000 13:22:55 +0200 (WET) From: Andris Pavenis To: Jim Smith cc: djgpp AT delorie DOT com Subject: Re: C compiler inserts 0x0d before 0x0a? In-Reply-To: <397BFC7C.111C0896@ethernet.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On Mon, 24 Jul 2000, Jim Smith wrote: > I just installed the latest djgpp C compiler on my Windows 98 machine, > and I cannot make this simple program work correctly. It is supposed > to simply open a file and write out 5 bytes. It does work correctly > (without any changes) on Linux. The Windows version always inserts a > 0x0d before every 0x0a. On Windows my output file ("junkfile") has a > total of 7 bytes ( two 0x0d bytes added), but on Linux my output file > has a total of 5 bytes, as expected. > > /*-------------------- START OF PROGRAM --------------------*/ > #include > #include > #include > #include > #include > > int main() { > > char myfile[] = "junkfile"; > > int out; > char buf[100]; > > if ((out = open(myfile, O_CREAT | O_WRONLY )) < 0 ) { Open file in binary mode: if ((out = open(myfile, O_CREAT | O_WRONLY | O_BINARY))<0) { > perror(myfile); > exit(1); > } > > buf[0] = 0x61; > buf[1] = 0x0a; > buf[2] = 0x62; > buf[3] = 0x0a; > buf[4] = 0x63; > > write(out, buf, 5); > > close(out); > exit(0); > > } > /* --------------------- END OF PROGRAM --------------------*/ > > Thanks for any and all help! > > >