It is not portable to use "std{in,out}" as "lvalues" (for instance, building under Sun Solaris breaks here). The portable solution is to use freopen(3). Unfortunately, to achieve the same effect than fdopen(3) on "std{in,out}", one has to use "/dev/std{in,out}" (which in turn is not really portable, but at least more portable than using "std{in,out}" as "lvalues"). The only "we know it better" alternative would be to just replace the code with a fflush(3) on the streams and know that the stream has not recognized the changed underlying filedescriptor. But this again is not really portable, although also working for mostly all Unix platforms. --- filter.c.orig 2003-03-25 17:39:08.000000000 +0100 +++ filter.c 2003-07-24 10:05:02.000000000 +0200 @@ -158,10 +158,10 @@ int r; /* setup streams again */ - if ((stdin = fdopen (0, "r")) == NULL) - flexfatal (_("fdopen(0) failed")); - if ((stdout = fdopen (1, "w")) == NULL) - flexfatal (_("fdopen(1) failed")); + if ((freopen ("/dev/stdin", "r", stdin)) == NULL) + flexfatal (_("freopen(stdin) failed")); + if ((freopen ("/dev/stdout", "w", stdout)) == NULL) + flexfatal (_("freopen(stdout) failed")); if ((r = chain->filter_func (chain)) == -1) flexfatal (_("filter_func failed")); @@ -181,8 +181,8 @@ if (dup2 (pipes[1], 1) == -1) flexfatal (_("dup2(pipes[1],1)")); close (pipes[1]); - if ((stdout = fdopen (1, "w")) == NULL) - flexfatal (_("fdopen(1) failed")); + if ((freopen ("/dev/stdout", "w", stdout)) == NULL) + flexfatal (_("freopen(stdout) failed")); return true; } Our package does not rely on GCC (and cannot for dependency reasons), so we have to make sure that no C99 style comments are used inside the code. --- main.c.orig Tue Apr 1 03:51:38 2003 +++ main.c Tue Jul 29 22:27:40 2003 @@ -1142,7 +1142,6 @@ break; case OPT_NO_UNISTD_H: - //buf_strdefine (&userdef_buf, "YY_NO_UNISTD_H", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNISTD_H",0); break; @@ -1257,7 +1256,6 @@ break; case OPT_STACK: - //buf_strdefine (&userdef_buf, "YY_STACK_USED", "1"); buf_m4_define( &m4defs_buf, "M4_YY_STACK_USED",0); break; @@ -1314,87 +1312,66 @@ break; case OPT_NO_YY_PUSH_STATE: - //buf_strdefine (&userdef_buf, "YY_NO_PUSH_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_PUSH_STATE",0); break; case OPT_NO_YY_POP_STATE: - //buf_strdefine (&userdef_buf, "YY_NO_POP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_POP_STATE",0); break; case OPT_NO_YY_TOP_STATE: - //buf_strdefine (&userdef_buf, "YY_NO_TOP_STATE", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_TOP_STATE",0); break; case OPT_NO_UNPUT: - //buf_strdefine (&userdef_buf, "YY_NO_UNPUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_UNPUT",0); break; case OPT_NO_YY_SCAN_BUFFER: - //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BUFFER", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BUFFER",0); break; case OPT_NO_YY_SCAN_BYTES: - //buf_strdefine (&userdef_buf, "YY_NO_SCAN_BYTES", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_BYTES",0); break; case OPT_NO_YY_SCAN_STRING: - //buf_strdefine (&userdef_buf, "YY_NO_SCAN_STRING", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SCAN_STRING",0); break; case OPT_NO_YYGET_EXTRA: - //buf_strdefine (&userdef_buf, "YY_NO_GET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_EXTRA",0); break; case OPT_NO_YYSET_EXTRA: - //buf_strdefine (&userdef_buf, "YY_NO_SET_EXTRA", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_EXTRA",0); break; case OPT_NO_YYGET_LENG: - //buf_strdefine (&userdef_buf, "YY_NO_GET_LENG", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LENG",0); break; case OPT_NO_YYGET_TEXT: - //buf_strdefine (&userdef_buf, "YY_NO_GET_TEXT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_TEXT",0); break; case OPT_NO_YYGET_LINENO: - //buf_strdefine (&userdef_buf, "YY_NO_GET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LINENO",0); break; case OPT_NO_YYSET_LINENO: - //buf_strdefine (&userdef_buf, "YY_NO_SET_LINENO", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LINENO",0); break; case OPT_NO_YYGET_IN: - //buf_strdefine (&userdef_buf, "YY_NO_GET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_IN",0); break; case OPT_NO_YYSET_IN: - //buf_strdefine (&userdef_buf, "YY_NO_SET_IN", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_IN",0); break; case OPT_NO_YYGET_OUT: - //buf_strdefine (&userdef_buf, "YY_NO_GET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_OUT",0); break; case OPT_NO_YYSET_OUT: - //buf_strdefine (&userdef_buf, "YY_NO_SET_OUT", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_OUT",0); break; case OPT_NO_YYGET_LVAL: - //buf_strdefine (&userdef_buf, "YY_NO_GET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LVAL",0); break; case OPT_NO_YYSET_LVAL: - //buf_strdefine (&userdef_buf, "YY_NO_SET_LVAL", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LVAL",0); break; case OPT_NO_YYGET_LLOC: - //buf_strdefine (&userdef_buf, "YY_NO_GET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_GET_LLOC",0); break; case OPT_NO_YYSET_LLOC: - //buf_strdefine (&userdef_buf, "YY_NO_SET_LLOC", "1"); buf_m4_define( &m4defs_buf, "M4_YY_NO_SET_LLOC",0); break; @@ -1547,7 +1524,6 @@ if (reject){ out_m4_define( "M4_YY_USES_REJECT", NULL); - //outn ("\n#define YY_USES_REJECT"); } if (!do_yywrap) { --- tables.c.orig Wed Nov 27 15:43:24 2002 +++ tables.c Tue Jul 29 22:28:18 2003 @@ -86,7 +86,7 @@ th->th_magic = YYTBL_MAGIC; th->th_hsize = 14 + strlen (version_str) + 1 + strlen (name) + 1; th->th_hsize += yypad64 (th->th_hsize); - th->th_ssize = 0; // Not known at this point. + th->th_ssize = 0; th->th_flags = 0; th->th_version = copy_string (version_str); th->th_name = copy_string (name);