build: Prepare config.h for inclusion in examples/tests

There are certain games played in the examples and tests source to
account for differences in build environments and target platforms. This
can be simplified by including config.h and using the definitions there.

To that end, move the printf function attribute definition from
libusbi.h to config.h and leverage it where it is used in the examples
and tests.

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
This commit is contained in:
Chris Dickens 2020-11-27 15:22:29 -08:00
parent 9d23ed25b4
commit f2e551a5ff
44 changed files with 82 additions and 45 deletions

View file

@ -29,5 +29,9 @@
/* Define to 1 if compiling for a POSIX platform. */
#define PLATFORM_POSIX 1
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
/* Enable GNU extensions. */
#define _GNU_SOURCE 1

View file

@ -44,6 +44,10 @@
/* Define to 1 if compiling for a POSIX platform. */
#define PLATFORM_POSIX 1
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) __attribute__ ((__format__ (__printf__, a, b)))
/* Define to 1 to output logging messages to the systemwide log. */
#define USE_SYSTEM_LOGGING_FACILITY 1

View file

@ -67,6 +67,7 @@ CFLAGS="${saved_CFLAGS}"
AC_DEFINE([_GNU_SOURCE], [1], [Enable GNU extensions.])
AC_DEFINE([DEFAULT_VISIBILITY], [__attribute__ ((visibility ("default")))], [Define to the attribute for default visibility.])
AC_DEFINE([PRINTF_FORMAT(a, b)], [__attribute__ ((__format__ (__printf__, a, b)))], [Define to the attribute for enabling parameter checks on printf-like functions.])
create_import_lib=
is_android_linux=

View file

@ -20,6 +20,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdio.h>
#include <errno.h>
#include <stdlib.h>
@ -29,9 +32,6 @@
#include "libusb.h"
#include "ezusb.h"
extern void logerror(const char *format, ...)
__attribute__ ((format(printf, 1, 2)));
/*
* This file contains functions for uploading firmware into Cypress
* EZ-USB microcontrollers. These chips use control endpoint 0 and vendor

View file

@ -21,12 +21,7 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#if defined(_MSC_VER)
#define __attribute__(x)
#if defined(_PREFAST_)
#pragma warning(disable:28193)
#endif
#endif
#include <config.h>
#include <stdbool.h>
@ -105,6 +100,8 @@ extern int ezusb_load_eeprom(libusb_device_handle *device,
/* Verbosity level (default 1). Can be increased or decreased with options v/q */
extern int verbose;
extern void logerror(const char *format, ...) PRINTF_FORMAT(1, 2);
#ifdef __cplusplus
}
#endif

View file

