Mail Archives: djgpp/2000/07/29/19:15:50
Uwe Bonnes wrote:
> Welcome to the wonderfull world of DOS CR/LF linebreaks.
>
> If you write out a text file on dos, you will get those CR/LF endings.
>
> Open with O_BINARY to circumvent.
Thanks to those who replied with the above suggestion. However, it still
does not work. As shown below, I simply added the O_BINARY word to the file
open, but the extra bytes (0x0d) are still inserted into the output file.
I'm lost. Thanks for any help.
-------------------------- 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 | 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);
}
- Raw text -