|
| 1 | +$NetBSD$ |
| 2 | + |
| 3 | +Fix iconv usage on SunOS and older NetBSD. |
| 4 | + |
| 5 | +--- libi3/ucs2_conversion.c.orig 2026-02-06 07:30:55.000000000 +0000 |
| 6 | ++++ libi3/ucs2_conversion.c |
| 7 | +@@ -12,6 +12,15 @@ |
| 8 | + #include <stdlib.h> |
| 9 | + #include <string.h> |
| 10 | + |
| 11 | ++#if defined(__NetBSD__) |
| 12 | ++#include <sys/param.h> |
| 13 | ++#if __NetBSD_Prereq__(9,99,17) |
| 14 | ++#define NETBSD_POSIX_ICONV 1 |
| 15 | ++#else |
| 16 | ++#define NETBSD_POSIX_ICONV 0 |
| 17 | ++#endif |
| 18 | ++#endif |
| 19 | ++ |
| 20 | + static iconv_t utf8_conversion_descriptor = (iconv_t)-1; |
| 21 | + static iconv_t ucs2_conversion_descriptor = (iconv_t)-1; |
| 22 | + |
| 23 | +@@ -42,8 +51,13 @@ char *convert_ucs2_to_utf8(xcb_char2b_t |
| 24 | + |
| 25 | + /* Do the conversion */ |
| 26 | + size_t input_len = num_glyphs * sizeof(xcb_char2b_t); |
| 27 | ++#if (defined(__NetBSD__) && !NETBSD_POSIX_ICONV) || defined(__sun) |
| 28 | ++ size_t rc = iconv(utf8_conversion_descriptor, (const char **)&text, |
| 29 | ++ &input_len, &output, &output_size); |
| 30 | ++#else |
| 31 | + size_t rc = iconv(utf8_conversion_descriptor, (char **)&text, |
| 32 | + &input_len, &output, &output_size); |
| 33 | ++#endif |
| 34 | + if (rc == (size_t)-1) { |
| 35 | + perror("Converting to UTF-8 failed"); |
| 36 | + free(buffer); |
| 37 | +@@ -89,8 +103,13 @@ xcb_char2b_t *convert_utf8_to_ucs2(char |
| 38 | + } |
| 39 | + |
| 40 | + /* Do the conversion */ |
| 41 | ++#if (defined(__NetBSD__) && !NETBSD_POSIX_ICONV) || defined(__sun) |
| 42 | ++ size_t rc = iconv(ucs2_conversion_descriptor, (const char *)&input, &input_size, |
| 43 | ++ (char **)&output, &output_bytes_left); |
| 44 | ++#else |
| 45 | + size_t rc = iconv(ucs2_conversion_descriptor, &input, &input_size, |
| 46 | + (char **)&output, &output_bytes_left); |
| 47 | ++#endif |
| 48 | + if (rc == (size_t)-1) { |
| 49 | + /* Conversion will only be partial. */ |
| 50 | + perror("Converting to UCS-2 failed"); |
0 commit comments