Mail Archives: djgpp/2000/07/24/07:28:48
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 -