Improve C99 compliance. by dbaarda · Pull Request #182 · librsync/librsync

added 12 commits

November 25, 2019 14:56
It looks like some tabs crept in at some point.
C99 doesn't like anonymous unions or returning void function calls.
C99 doesn't like initializing char arrays from expressions. Brackets around a
string literal make it into an expression, so they had to go.
In CMakeLists.txt add "-pedantic" to CMAKE_C_FLAGS for gcc/clang to enable
stricter C99 compiling. Add checks for symbols __func__ and __FUNCTION__.

In src/config.h.cmake add cmakedefine's for HAVE___FUNC__ and
HAVE___FUNCTION__. Remove unimplemented FIXME defines for C99 standards const,
off_t, and size_t.

In src/trace.[ch] remove all support for compilers without C99's macro varargs
support. Add support for platforms with __FUNCTION__ instead of __func__. Use
C99 macro varargs instead of GNU named varargs and simplify macros.
In CMakeList.txt and src/config.h.cmake remove support for unused alloca
function, including HAVE_ALLOCA_H, HAVE_ALLOCA, CRAY_STACKSEG_END, C_ALLOCA,
and STACK_DIRECTION.

In src/config.h.cmake remove unused and unchecked or not working cmakedefines
for HAVE_LIBBZ2, HAVE_LIBPOPT, HAVE_LIBZ, HAVE_SNPRINTF, HAVE_VARARG_MACROS,
HAVE_VSNPRINTF, HAVE__SNPRINTF, and HAVE__VSNPRINTF. The HAVE_LIB* ones were
just broken and unused. The others were unchecked, unused, and for standard
C99 features we assume exist in the code.
In CMakeLists.txt and src/config.h.cmake remove HAVE_PROGRAM_INVOCATION_NAME.

In src/trace.c remove conditional use of program_invocation_short_name. This
was unused because we never checked/set HAVE_PROGRAM_INVOCATION_NAME.
We never used these HAVE_* defines and just assumed the features existed
anyway. Also put the checks and cmakedefines into the same order.
This makes the cmakedefines in src/config.h.cmake reflect the order of checks
in CMakeLists.txt. It also removes the obsolete STDC_HEADERS define.
For non-GNUC compatible compilers #define away __attribute__. For compilers
without __func__ or __FUNCTION__ use an empty string. Make logging use
RS_LOG_NONAME format when __func__ is an empty string. Use C99 fputs() instead
of Unix/Posix write(). Prune and tidy imports to only what's needed.
The docs for some of the stat() variants suggest sys/types.h is needed, so
best to import it incase it's actually needed on some platforms.
This removes all not-required #include statements, including some non-C99
headers, and re-arranges them into more consistent order.

@dbaarda

…VE_UINT64.

We have not been setting HAVE_UINT64 which means we've not been using 64bit
support for calculating md4sums. Checking that the C99 stdint.h's UINT64_MAX
is defined is the best way of checking that the uint64_t type exists on the
target platform.

@dbaarda