Improve C99 compliance. by dbaarda · Pull Request #182 · librsync/librsync
added 12 commits
November 25, 2019 14:56C99 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.
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters