Skip to content

Commit

Permalink
Try using _setmode() in Windows
Browse files Browse the repository at this point in the history
Yucky.
  • Loading branch information
hackerb9 committed Jul 16, 2024
1 parent b62de39 commit 6c5fe30
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions 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 @@ -31,10 +36,18 @@ int main(int argc, char *argv[]) {

/* Second arg (if any) is output file name */
++argv, --argc;
if (argc>0) freopen( argv[0], "wb+", stdout );
yyout = stdout;
if (argc>0) yyout = fopen( argv[0], "wb+" );
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 6c5fe30

Please sign in to comment.