Skip to content

Commit

Permalink
Make it compile under MSVC2017.
Browse files Browse the repository at this point in the history
  • Loading branch information
puppywang authored and gelotus committed Jul 4, 2020
1 parent 66d3560 commit 82f23c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 8 deletions.
2 changes: 2 additions & 0 deletions contrib/windows.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@
# define ENOTSUP WSAEOPNOTSUPP
# define ECONNABORTED WSAECONNABORTED
# else
#if !defined(_MSC_VER) || (_MSC_VER < 1910) // VS2017 don't like snprintf macro
# define snprintf sprintf_s
#endif
# define strdup _strdup
# endif

Expand Down
20 changes: 13 additions & 7 deletions libnfc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ IF(WIN32)

# Add in the rc for version information in the dll
LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_BINARY_DIR}/../windows/libnfc.rc)
IF (NOT MINGW)
LIST(APPEND WINDOWS_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc_msvc.def)
ENDIF()
ENDIF(WIN32)

# Library's chips
Expand Down Expand Up @@ -88,13 +91,16 @@ SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 6 VERSION 6.0.0)
IF(WIN32)
# Libraries that are windows specific
TARGET_LINK_LIBRARIES(nfc wsock32)

ADD_CUSTOM_COMMAND(
OUTPUT libnfc.lib
COMMAND ${DLLTOOL} -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def
)
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
IF(MINGW)
ADD_CUSTOM_COMMAND(
OUTPUT libnfc.lib
COMMAND ${DLLTOOL} -d ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def -l ${CMAKE_CURRENT_BINARY_DIR}/libnfc.lib ${CMAKE_CURRENT_BINARY_DIR}/libnfc.dll
DEPENDS nfc ${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32/nfc.def
)
ADD_CUSTOM_TARGET(win32lib ALL DEPENDS libnfc.lib)
ELSE()
ADD_LIBRARY(win32lib ALIAS nfc)
ENDIF()

# On Windows the shared (runtime) library should be either in the same
# directory as the excutables or in the path, we add it to same directory
Expand Down
2 changes: 2 additions & 0 deletions libnfc/buses/uart.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@
#ifndef __NFC_BUS_UART_H__
# define __NFC_BUS_UART_H__

#if !defined(_MSC_VER)
# include <sys/time.h>
#endif

# include <stdio.h>
# include <string.h>
Expand Down
2 changes: 2 additions & 0 deletions libnfc/nfc-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@

#include <stdbool.h>
#include <err.h>
#if !defined(_MSC_VER)
# include <sys/time.h>
#endif

#include "nfc/nfc.h"

Expand Down
4 changes: 3 additions & 1 deletion libnfc/nfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ nfc_initiator_select_passive_target(nfc_device *pnd,
nfc_target *pnt)
{
uint8_t *abtInit = NULL;
uint8_t abtTmpInit[MAX(12, szInitData)];
uint8_t *abtTmpInit = malloc(MAX(12, szInitData));
size_t szInit = 0;
int res;
if ((res = nfc_device_validate_modulation(pnd, N_INITIATOR, &nm)) != NFC_SUCCESS)
Expand All @@ -583,6 +583,8 @@ nfc_initiator_select_passive_target(nfc_device *pnd,
}

HAL(initiator_select_passive_target, pnd, nm, abtInit, szInit, pnt);

free(abtTmpInit);
}

/** @ingroup initiator
Expand Down

0 comments on commit 82f23c4

Please sign in to comment.