Skip to content

Commit

Permalink
Try using _setmode() in Windows
Browse files Browse the repository at this point in the history
Gross, but seems to be only way to be able to write linefeed to stdout.
  • Loading branch information
hackerb9 committed Jul 16, 2024
1 parent 8725916 commit 064488d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion m100-tokenize-main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@
*/

/* To be able to write '\n' to stdout as '\n' instead of '\n\r'. */
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif

int main(int argc, char *argv[]) {

Expand All @@ -34,7 +39,15 @@ int main(int argc, char *argv[]) {
++argv, --argc;
yyout = (argc>0) ? fopen( argv[0], "wb+" ) : stdout;
if (yyout == NULL) { perror(argv[0]); exit(1); }


/* MS-DOS & Windows prepend a CR before every LF */
#ifdef _WIN32
if ( _setmode(fileno(stdout), O_BINARY) == -1 ) {
perror("_setmode to binary failed");
return(1);
}
#endif

while (yylex())
;
return 0;
Expand Down

0 comments on commit 064488d

Please sign in to comment.