Reputation: 3611
The following flex file gives output that does not exit with a nonzero status when it encounters an error, like trying to write to /dev/full:
WS [ \t]+
%option noyywrap
%{
#include <stdio.h>
#include <stdlib.h>
int output(const char *);
%}
newline (\r|\n|\r\n|\n\r)
%%
#[^\r\n]*/{newline} {};
[^#]+ { output(yytext); }
<<EOF>> { output(yytext); return 0; }
%%
int main (void) {
while (yylex()) ;
return errno;
}
int output(const char *string)
{
int error;
if (fputs(string, stdout) == EOF ){
error = errno;
fprintf(stderr, "Output error: %s\n", strerror(error));
exit(errno);
}
return 0;
}
How do I fix this?
Upvotes: 0
Views: 84
Reputation: 3611
The problem was that I was not flushing stdout. Due to buffering, the printf succeeded, but the fflush failed.
Upvotes: 1