Skip to content

Commit 2e9ff47

Browse files
committed
netbsd: check if iconv(3) requires pointer-to-const as libusb does
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 55aab02 commit 2e9ff47

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 */
@@ -1087,7 +1091,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
10871091
struct usb_string_desc usd;
10881092
usb_string_descriptor_t *str;
10891093
iconv_t ic;
1090-
const char *src;
1094+
ICONV_CONST char *src;
10911095
size_t srcleft;
10921096
char *dst;
10931097
size_t dstleft;
@@ -1131,7 +1135,7 @@ int HID_API_EXPORT_CALL hid_get_indexed_string(hid_device *dev, int string_index
11311135
return -1;
11321136
}
11331137

1134-
src = (const char *) str->bString;
1138+
src = (ICONV_CONST char *)str->bString;
11351139
srcleft = str->bLength - 2;
11361140
dst = (char *) string;
11371141
dstleft = sizeof(wchar_t[maxlen]);

0 commit comments

Comments
 (0)