Skip to content

Commit 6063ff5

Browse files
committed
Cleanup codes
1 parent df0a3be commit 6063ff5

32 files changed

+205
-286
lines changed

CMakeLists.txt

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ SET(PACKAGE_NAME "libnfc")
1616
SET(PACKAGE_VERSION ${VERSION})
1717
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
1818

19+
SET(C_STANDARD 99)
20+
1921
# config.h
2022
IF(WIN32)
2123
SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
@@ -52,9 +54,7 @@ ENDIF(LIBNFC_ENVVARS)
5254
SET(LIBNFC_DEBUG_MODE OFF CACHE BOOL "Debug mode")
5355
IF(LIBNFC_DEBUG_MODE)
5456
ADD_DEFINITIONS(-DDEBUG)
55-
SET(CMAKE_C_FLAGS "-g3 ${CMAKE_C_FLAGS}")
5657
SET(WIN32_MODE "debug")
57-
SET(CMAKE_RC_FLAGS "-D_DEBUG ${CMAKE_RC_FLAGS}")
5858
ELSE(LIBNFC_DEBUG_MODE)
5959
SET(WIN32_MODE "release")
6060
ENDIF(LIBNFC_DEBUG_MODE)
@@ -93,12 +93,6 @@ IF(NOT DEFINED SHARE_INSTALL_PREFIX)
9393
SET(SHARE_INSTALL_PREFIX share)
9494
ENDIF(NOT DEFINED SHARE_INSTALL_PREFIX)
9595

96-
# Additonnal GCC flags
97-
IF(CMAKE_COMPILER_IS_GNUCC)
98-
# Make sure we will not miss some warnings ;)
99-
SET(CMAKE_C_FLAGS "-Wall -pedantic -std=c99 ${CMAKE_C_FLAGS}")
100-
ENDIF(CMAKE_COMPILER_IS_GNUCC)
101-
10296
# Workarounds for libusb in C99
10397
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
10498

@@ -152,20 +146,20 @@ ENDIF(NOT WIN32)
152146
INCLUDE(LibnfcDrivers)
153147

154148
IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
155-
IF(I2C_REQUIRED)
156-
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
157-
INCLUDE (CheckFunctionExists)
158-
INCLUDE (CheckLibraryExists)
159-
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
160-
IF (NOT HAVE_CLOCK_GETTIME)
161-
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
162-
IF (HAVE_CLOCK_GETTIME_IN_RT)
163-
SET(LIBRT_FOUND TRUE)
164-
SET(LIBRT_LIBRARIES "rt")
165-
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
166-
ENDIF (NOT HAVE_CLOCK_GETTIME)
167-
ENDIF(I2C_REQUIRED)
168-
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
149+
IF(I2C_REQUIRED)
150+
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
151+
INCLUDE (CheckFunctionExists)
152+
INCLUDE (CheckLibraryExists)
153+
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
154+
IF (NOT HAVE_CLOCK_GETTIME)
155+
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
156+
IF (HAVE_CLOCK_GETTIME_IN_RT)
157+
SET(LIBRT_FOUND TRUE)
158+
SET(LIBRT_LIBRARIES "rt")
159+
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
160+
ENDIF (NOT HAVE_CLOCK_GETTIME)
161+
ENDIF(I2C_REQUIRED)
162+
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
169163

170164
IF(PCSC_INCLUDE_DIRS)
171165
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})

contrib/win32/libnfc/buses/uart.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@
4545
#define LOG_GROUP NFC_LOG_GROUP_COM
4646
#define LOG_CATEGORY "libnfc.bus.uart_win32"
4747

48-
// Handle platform specific includes
4948
#include "contrib/windows.h"
50-
#define delay_ms( X ) Sleep( X )
5149

5250
struct serial_port_windows {
5351
HANDLE hPort; // Serial port handle
@@ -143,7 +141,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
143141
// Set baud rate
144142
spw->dcb.BaudRate = uiPortSpeed;
145143
if (!SetCommState(spw->hPort, &spw->dcb)) {
146-
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
144+
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings.");
147145
return;
148146
}
149147
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);

examples/nfc-emulate-forum-tag2.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,8 @@ static uint8_t __nfcforum_tag2_memory_area[] = {
120120
#define READ 0x30
121121
#define WRITE 0xA2
122122
#define SECTOR_SELECT 0xC2
123-
124123
#define HALT 0x50
124+
125125
static int
126126
nfcforum_tag2_io(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len)
127127
{

examples/nfc-emulate-tag.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,7 @@ main(int argc, char *argv[])
189189
(void) argc;
190190
const char *acLibnfcVersion;
191191

192-
#ifdef WIN32
193-
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
194-
#else
195192
signal(SIGINT, intr_hdlr);
196-
#endif
197193

198194
nfc_init(&context);
199195
if (context == NULL) {

examples/nfc-emulate-uid.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,7 @@ main(int argc, char *argv[])
130130
}
131131
}
132132

133-
#ifdef WIN32
134-
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
135-
#else
136133
signal(SIGINT, intr_hdlr);
137-
#endif
138134

139135
nfc_init(&context);
140136
if (context == NULL) {

examples/nfc-poll.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
# include "config.h"
4545
#endif // HAVE_CONFIG_H
4646

47-
#include <err.h>
4847
#include <inttypes.h>
4948
#include <signal.h>
5049
#include <stdio.h>

examples/nfc-relay.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,11 +109,7 @@ main(int argc, char *argv[])
109109
// Display libnfc version
110110
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
111111

112-
#ifdef WIN32
113-
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
114-
#else
115112
signal(SIGINT, intr_hdlr);
116-
#endif
117113

118114
nfc_context *context;
119115
nfc_init(&context);

examples/nfc-st25tb.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,7 @@
6464
#include <string.h>
6565
#include <nfc/nfc.h>
6666

67-
#if defined(WIN32) /* mingw compiler */
68-
#include <getopt.h>
69-
#endif
70-
71-
#define ST25TB_SR_BLOCK_MAX_SIZE ((uint8_t) 4) // for static arrays
67+
#define ST25TB_SR_BLOCK_MAX_SIZE ((size_t) 4) // for static arrays
7268
typedef void(*get_info_specific) (uint8_t * systemArea);
7369

7470
typedef struct _st_data {

examples/pn53x-diagnose.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
# include "config.h"
4444
#endif // HAVE_CONFIG_H
4545

46-
#include <err.h>
4746
#include <stdlib.h>
4847
#include <string.h>
4948

examples/pn53x-tamashell.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,11 @@
5454
#include <ctype.h>
5555
#include <time.h>
5656

57-
#ifndef _WIN32
58-
# include <time.h>
59-
# define msleep(x) do { \
60-
struct timespec xsleep; \
61-
xsleep.tv_sec = x / 1000; \
62-
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
63-
nanosleep(&xsleep, NULL); \
64-
} while (0)
65-
#else
66-
# include <winbase.h>
67-
# define msleep Sleep
68-
#endif
69-
70-
7157
#include <nfc/nfc.h>
7258

7359
#include "utils/nfc-utils.h"
7460
#include "libnfc/chips/pn53x.h"
61+
#include "libnfc/nfc-internal.h"
7562

7663
#define MAX_FRAME_LEN 264
7764

0 commit comments

Comments
 (0)