Skip to content

Commit

Permalink
Added build option WITH_ICONV.
Browse files Browse the repository at this point in the history
Default is OFF, which means MariaDB Connector/C
will be built without iconv support.

If set to OFF The API function mariadb_convert_string will always
return -1 and errorcode ENOTSUP.
  • Loading branch information
9EOR9 committed Sep 14, 2020
1 parent ed9a6d4 commit 7052619
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
9 changes: 6 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ get_directory_property(IS_SUBPROJECT PARENT_DIRECTORY)
# do not inherit include directories from the parent project
SET_PROPERTY(DIRECTORY PROPERTY INCLUDE_DIRECTORIES)
FOREACH(V WITH_MYSQLCOMPAT WITH_MSI WITH_SIGNCODE WITH_RTC WITH_UNIT_TESTS
WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL
WITH_DYNCOL WITH_EXTERNAL_ZLIB WITH_CURL WITH_SQLITE WITH_SSL WITH_ICONV
INSTALL_LAYOUT WITH_TEST_SRCPKG)
SET(${V} ${${OPT}${V}})
ENDFOREACH()
Expand Down Expand Up @@ -57,6 +57,7 @@ ELSE()
ADD_OPTION(WITH_MSI "Build MSI installation package" OFF)
ADD_OPTION(WITH_SIGNCODE "digitally sign files" OFF)
ADD_OPTION(WITH_RTC "enables run time checks for debug builds" OFF)
ADD_OPTION(WITH_ICONV "enables character set conversion" OFF)
ENDIF()

ADD_OPTION(WITH_UNIT_TESTS "build test suite" ON)
Expand Down Expand Up @@ -343,8 +344,10 @@ ELSEIF (NOT ENABLED_LOCAL_INFILE MATCHES "^(ON|OFF|AUTO)$")
MESSAGE(FATAL_ERROR "ENABLED_LOCAL_INFILE must be one of OFF, ON, AUTO")
ENDIF()

IF(NOT WIN32)
INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
IF(WITH_ICONV)
IF(NOT WIN32)
INCLUDE(${CC_SOURCE_DIR}/cmake/FindIconv.cmake)
ENDIF()
ENDIF()

CONFIGURE_FILE(${CC_SOURCE_DIR}/include/ma_config.h.in
Expand Down
1 change: 1 addition & 0 deletions cmake/FindIconv.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ if (ICONV_FOUND)
return 0;
}
" ICONV_SECOND_ARGUMENT_IS_CONST )
ADD_DEFINITIONS(-DHAVE_ICONV)
endif (ICONV_FOUND)

set (CMAKE_REQUIRED_INCLUDES)
Expand Down
18 changes: 15 additions & 3 deletions libmariadb/ma_charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@
#include <mariadb_ctype.h>
#include <ma_string.h>

#ifdef HAVE_ICONV
#ifdef _WIN32
#include "../win-iconv/iconv.h"
#else
#include <iconv.h>
#endif
#endif


#if defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE)
Expand Down Expand Up @@ -1385,7 +1387,7 @@ int madb_get_windows_cp(const char *charset)
#endif
/* }}} */


#ifdef HAVE_ICONV
/* {{{ map_charset_name
Changing charset name into something iconv understands, if necessary.
Another purpose it to avoid BOMs in result string, adding BE if necessary
Expand Down Expand Up @@ -1413,6 +1415,7 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe
}
}
/* }}} */
#endif

/* {{{ mariadb_convert_string
Converts string from one charset to another, and writes converted string to given buffer
Expand All @@ -1426,9 +1429,17 @@ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffe
@return -1 in case of error, bytes used in the "to" buffer, otherwise
*/
size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIADB_CHARSET_INFO *from_cs,
char *to, size_t *to_len, MARIADB_CHARSET_INFO *to_cs, int *errorcode)
size_t STDCALL mariadb_convert_string(const char *from __attribute__((unused)),
size_t *from_len __attribute__((unused)),
MARIADB_CHARSET_INFO *from_cs __attribute__((unused)),
char *to __attribute__((unused)),
size_t *to_len __attribute__((unused)),
MARIADB_CHARSET_INFO *to_cs __attribute__((unused)), int *errorcode)
{
#ifndef HAVE_ICONV
*errorcode= ENOTSUP;
return -1;
#else
iconv_t conv= 0;
size_t rc= -1;
size_t save_len= *to_len;
Expand Down Expand Up @@ -1462,6 +1473,7 @@ size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, MARIAD
if (conv != (iconv_t)-1)
iconv_close(conv);
return rc;
#endif
}
/* }}} */

5 changes: 5 additions & 0 deletions unittest/libmariadb/charset.c
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,10 @@ static int test_bug_54100(MYSQL *mysql)

static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused)))
{
#ifndef HAVE_ICONV
diag("MariaDB Connector/C was built without iconv support");
return SKIP;
#else
const char *csname[]= {"utf16", "utf16le", "utf32", "utf8"};
MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)];

Expand Down Expand Up @@ -724,6 +728,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql __attribute__((unused)))
}

return OK;
#endif
}

static int charset_auto(MYSQL *my __attribute__((unused)))
Expand Down

0 comments on commit 7052619

Please sign in to comment.