Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup codes #736

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ SET(PACKAGE_NAME "libnfc")
SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")

SET(CMAKE_C_STANDARD 99)

# config.h
IF(WIN32)
SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
Expand Down Expand Up @@ -52,9 +54,7 @@ ENDIF(LIBNFC_ENVVARS)
SET(LIBNFC_DEBUG_MODE OFF CACHE BOOL "Debug mode")
IF(LIBNFC_DEBUG_MODE)
ADD_DEFINITIONS(-DDEBUG)
SET(CMAKE_C_FLAGS "-g3 ${CMAKE_C_FLAGS}")
SET(WIN32_MODE "debug")
SET(CMAKE_RC_FLAGS "-D_DEBUG ${CMAKE_RC_FLAGS}")
ELSE(LIBNFC_DEBUG_MODE)
SET(WIN32_MODE "release")
ENDIF(LIBNFC_DEBUG_MODE)
Expand Down Expand Up @@ -93,12 +93,6 @@ IF(NOT DEFINED SHARE_INSTALL_PREFIX)
SET(SHARE_INSTALL_PREFIX share)
ENDIF(NOT DEFINED SHARE_INSTALL_PREFIX)

# Additonnal GCC flags
IF(CMAKE_COMPILER_IS_GNUCC)
# Make sure we will not miss some warnings ;)
SET(CMAKE_C_FLAGS "-Wall -pedantic -std=c99 ${CMAKE_C_FLAGS}")
ENDIF(CMAKE_COMPILER_IS_GNUCC)

# Workarounds for libusb in C99
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)

Expand Down Expand Up @@ -152,20 +146,20 @@ ENDIF(NOT WIN32)
INCLUDE(LibnfcDrivers)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(I2C_REQUIRED)
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (NOT HAVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
IF (HAVE_CLOCK_GETTIME_IN_RT)
SET(LIBRT_FOUND TRUE)
SET(LIBRT_LIBRARIES "rt")
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
ENDIF (NOT HAVE_CLOCK_GETTIME)
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(I2C_REQUIRED)
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (NOT HAVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
IF (HAVE_CLOCK_GETTIME_IN_RT)
SET(LIBRT_FOUND TRUE)
SET(LIBRT_LIBRARIES "rt")
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
ENDIF (NOT HAVE_CLOCK_GETTIME)
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(PCSC_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
Expand Down
4 changes: 1 addition & 3 deletions contrib/win32/libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#define LOG_GROUP NFC_LOG_GROUP_COM
#define LOG_CATEGORY "libnfc.bus.uart_win32"

// Handle platform specific includes
#include "contrib/windows.h"
#define delay_ms( X ) Sleep( X )

struct serial_port_windows {
HANDLE hPort; // Serial port handle
Expand Down Expand Up @@ -143,7 +141,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
// Set baud rate
spw->dcb.BaudRate = uiPortSpeed;
if (!SetCommState(spw->hPort, &spw->dcb)) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings.");
return;
}
PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
Expand Down
2 changes: 1 addition & 1 deletion examples/nfc-emulate-forum-tag2.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ static uint8_t __nfcforum_tag2_memory_area[] = {
#define READ 0x30
#define WRITE 0xA2
#define SECTOR_SELECT 0xC2

#define HALT 0x50

static int
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)
{
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-emulate-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ main(int argc, char *argv[])
(void) argc;
const char *acLibnfcVersion;

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_init(&context);
if (context == NULL) {
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-emulate-uid.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ main(int argc, char *argv[])
}
}

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_init(&context);
if (context == NULL) {
Expand Down
1 change: 0 additions & 1 deletion examples/nfc-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
# include "config.h"
#endif // HAVE_CONFIG_H

#include <err.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ main(int argc, char *argv[])
// Display libnfc version
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_context *context;
nfc_init(&context);
Expand Down
6 changes: 1 addition & 5 deletions examples/nfc-st25tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@
#include <string.h>
#include <nfc/nfc.h>

#if defined(WIN32) /* mingw compiler */
#include <getopt.h>
#endif

#define ST25TB_SR_BLOCK_MAX_SIZE ((uint8_t) 4) // for static arrays
#define ST25TB_SR_BLOCK_MAX_SIZE ((size_t) 4) // for static arrays
typedef void(*get_info_specific) (uint8_t * systemArea);

typedef struct _st_data {
Expand Down
1 change: 0 additions & 1 deletion examples/pn53x-diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
# include "config.h"
#endif // HAVE_CONFIG_H

#include <err.h>
#include <stdlib.h>
#include <string.h>

Expand Down
15 changes: 1 addition & 14 deletions examples/pn53x-tamashell.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,11 @@
#include <ctype.h>
#include <time.h>

#ifndef _WIN32
# include <time.h>
# define msleep(x) do { \
struct timespec xsleep; \
xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else
# include <winbase.h>
# define msleep Sleep
#endif


#include <nfc/nfc.h>

#include "utils/nfc-utils.h"
#include "libnfc/chips/pn53x.h"
#include "libnfc/nfc-internal.h"

#define MAX_FRAME_LEN 264

Expand Down
2 changes: 1 addition & 1 deletion libnfc/buses/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <termios.h>
Expand Down
1 change: 0 additions & 1 deletion libnfc/buses/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
Expand Down
22 changes: 3 additions & 19 deletions libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@
#define LOG_GROUP NFC_LOG_GROUP_COM
#define LOG_CATEGORY "libnfc.bus.uart"

#ifndef _WIN32
// Needed by sleep() under Unix
# include <unistd.h>
# include <time.h>
# define msleep(x) do { \
struct timespec xsleep; \
xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else
// Needed by Sleep() under Windows
# include <winbase.h>
# define msleep Sleep
#endif

# if defined(__APPLE__)
const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial", "tty.usbmodem", NULL };
# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__)
Expand Down Expand Up @@ -233,7 +217,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed)
cfsetispeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
cfsetospeed(&(UART_DATA(sp)->termios_new), stPortSpeed);
if (tcsetattr(UART_DATA(sp)->fd, TCSADRAIN, &(UART_DATA(sp)->termios_new)) == -1) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings.");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings.");
}
}

Expand Down Expand Up @@ -338,13 +322,13 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i
}
// Read time-out
if (res == 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Timeout!");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeout!");
return NFC_ETIMEOUT;
}

if (FD_ISSET(iAbortFd, &rfds)) {
// Abort requested
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Abort!");
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Abort!");
close(iAbortFd);
return NFC_EOPABORTED;
}
Expand Down
Loading