@ -21,6 +21,8 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
#include <config.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
@ -47,9 +49,6 @@ static bool dosyslog = false;
#define ARRAYSIZE(A) (sizeof(A)/sizeof((A)[0]))
#endif
void logerror(const char *format, ...)
__attribute__ ((format (__printf__, 1, 2)));
void logerror(const char *format, ...)
{
va_list ap;

View file

@ -101,16 +101,6 @@
*/
#define API_EXPORTED LIBUSB_CALL DEFAULT_VISIBILITY
/* Macro to decorate printf-like functions, in order to get
* compiler warnings about format string mistakes.
*/
#ifndef _MSC_VER
#define USBI_PRINTFLIKE(formatarg, firstvararg) \
__attribute__ ((__format__ (__printf__, formatarg, firstvararg)))
#else
#define USBI_PRINTFLIKE(formatarg, firstvararg)
#endif
#ifdef __cplusplus
extern "C" {
#endif
@ -292,7 +282,7 @@ int usbi_vsnprintf(char *dst, size_t size, const char *format, va_list args);
#endif /* defined(_MSC_VER) && (_MSC_VER < 1900) */
void usbi_log(struct libusb_context *ctx, enum libusb_log_level level,
const char *function, const char *format, ...) USBI_PRINTFLIKE(4, 5);
const char *function, const char *format, ...) PRINTF_FORMAT(4, 5);
#define _usbi_log(ctx, level, ...) usbi_log(ctx, level, __func__, __VA_ARGS__)

View file

@ -1 +1 @@
#define LIBUSB_NANO 11576
#define LIBUSB_NANO 11577

View file

@ -50,5 +50,9 @@
/* Define to 1 if compiling for a Windows platform. */
#define PLATFORM_WINDOWS 1
/* Define to the attribute for enabling parameter checks on printf-like
functions. */
#define PRINTF_FORMAT(a, b) /**/
/* Define to 1 to output logging messages to the systemwide log. */
/* #undef USE_SYSTEM_LOGGING_FACILITY */

View file

@ -73,6 +73,7 @@
<ClCompile Include="..\examples\fxload.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\examples\ezusb.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\examples\ezusb.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -73,6 +73,7 @@
<ClCompile Include="..\examples\fxload.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\examples\ezusb.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\examples\ezusb.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -92,6 +92,7 @@
<ClCompile Include="..\examples\fxload.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\examples\ezusb.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\examples\ezusb.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -92,6 +92,7 @@
<ClCompile Include="..\examples\fxload.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\examples\ezusb.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\examples\ezusb.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -45,7 +45,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -46,7 +46,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -45,7 +45,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -46,7 +46,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -73,6 +73,7 @@
<ClCompile Include="..\tests\testlib.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\tests\libusb_testlib.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\tests\libusb_testlib.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -73,6 +73,7 @@
<ClCompile Include="..\tests\testlib.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\tests\libusb_testlib.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\tests\libusb_testlib.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -92,6 +92,7 @@
<ClCompile Include="..\tests\testlib.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\tests\libusb_testlib.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\tests\libusb_testlib.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -92,6 +92,7 @@
<ClCompile Include="..\tests\testlib.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h" />
<ClInclude Include="..\tests\libusb_testlib.h" />
</ItemGroup>
<ItemGroup>

View file

@ -11,6 +11,9 @@
</Filter>
</ItemGroup>
<ItemGroup>
<ClInclude Include=".\config.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\tests\libusb_testlib.h">
<Filter>Header Files</Filter>
</ClInclude>

View file

@ -45,7 +45,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -46,7 +46,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -45,7 +45,7 @@
</PropertyGroup>
<ItemDefinitionGroup>
<ClCompile>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -46,7 +46,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -65,7 +65,7 @@
<ItemDefinitionGroup>
<ClCompile>
<AdditionalOptions>/utf-8 %(AdditionalOptions)</AdditionalOptions>
<AdditionalIncludeDirectories>..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>.;..\libusb;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>_CONSOLE;_CRT_SECURE_NO_WARNINGS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<WarningLevel>Level3</WarningLevel>
</ClCompile>

View file

@ -20,6 +20,8 @@
#ifndef LIBUSB_TESTLIB_H
#define LIBUSB_TESTLIB_H
#include <config.h>
/** Values returned from a test function to indicate test result */
typedef enum {
/** Indicates that the test ran successfully. */
@ -36,7 +38,7 @@ typedef enum {
/**
* Logs some test information or state
*/
void libusb_testlib_logf(const char *fmt, ...);
void libusb_testlib_logf(const char *fmt, ...) PRINTF_FORMAT(1, 2);
/**
* Structure holding a test description.

View file

@ -17,6 +17,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include <config.h>
#include <string.h>
#include "libusb.h"

View file

@ -17,7 +17,7 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "libusb_testlib.h"
#include <config.h>
#include <errno.h>
#include <stdarg.h>
@ -25,10 +25,12 @@
#include <stdio.h>
#include <string.h>
#if defined(_WIN32)
#define NULL_PATH "nul"
#else
#include "libusb_testlib.h"
#if defined(PLATFORM_POSIX)
#define NULL_PATH "/dev/null"
#elif defined(PLATFORM_WINDOWS)
#define NULL_PATH "nul"
#endif
/**