delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/07/24/05:45:31

Message-ID: <397BFC7C.111C0896@ethernet.com>
From: Jim Smith <jsmith AT ethernet DOT com>
X-Mailer: Mozilla 4.73 [en] (Win98; I)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: C compiler inserts 0x0d before 0x0a?
Lines: 44
Date: Mon, 24 Jul 2000 01:21:16 -0700
NNTP-Posting-Host: 216.101.0.2
X-Complaints-To: abuse AT pacbell DOT net
X-Trace: news.pacbell.net 964426855 216.101.0.2 (Mon, 24 Jul 2000 01:20:55 PDT)
NNTP-Posting-Date: Mon, 24 Jul 2000 01:20:55 PDT
Organization: SBC Internet Services
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 ) {
      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