]> granicus.if.org Git - flex/commit
scanner: Fix glibc features.h dependency in skeleton.
authorExplorer09 <explorer09@gmail.com>
Thu, 8 Mar 2018 02:04:36 +0000 (10:04 +0800)
committerExplorer09 <explorer09@gmail.com>
Thu, 8 Mar 2018 02:04:36 +0000 (10:04 +0800)
commit4081efa0831b15d7e4e4255401c225ad8262426d
tree280c0a7bd8280927347d5f92cf7b89618e7d79c6
parentd5023f5a48ac477916d43453a16afd792f422e85
scanner: Fix glibc features.h dependency in skeleton.

Commit a17d79e9c722a6735b6d2a8f152287404f27df32 defines _POSIX_C_SOURCE
to the minimum of 1 if it's not defined in the user's scanner code or
the compiling environment. However in glibc the macros are not yet set
up until one of the libc headers is included. This unfortunately have
made us overwrite the default _POSIX_C_SOURCE value that would be
defined by glibc (200809L at the time of writing), causing regressions
in user code.

Now in this patch:
1. Ensure feature test macros have been set up in glibc before checking
or defining any of them in our skeleton code.
2. Have a more conservative logic when determining the need to define
_POSIX_C_SOURCE (required for fileno()).

Fixes: #313
Note:
It could be tricky for application code to ensure feature test macros
have been set up in glibc, since <features.h> is no portable header and
not meant to be included directly by applications. The way to do it is
to include a libc header which in turn includes <features.h>. However,
many of the glibc headers check __USE_POSIX (a glibc internal macro
defined if _POSIX_C_SOURCE is defined) and determine which interfaces
to expose already, making the headers inappropriate for our goal.
Those which don't depend on _POSIX_C_SOURCE, and are also available
since ANSI C89, are only <assert.h>, <errno.h> and <math.h>.

<assert.h> is finally favored due to other considerations:
- <math.h> check for __USE_XOPEN in glibc, making a dependency on
_XOPEN_SOURCE, besides it exposes much more interfaces than we need.
- In djgpp, <errno.h> depends on _POSIX_SOURCE to hide definitions of
some errno values when it's defined.
- <assert.h> exposes the fewest interfaces among the 3 headers and, at
the time of writing, checks for only C99 (for __func__), C11 (for
_Static_assert), and _GNU_SOURCE when needed.

Signed-off-by: Kang-Che Sung <explorer09@gmail.com>
src/flex.skl