Skip to content

Commit 7c6eea2

Browse files
committed
Windows: json-c 0.17 compatibility with ssize_t type definition
json-c 0.17 defines the ssize_t type using a typedef on Windows. We have been setting ssize_t for Windows to a different type using a #define instead of a typedef. We should have been using a typedef since it is a type. However, we must also match the exact type they're setting it to or else the compiler will baulk because the types are different. Note: in C11, it's fine to use typedef the same type more than once, so long as you're defining it the same every time.
1 parent 68944dd commit 7c6eea2

3 files changed

Lines changed: 24 additions & 7 deletions

File tree

CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -676,13 +676,13 @@ check_type_size("ssize_t" SIZEOF_SSIZE_T)
676676
if(SIZEOF_SSIZE_T STREQUAL "")
677677
# ssize_t is a signed type in POSIX storing at least -1.
678678
# Set it to "int" to match the behavior of AC_TYPE_SSIZE_T (autotools).
679-
set(ssize_t int)
679+
set(SSIZE_T_DEF "typedef int ssize_t;")
680680
endif()
681681
check_type_size("off_t" SIZEOF_OFF_T)
682682
if(SIZEOF_OFF_T STREQUAL "")
683683
# off_t is a signed type in POSIX no narrower than int.
684684
# Set it to "long int" to match the behavior of AC_TYPE_OFF_T (autotools).
685-
set(off_t long int)
685+
set(OFF_T_DEF "typedef long int off_t;")
686686
endif()
687687

688688
check_type_size("int" SIZEOF_INT)

clamav-config.h.cmake.in

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -590,11 +590,22 @@
590590
#define inline @INLINE_KEYWORD@
591591
#endif
592592

593-
/* Define to `long int' if <sys/types.h> does not define. */
594-
#cmakedefine off_t @off_t@
595-
596593
/* Define to `int' if <sys/types.h> does not define. */
597-
#cmakedefine ssize_t @ssize_t@
594+
#ifndef SSIZE_T_DEFINED
595+
#if defined(_MSC_VER)
596+
#include <BaseTsd.h>
597+
typedef SSIZE_T ssize_t;
598+
#else
599+
@SSIZE_T_DEF@
600+
#endif
601+
# define SSIZE_T_DEFINED
602+
#endif
603+
604+
/* Define to `long int' if <sys/types.h> does not define. */
605+
#ifndef OFF_T_DEFINED
606+
@OFF_T_DEF@
607+
#define OFF_T_DEFINED
608+
#endif
598609

599610
/* Define to the equivalent of the C99 'restrict' keyword, or to
600611
nothing if this is not supported. Do not define if restrict is

win32/compat/net.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,15 @@
2424

2525
/* Don't include clamav-config.h, because that brings in platform.h
2626
and platform.h will make these functions recursive ;-). */
27-
#ifndef ssize_t
27+
#ifndef SSIZE_T_DEFINED
28+
#if defined(_MSC_VER)
29+
#include <BaseTsd.h>
30+
typedef SSIZE_T ssize_t;
31+
#else
2832
typedef int ssize_t;
2933
#endif
34+
#define SSIZE_T_DEFINED
35+
#endif
3036

3137
#define F_GETFL 1
3238
#define F_SETFL 2

0 commit comments

Comments
 (0)