www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/24/07:28:48

Date: Mon, 24 Jul 2000 13:22:55 +0200 (WET)
From: Andris Pavenis <pavenis AT lanet DOT lv>
To: Jim Smith <jsmith AT ethernet DOT com>
cc: djgpp AT delorie DOT com
Subject: Re: C compiler inserts 0x0d before 0x0a?
In-Reply-To: <397BFC7C.111C0896@ethernet.com>
Message-ID: <Pine.A41.4.05.10007241321430.46712-100000@ieva06.lanet.lv>
MIME-Version: 1.0
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


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 <stdio.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <unistd.h>
> #include <fcntl.h>
> 
> 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!
> 
> 
> 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019