Since Clang 15 (which still is under development, so this may
still change before it's released) [1], implicit function
declarations are a hard error by default, when building code
in C99 mode (or newer).
[1] 7d644e1215
The upstream zvbi code doesn't seem to have any support for
building for Windows at all, therefore not trying to upstream it.
On Windows, the <io.h> header is needed for getting declarations
of functions like open/read/write/close. The zvbi project has a
header of its own, named io.h, and it resides on a path added with
-I, so any includes of <io.h> ends up including this header instead
of the system header. Therefore, add an #include_next <io.h> which
should bring in the system header and its declarations too.
Adjust ifdefs to ifdef out larger bits of the code that contained
calls to functions that simply don't exist on Windows, like
ioctl, munmap etc. Previously, the zvbi library has been built with
implicit declarations of those functions, and the static library has
had undefined references to them. As long as those object files
from the static library haven't been included in the link, this issue
has been unnoticed so far.
For the function ffs(), which also was undefined on Windows,
provide a _BitScanForward based reimplementation. This also resides
in a file that doesn't end up included in the end, but for this
case it's just as easy to provide a working implementation as it
would be to ifdef it out.
(cherry picked from commit 68efd7e558)