문제

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?

도움이 되었습니까?

해결책

The problem was that I was not flushing stdout. Due to buffering, the printf succeeded, but the fflush failed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top