Skip to content

Commit 657b9fa

Browse files
authored
netbsd: check if iconv(3) requires pointer-to-const as libusb does (#779)
The iconv(3) prototype has been changed since NetBSD 10 to sync with the standard: https://man.netbsd.org/NetBSD-10.0/iconv.3#STANDARDS
1 parent 7e994d8 commit 657b9fa

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

netbsd/CMakeLists.txt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,16 @@ find_package(Threads REQUIRED)
1010

1111
target_link_libraries(hidapi_netbsd PRIVATE Threads::Threads)
1212

13+
# check for error: "conflicting types for 'iconv'"
14+
include(CheckCSourceCompiles)
15+
check_c_source_compiles("#include<iconv.h>
16+
extern size_t iconv (iconv_t cd, const char **inbuf, size_t *inbytesleft, char **outbuf, size_t *outbytesleft);
17+
int main() {}"
18+
HIDAPI_ICONV_CONST)
19+
if(HIDAPI_ICONV_CONST)
20+
target_compile_definitions(hidapi_netbsd PRIVATE "ICONV_CONST=const")
21+
endif()
22+
1323
set_target_properties(hidapi_netbsd
1424
PROPERTIES
1525
EXPORT_NAME "netbsd"

netbsd/hid.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include <unistd.h>
3131
#include <fcntl.h>
3232
#include <iconv.h>
33+
#ifndef ICONV_CONST
34+
#define ICONV_CONST
35+
#endif
36+
3337
#include <poll.h>
3438

3539
/* NetBSD */
@@ -1098,7 +1102,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
10981102
struct usb_string_desc usd;
10991103
usb_string_descriptor_t *str;
11001104
iconv_t ic;
1101-
const char *src;
1105+
ICONV_CONST char *src;
11021106
size_t srcleft;
11031107
char *dst;
11041108
size_t dstleft;
@@ -1142,7 +1146,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
11421146
return -1;
11431147
}
11441148

1145-
src = (const char *) str->bString;
1149+
src = (ICONV_CONST char *)str->bString;
11461150
srcleft = str->bLength - 2;
11471151
dst = (char *) string;
11481152
dstleft = sizeof(wchar_t[maxlen]);

0 commit comments

Comments
 (0)