Skip to content

flex.skl calls fileno(), which is not ISO C99 function #263

@Explorer09

Description

@Explorer09

I caught this warning when building flex in -std=c99 mode:

./stage1flex   -o stage1scan.c ./scan.l
  CC       flex-stage1scan.o
stage1scan.c: In function ‘yy_init_buffer’:
stage1scan.c:4757:48: warning: implicit declaration of function ‘fileno’; did you mean ‘mblen’? [-Wimplicit-function-declaration]
         b->yy_is_interactive = file ? (isatty( fileno(file) ) > 0) : 0;
                                                ^~~~~~
                                                mblen

In glibc, fileno() prototype is exposed only if _POSIX_C_SOURCE is defined to >= 1. Although flex will build with _GNU_SOURCE defined (AC_USE_SYSTEM_EXTENSIONS in configure script), the problem is that generated scanners may not build if the user's environment requires strict ISO C99, and I consider this a bug.

So this issue report is about two things:

  1. The #define _POSIX_C_SOURCE 1 is missing in flex.skl when the scanner is specified neither always-interactive or never-interactive option.
  2. We didn't document that we use POSIX functions to detect whether the input is "interactive", and so brings surprise to users that expect it builds in non-POSIX environments.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions