diff --git a/CMakeLists.txt b/CMakeLists.txt index 95ef41d5..746e4a8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,8 +7,8 @@ PROJECT(mariadb-connector-c C) SET(PACKAGE_STATUS_SUFFIX "alpha") SET(CPACK_PACKAGE_VERSION_MAJOR 3) -SET(CPACK_PACKAGE_VERSION_MINOR 0) -SET(CPACK_PACKAGE_VERSION_PATCH 1) +SET(CPACK_PACKAGE_VERSION_MINOR 1) +SET(CPACK_PACKAGE_VERSION_PATCH 0) SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") #Minimum required version is Cmake 2.8.8, since we need to build object libraries @@ -19,6 +19,8 @@ CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR) ENDIF() IF(COMMAND CMAKE_POLICY) CMAKE_POLICY(SET CMP0003 NEW) + CMAKE_POLICY(SET CMP0022 NEW) + CMAKE_POLICY(SET CMP0023 NEW) ENDIF() #Allow access to non existing targets @@ -34,10 +36,14 @@ SET(MARIADB_CONNECTOR_C_COPYRIGHT "2013-2016 MariaDB Corporation Ab") IF(NOT WIN32) OPTION(WITH_MYSQLCOMPAT "creates libmysql* symbolic links" ON) ELSE() + OPTION(WITH_MSI "Build MSI installation package" OFF) OPTION(WITH_SIGNCODE "digitally sign files" OFF) OPTION(WITH_RTC "enables run time checks for debug builds" OFF) ENDIF() +OPTION(WITH_UNITTEST "build test suite" ON) +OPTION(WITH_DYNCOL "Enables support of dynamic coluumns" ON) +OPTION(WITH_NONBLOCK "Enables support for non blocking operations" ON) OPTION(WITH_EXTERNAL_ZLIB "Enables use of external zlib" OFF) ############### IF(WITH_SIGNCODE) @@ -47,7 +53,6 @@ IF(WITH_SIGNCODE) MARK_AS_ADVANCED(SIGN_OPTIONS) ENDIF() - IF(WITH_RTC) SET(RTC_OPTIONS "/RTC1 /RTCc") ENDIF() @@ -111,7 +116,7 @@ ENDIF() # If the build type isn't specified, set to Relwithdebinfo as default. IF(NOT CMAKE_BUILD_TYPE) - SET(CMAKE_BUILD_TYPE "Relwithdebinfo") + SET(CMAKE_BUILD_TYPE "RelWithDebInfo") ENDIF() # various defines for generating include/mysql_version.h @@ -236,14 +241,10 @@ IF(NOT WIN32) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/FindIconv.cmake) ENDIF() -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/mysql_version.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h.in - ${CMAKE_CURRENT_BINARY_DIR}/include/my_config.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/mysql_version.h) -CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h.in - ${CMAKE_CURRENT_SOURCE_DIR}/include/my_config.h) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/ma_config.h.in + ${CMAKE_CURRENT_BINARY_DIR}/include/ma_config.h) +CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/include/mariadb_version.h.in + ${CMAKE_CURRENT_SOURCE_DIR}/include/mariadb_version.h) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR}/include) @@ -287,11 +288,11 @@ IF(NOT WIN32) ADD_SUBDIRECTORY(mariadb_config) ENDIF() -ADD_SUBDIRECTORY(client) - IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/unittest) - ADD_SUBDIRECTORY(unittest/mytap) - ADD_SUBDIRECTORY(unittest/libmariadb) + IF(WITH_UNITTEST STREQUAL "ON") + ADD_SUBDIRECTORY(unittest/mytap) + ADD_SUBDIRECTORY(unittest/libmariadb) + ENDIF() ENDIF() IF(CLIENT_DOCS) @@ -300,8 +301,8 @@ IF(CLIENT_DOCS) ENDIF() -IF(WIN32 AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") - ADD_SUBDIRECTORY(win/packaging) +IF(WIN32 AND WITH_MSI AND CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo") + DD_SUBDIRECTORY(win/packaging) ENDIF() SET(CPACK_PACKAGE_VENDOR "MariaDB Corporation Ab") diff --git a/client/ma_plugin_info.c b/client/ma_plugin_info.c index f273bed9..b015ba7f 100644 --- a/client/ma_plugin_info.c +++ b/client/ma_plugin_info.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #define CLIENT_PLUGIN_INFO_VERSION "1.0.0" @@ -56,16 +56,16 @@ static struct st_plugin_type plugin_types[]= static void version() { - printf("%s Version %s\n", my_progname, CLIENT_PLUGIN_INFO_VERSION); + printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION); } static void usage(void) { int i=0; - printf("%s Version %s\n", my_progname, CLIENT_PLUGIN_INFO_VERSION); + printf("%s Version %s\n", ma_progname, CLIENT_PLUGIN_INFO_VERSION); puts("Copyright 2015 MariaDB Corporation AB"); puts("Show client plugin information for MariaDB Connector/C."); - printf("Usage: %s [OPTIONS] [plugin_name]\n", my_progname); + printf("Usage: %s [OPTIONS] [plugin_name]\n", ma_progname); while (long_options[i].name) { printf(" --%-12s -%s\n", long_options[i].name, values[i]); @@ -73,7 +73,7 @@ static void usage(void) } } -static char *get_type_name(int type) +static char *ma_get_type_name(int type) { int i=0; while (plugin_types[i].type) @@ -88,7 +88,7 @@ static char *get_type_name(int type) static void show_plugin_info(struct st_mysql_client_plugin *plugin, my_bool builtin) { printf("Name: %s\n", plugin->name); - printf("Type: %s\n", get_type_name(plugin->type)); + printf("Type: %s\n", ma_get_type_name(plugin->type)); printf("Desc: %s\n", plugin->desc); printf("Author: %s\n", plugin->author); printf("License: %s\n", plugin->license); @@ -115,8 +115,10 @@ static void show_file(char *filename) char *has_so_ext= strstr(filename, SO_EXT); if (!strchr(filename, FN_LIBCHAR)) - strxnmov(dlpath, sizeof(dlpath) - 1, - (env_plugin_dir) ? env_plugin_dir : PLUGINDIR, "/", filename, has_so_ext ? "" : SO_EXT, NullS); + snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s", + (env_plugin_dir) ? env_plugin_dir : PLUGINDIR, + filename, + has_so_ext ? "" : SO_EXT); else strcpy(dlpath, filename); if ((dlhandle= dlopen((const char *)dlpath, RTLD_NOW))) @@ -164,7 +166,7 @@ int main(int argc, char *argv[]) { int option_index= 0; int c; - my_progname= argv[0]; + ma_progname= argv[0]; mysql_server_init(0, NULL, NULL); diff --git a/cmake/export.cmake b/cmake/export.cmake new file mode 100644 index 00000000..595b259f --- /dev/null +++ b/cmake/export.cmake @@ -0,0 +1,16 @@ +MACRO(CREATE_EXPORT_FILE targetname directory symbols) + SET(EXPORT_FILE "${directory}/${targetname}.def") + IF(WIN32) + SET(EXPORT_CONTENT "EXPORTS\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT ${EXPORT_CONTENT} "${exp_symbol}\n") + ENDFOREACH() + ELSE() + SET(EXPORT_CONTENT "{\nglobal:\n") + FOREACH(exp_symbol ${symbols}) + SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${exp_symbol}\\;\n") + ENDFOREACH() + SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;") + ENDIF() + FILE(WRITE ${EXPORT_FILE} ${EXPORT_CONTENT}) +ENDMACRO() diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake index 2068b1e3..81418d98 100644 --- a/cmake/plugins.cmake +++ b/cmake/plugins.cmake @@ -50,7 +50,7 @@ IF(CURL_FOUND) IF(WIN32) REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" "remote_io" 1) ELSE() - REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "STATIC" "remote_io" 1) + REGISTER_PLUGIN("REMOTEIO" "${CMAKE_SOURCE_DIR}/plugins/io/remote_io.c" "remote_io_plugin" "DYNAMIC" "remote_io" 1) ENDIF() ENDIF() @@ -90,7 +90,7 @@ ENDIF() # since some files contain multiple plugins, remove duplicates from source files LIST(REMOVE_DUPLICATES LIBMARIADB_SOURCES) -CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/libmariadb/client_plugin.c.in - ${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c) +CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/libmariadb/ma_client_plugin.c.in + ${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c) MARK_AS_ADVANCED(LIBMARIADB_SOURCES) diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index 47e7f7b2..6223c918 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -1,37 +1,23 @@ -SET(MARIADB_CLIENT_INCLUDES config-win.h - dbug.h - errmsg.h - getopt.h - hash.h - ma_common.h - ma_pvio.h - ma_ssl.h - m_ctype.h - m_string.h - ma_dyncol.h - my_alarm.h - my_base.h - my_config.h.in - my_dir.h - my_global.h - my_list.h - my_net.h - my_no_pthread.h - my_pthread.h - my_stmt.h - my_sys.h - mysql.h - mysql_com.h - mysql_io.h - mysql_mm.h - mysql_priv.h - mysql_version.h - mysql_wireprotocol.h - mysqld_error.h - mysys_err.h - sha1.h - thr_alarm.h - mysql/client_plugin.h - mysql/plugin_auth_common.h - mysql/plugin_auth.h - PARENT_SCOPE) +SET(MARIADB_CLIENT_INCLUDES ${CMAKE_SOURCE_DIR}/include/mariadb_com.h + ${CMAKE_SOURCE_DIR}/include/mysql.h + ${CMAKE_SOURCE_DIR}/include/mariadb_stmt.h + ${CMAKE_SOURCE_DIR}/include/mariadb_version.h + ${CMAKE_SOURCE_DIR}/include/ma_list.h + ${CMAKE_SOURCE_DIR}/include/ma_errmsg.h + ${CMAKE_SOURCE_DIR}/include/mariadb_dyncol.h + ${CMAKE_SOURCE_DIR}/include/mariadb_ctype.h) +SET(MARIADB_ADDITIONAL_INCLUDES + ${CMAKE_SOURCE_DIR}/include/mysql/client_plugin.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth_common.h + ${CMAKE_SOURCE_DIR}/include/mysql/plugin_auth.h) + +INSTALL(FILES + ${MARIADB_CLIENT_INCLUDES} + DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR} + COMPONENT ALL) +INSTALL(FILES + ${MARIADB_ADDITIONAL_INCLUDES} + DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}/mysql + COMPONENT ALL) + + diff --git a/include/dbug.h b/include/dbug.h deleted file mode 100644 index b7b17e32..00000000 --- a/include/dbug.h +++ /dev/null @@ -1,151 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _dbug_h -#define _dbug_h -#ifdef __cplusplus -extern "C" { -#endif - -/* unsupported macros (used by async) */ -#define DBUG_SWAP_CODE_STATE(a) {} -#define DBUG_FREE_CODE_STATE(a) {} - -#if !defined(DBUG_OFF) && !defined(_lint) - -struct _db_stack_frame_ { - const char *func; /* function name of the previous stack frame */ - const char *file; /* filename of the function of previous frame */ - uint level; /* this nesting level, highest bit enables tracing */ - struct _db_stack_frame_ *prev; /* pointer to the previous frame */ -}; - -struct _db_code_state_; -extern my_bool _dbug_on_; -extern my_bool _db_keyword_(struct _db_code_state_ *, const char *, int); -extern int _db_explain_(struct _db_code_state_ *cs, char *buf, size_t len); -extern int _db_explain_init_(char *buf, size_t len); -extern int _db_is_pushed_(void); -extern void _db_setjmp_(void); -extern void _db_longjmp_(void); -extern void _db_process_(const char *name); -extern void _db_push_(const char *control); -extern void _db_pop_(void); -extern void _db_set_(const char *control); -extern void _db_set_init_(const char *control); -extern void _db_enter_(const char *_func_, const char *_file_, uint _line_, - struct _db_stack_frame_ *_stack_frame_); -extern void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_); -extern void _db_pargs_(uint _line_,const char *keyword); -extern void _db_doprnt_ _VARARGS((const char *format,...)); -extern void _db_dump_(uint _line_,const char *keyword, - const unsigned char *memory, size_t length); -extern void _db_end_(void); -extern void _db_lock_file_(void); -extern void _db_unlock_file_(void); -extern FILE *_db_fp_(void); -extern void _db_flush_(); -extern const char* _db_get_func_(void); -/* -#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ - _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) -#define DBUG_LEAVE \ - (_db_return_ (__LINE__, &_db_func_, &_db_file_, &_db_level_)) -#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) -#define DBUG_VOID_RETURN {DBUG_LEAVE; return;} -#define DBUG_END() _db_end_ () -#define DBUG_EXECUTE(keyword,a1) \ - {if (_db_on_) {if (_db_keyword_ (keyword)) { a1 }}} -#define DBUG_PRINT(keyword,arglist) \ - {if (_db_on_) {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;}} -#define DBUG_PUSH(a1) _db_push_ (a1) -#define DBUG_POP() _db_pop_ () -#define DBUG_PROCESS(a1) (_db_process_ = a1) -#define DBUG_FILE (_db_fp_) -#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) -#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) -#define DBUG_DUMP(keyword,a1,a2)\ - {if (_db_on_) {_db_dump_(__LINE__,keyword,a1,a2);}} -#define DBUG_IN_USE (_db_fp_ && _db_fp_ != stderr) -#define DEBUGGER_OFF _no_db_=1;_db_on_=0; -#define DEBUGGER_ON _no_db_=0 -#define DBUG_LOCK_FILE { _db_lock_file(); } -#define DBUG_UNLOCK_FILE { _db_unlock_file(); } -#define DBUG_ASSERT(A) assert(A) */ -#define DBUG_ENTER(a) struct _db_stack_frame_ _db_stack_frame_; \ - _db_enter_ (a,__FILE__,__LINE__,&_db_stack_frame_) -#define DBUG_LEAVE _db_return_ (__LINE__, &_db_stack_frame_) -#define DBUG_RETURN(a1) do {DBUG_LEAVE; return(a1);} while(0) -#define DBUG_VOID_RETURN do {DBUG_LEAVE; return;} while(0) -#define DBUG_EXECUTE(keyword,a1) \ - do {if (_db_keyword_(0, (keyword), 0)) { a1 }} while(0) -#define DBUG_EXECUTE_IF(keyword,a1) \ - do {if (_db_keyword_(0, (keyword), 1)) { a1 }} while(0) -#define DBUG_EVALUATE(keyword,a1,a2) \ - (_db_keyword_(0,(keyword), 0) ? (a1) : (a2)) -#define DBUG_EVALUATE_IF(keyword,a1,a2) \ - (_db_keyword_(0,(keyword), 1) ? (a1) : (a2)) -#define DBUG_PRINT(keyword,arglist) \ - do {_db_pargs_(__LINE__,keyword); _db_doprnt_ arglist;} while(0) -#define DBUG_PUSH(a1) _db_push_ (a1) -#define DBUG_POP() _db_pop_ () -#define DBUG_SET(a1) _db_set_ (a1) -#define DBUG_SET_INITIAL(a1) _db_set_init_ (a1) -#define DBUG_PROCESS(a1) _db_process_(a1) -#define DBUG_FILE _db_fp_() -#define DBUG_SETJMP(a1) (_db_setjmp_ (), setjmp (a1)) -#define DBUG_LONGJMP(a1,a2) (_db_longjmp_ (), longjmp (a1, a2)) -#define DBUG_DUMP(keyword,a1,a2) _db_dump_(__LINE__,keyword,a1,a2) -#define DBUG_END() _db_end_ () -#define DBUG_LOCK_FILE _db_lock_file_() -#define DBUG_UNLOCK_FILE _db_unlock_file_() -#define DBUG_ASSERT(A) assert(A) -#define DBUG_EXPLAIN(buf,len) _db_explain_(0, (buf),(len)) -#define DBUG_EXPLAIN_INITIAL(buf,len) _db_explain_init_((buf),(len)) -#define DEBUGGER_OFF do { _dbug_on_= 0; } while(0) -#define DEBUGGER_ON do { _dbug_on_= 1; } while(0) -#ifndef _WIN32 -#define DBUG_ABORT() (_db_flush_(), abort()) -#else -#define DBUG_ABORT() (_db_flush_(), exit(3)) -#endif - -#else /* No debugger */ -#define DBUG_ENTER(a1) -#define DBUG_END() {} -#define DBUG_RETURN(a1) return(a1) -#define DBUG_VOID_RETURN return -#define DBUG_EXECUTE(keyword,a1) {} -#define DBUG_PRINT(keyword,arglist) {} -#define DBUG_PUSH(a1) {} -#define DBUG_POP() {} -#define DBUG_PROCESS(a1) {} -#define DBUG_FILE (stderr) -#define DBUG_SETJMP setjmp -#define DBUG_LONGJMP longjmp -#define DBUG_DUMP(keyword,a1,a2) {} -#define DBUG_IN_USE 0 -#define DEBUGGER_OFF -#define DEBUGGER_ON -#define DBUG_LOCK_FILE -#define DBUG_UNLOCK_FILE -#define DBUG_ASSERT(A) {} -#endif -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/m_string.h b/include/m_string.h deleted file mode 100644 index 7d102127..00000000 --- a/include/m_string.h +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* There may be prolems include all of theese. Try to test in - configure with ones are needed? */ - -/* This is needed for the definitions of strchr... on solaris */ - -#ifndef _m_string_h -#define _m_string_h -#ifndef __USE_GNU -#define __USE_GNU /* We want to use stpcpy */ -#endif -#if defined(HAVE_STRINGS_H) -#include -#endif -#if defined(HAVE_STRING_H) -#include -#endif - -/* Correct some things for UNIXWARE7 */ -#ifdef HAVE_UNIXWARE7_THREADS -#undef HAVE_STRINGS_H -#undef HAVE_MEMORY_H -#define HAVE_MEMCPY -#ifndef HAVE_MEMMOVE -#define HAVE_MEMMOVE -#endif -#undef HAVE_BCMP -#undef bcopy -#undef bcmp -#undef bzero -#endif /* HAVE_UNIXWARE7_THREADS */ -#ifdef _AIX -#undef HAVE_BCMP -#endif - -/* This is needed for the definitions of bzero... on solaris */ -#if defined(HAVE_STRINGS_H) && !defined(HAVE_mit_thread) -#include -#endif - -/* This is needed for the definitions of memcpy... on solaris */ -#if defined(HAVE_MEMORY_H) && !defined(__cplusplus) -#include -#endif - -#if !defined(HAVE_MEMCPY) && !defined(HAVE_MEMMOVE) -# define memcpy(d, s, n) bcopy ((s), (d), (n)) -# define memset(A,C,B) bfill((A),(B),(C)) -# define memmove(d, s, n) bmove ((d), (s), (n)) -#elif defined(HAVE_MEMMOVE) -# define bmove(d, s, n) memmove((d), (s), (n)) -#else -# define memmove(d, s, n) bmove((d), (s), (n)) /* our bmove */ -#endif - -/* Unixware 7 */ -#if !defined(HAVE_BFILL) -# define bfill(A,B,C) memset((A),(C),(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) -#endif - -#if !defined(HAVE_BCMP) -# define bcopy(s, d, n) memcpy((d), (s), (n)) -# define bcmp(A,B,C) memcmp((A),(B),(C)) -# define bzero(A,B) memset((A),0,(B)) -# define bmove_allign(A,B,C) memcpy((A),(B),(C)) -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -#if defined(HAVE_STPCPY) && !defined(HAVE_mit_thread) -#define strmov(A,B) stpcpy((A),(B)) -#endif - -extern char NEAR _dig_vec[]; /* Declared in int2str() */ - -#ifdef BAD_STRING_COMPILER -#define strmov(A,B) (memccpy(A,B,0,INT_MAX)-1) -#else -#define strmov_overlapp(A,B) strmov(A,B) -#define strmake_overlapp(A,B,C) strmake(A,B,C) -#endif - -#ifdef BAD_MEMCPY /* Problem with gcc on Alpha */ -#define memcpy_fixed(A,B,C) bmove((A),(B),(C)) -#else -#define memcpy_fixed(A,B,C) memcpy((A),(B),(C)) -#endif - -#if (!defined(USE_BMOVE512) || defined(HAVE_purify)) && !defined(bmove512) -#define bmove512(A,B,C) memcpy(A,B,C) -#endif - - /* Prototypes for string functions */ - -#if !defined(bfill) && !defined(HAVE_BFILL) -extern void bfill(gptr dst, size_t len, pchar fill); -#endif - -#if !defined(bzero) && !defined(HAVE_BZERO) -extern void bzero(gptr dst, size_t len); -#endif - -#if !defined(bcmp) && !defined(HAVE_BCMP) -extern int bcmp(const char *s1,const char *s2, size_t len); -#ifdef HAVE_purify -extern int my_bcmp(const char *s1,const char *s2, size_t len); -#define bcmp(A,B,C) my_bcmp((A),(B),(C)) -#endif -#endif - -#ifndef bmove512 -extern void bmove512(gptr dst,const gptr src, size_t len); -#endif - -#if !defined(HAVE_BMOVE) && !defined(bmove) -extern void bmove(char *dst, const char *src, size_t len); -#endif - -extern void bmove_upp(char *dst,const char *src, size_t len); -extern void bchange(char *dst, size_t old_len, const char *src, - size_t new_len, size_t tot_len); -extern void strappend(char *s,size_t len,pchar fill); -extern char *strend(const char *s); -extern char *strcend(const char *, char); -extern char *strfield(char *src,int fields,int chars,int blanks, - int tabch); -extern char *strfill(my_string s, size_t len, pchar fill); -extern uint strinstr(const char *str,const char *search); -extern uint r_strinstr(reg1 my_string str,int from, reg4 my_string search); -extern char *strkey(char *dst,char *head,char *tail,char *flags); -extern char *strmake(char *dst,const char *src, size_t length); -#ifndef strmake_overlapp -extern char *strmake_overlapp(char *dst,const char *src, size_t length); -#endif - -#ifndef strmov -extern char *strmov(char *dst,const char *src); -#endif -extern char *strnmov(char *dst,const char *src,uint n); -extern char *strsuff(const char *src,const char *suffix); -extern char *strcont(const char *src,const char *set); -extern char *strxcat _VARARGS((char *dst,const char *src, ...)); -extern char *strxmov _VARARGS((char *dst,const char *src, ...)); -extern char *strxcpy _VARARGS((char *dst,const char *src, ...)); -extern char *strxncat _VARARGS((char *dst, size_t len, const char *src, ...)); -extern char *strxnmov _VARARGS((char *dst, size_t len, const char *src, ...)); -extern char *strxncpy _VARARGS((char *dst, size_t len, const char *src, ...)); - -/* Prototypes of normal stringfunctions (with may ours) */ - -#ifdef WANT_STRING_PROTOTYPES -extern char *strcat(char *, const char *); -extern char *strchr(const char *, pchar); -extern char *strrchr(const char *, pchar); -extern char *strcpy(char *, const char *); -extern int strcmp(const char *, const char *); -#ifndef __GNUC__ -extern size_t strlen(const char *); -#endif -#endif - -#if !defined(__cplusplus) -#ifndef HAVE_STRPBRK -extern char *strpbrk(const char *, const char *); -#endif -#ifndef HAVE_STRSTR -extern char *strstr(const char *, const char *); -#endif -#endif -extern int is_prefix(const char *, const char *); - -/* Conversion rutins */ - -#ifdef USE_MY_ITOA -extern char *my_itoa(int val,char *dst,int radix); -extern char *my_ltoa(long val,char *dst,int radix); -#endif - -extern char *llstr(longlong value,char *buff); -#ifndef HAVE_STRTOUL -extern long strtol(const char *str, char **ptr, int base); -extern ulong strtoul(const char *str, char **ptr, int base); -#endif - -extern char *int2str(long val,char *dst,int radix); -extern char *int10_to_str(long val,char *dst,int radix); -extern char *str2int(const char *src,int radix,long lower,long upper, - long *val); -#if SIZEOF_LONG == SIZEOF_LONG_LONG -#define longlong2str(A,B,C) int2str((A),(B),(C)) -#define longlong10_to_str(A,B,C) int10_to_str((A),(B),(C)) -#define strtoll(A,B,C) strtol((A),(B),(C)) -#define strtoull(A,B,C) strtoul((A),(B),(C)) -#ifndef HAVE_STRTOULL -#define HAVE_STRTOULL -#endif -#else -#ifdef HAVE_LONG_LONG -extern char *longlong2str(longlong val,char *dst,int radix); -extern char *longlong10_to_str(longlong val,char *dst,int radix); -#if (!defined(HAVE_STRTOULL) || defined(HAVE_mit_thread)) || defined(NO_STRTOLL_PROTO) -extern longlong strtoll(const char *str, char **ptr, int base); -extern ulonglong strtoull(const char *str, char **ptr, int base); -#endif -#endif -#endif - -#if defined(__cplusplus) -} -#endif -#endif diff --git a/include/ma_common.h b/include/ma_common.h index edf69c42..dd63913b 100644 --- a/include/ma_common.h +++ b/include/ma_common.h @@ -21,7 +21,7 @@ #define _ma_common_h #include -#include +#include typedef struct st_mariadb_db_driver @@ -52,10 +52,13 @@ struct st_mysql_options_extension { char *ssl_fp; /* finger print of server certificate */ char *ssl_fp_list; /* white list of finger prints */ char *ssl_pw; /* password for encrypted certificates */ + my_bool multi_command; /* indicates if client wants to send multiple + commands in one packet */ char *url; /* for connection handler we need to save URL for reconnect */ unsigned int ssl_cipher_strength; my_bool read_only; char *connection_handler; + my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value); HASH userdata; }; diff --git a/include/my_config.h.in b/include/ma_config.h.in similarity index 100% rename from include/my_config.h.in rename to include/ma_config.h.in diff --git a/include/config-win.h b/include/ma_config_win.h similarity index 100% rename from include/config-win.h rename to include/ma_config_win.h diff --git a/include/my_context.h b/include/ma_context.h similarity index 100% rename from include/my_context.h rename to include/ma_context.h diff --git a/include/errmsg.h b/include/ma_errmsg.h similarity index 91% rename from include/errmsg.h rename to include/ma_errmsg.h index 0af17b20..18397bca 100644 --- a/include/errmsg.h +++ b/include/ma_errmsg.h @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2012-2016 SkySQL AB, MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,8 +18,8 @@ /* Error messages for mysql clients */ /* error messages for the demon is in share/language/errmsg.sys */ -#ifndef _errmsg_h_ -#define _errmsg_h_ +#ifndef _ma_errmsg_h_ +#define _ma_errmsg_h_ #ifdef __cplusplus extern "C" { @@ -31,13 +32,14 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #endif + #define CR_MIN_ERROR 2000 /* For easier client code */ #define CR_MAX_ERROR 2999 #define CER_MIN_ERROR 5000 #define CER_MAX_ERROR 5999 #define CER(X) mariadb_client_errors[(X)-CER_MIN_ERROR] #define ER(X) client_errors[(X)-CR_MIN_ERROR] -#define CLIENT_ERRMAP 2 /* Errormap used by my_error() */ +#define CLIENT_ERRMAP 2 /* Errormap used by ma_error() */ #define CR_UNKNOWN_ERROR 2000 #define CR_SOCKET_CREATE_ERROR 2001 @@ -70,7 +72,6 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_SHARED_MEMORY_CONNECTION 2037 #define CR_SHARED_MEMORY_CONNECT_ERROR 2038 - #define CR_SECURE_AUTH 2049 #define CR_NO_DATA 2051 #define CR_NO_STMT_METADATA 2052 @@ -82,10 +83,15 @@ extern const char *mariadb_client_errors[]; /* Error messages */ #define CR_ALREADY_CONNECTED 2059 #define CR_PLUGIN_FUNCTION_NOT_SUPPORTED 2060 +/* + * MariaDB Connector/C errors: + */ #define CR_EVENT_CREATE_FAILED 5000 #define CR_BIND_ADDR_FAILED 5001 #define CR_ASYNC_NOT_SUPPORTED 5002 #define CR_FUNCTION_NOT_SUPPORTED 5003 +#define CR_FILE_NOT_FOUND 5004 +#define CR_FILE_READ 5005 #define SQLSTATE_UNKNOWN "HY000" diff --git a/include/my_global.h b/include/ma_global.h similarity index 99% rename from include/my_global.h rename to include/ma_global.h index 7ec47051..0b21400f 100644 --- a/include/my_global.h +++ b/include/ma_global.h @@ -23,9 +23,9 @@ #ifdef _WIN32 -#include +#include #else -#include +#include #if defined(__cplusplus) && defined(inline) #undef inline /* fix configure problem */ #endif @@ -257,7 +257,7 @@ int __void__; #if defined(_lint) || defined(FORCE_INIT_OF_VARS) #define LINT_INIT(var) var=0 /* No uninitialize-warning */ -#define LINT_INIT_STRUCT(var) bzero(&var, sizeof(var)) /* No uninitialize-warning */ +#define LINT_INIT_STRUCT(var) memset(&var, 0, sizeof(var)) /* No uninitialize-warning */ #else #define LINT_INIT(var) #define LINT_INIT_STRUCT(var) @@ -1064,11 +1064,12 @@ do { doubleget_union _tmp; \ #define SO_EXT ".so" #endif -#include #ifndef DBUG_OFF #define dbug_assert(A) assert(A) +#define DBUG_ASSERT(A) assert(A) #else #define dbug_assert(A) +#define DBUG_ASSERT(A) #endif #ifdef HAVE_DLOPEN diff --git a/include/hash.h b/include/ma_hash.h similarity index 96% rename from include/hash.h rename to include/ma_hash.h index 35e24c32..198d4d0a 100644 --- a/include/hash.h +++ b/include/ma_hash.h @@ -21,8 +21,8 @@ is freely available from http://www.php.net *************************************************************************************/ -#ifndef _hash_h -#define _hash_h +#ifndef _ma_hash_h +#define _ma_hash_h #ifdef __cplusplus extern "C" { #endif @@ -61,7 +61,7 @@ my_bool hash_delete(HASH *hash,uchar *record); my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length); my_bool hash_check(HASH *hash); /* Only in debug library */ -#define hash_clear(H) bzero((char*) (H),sizeof(*(H))) +#define hash_clear(H) memset((char*) (H), 0,sizeof(*(H))) #define hash_inited(H) ((H)->array.buffer != 0) #ifdef __cplusplus diff --git a/include/my_list.h b/include/ma_list.h similarity index 97% rename from include/my_list.h rename to include/ma_list.h index a5621367..d733decc 100644 --- a/include/my_list.h +++ b/include/ma_list.h @@ -39,7 +39,7 @@ extern int list_walk(LIST *list,list_walk_action action,gptr argument); #define rest(a) ((a)->next) #define list_push(a,b) (a)=list_cons((b),(a)) -#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; my_free((gptr) old,MYF(MY_FAE)); } +#define list_pop(A) {LIST *old=(A); (A)=list_delete(old,old) ; ma_free((gptr) old,MYF(MY_FAE)); } #ifdef __cplusplus } diff --git a/include/my_pthread.h b/include/ma_pthread.h similarity index 99% rename from include/my_pthread.h rename to include/ma_pthread.h index 1d4f894c..74bd83ad 100644 --- a/include/my_pthread.h +++ b/include/ma_pthread.h @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public diff --git a/include/ma_pvio.h b/include/ma_pvio.h index 6984bb7b..4848bebf 100644 --- a/include/ma_pvio.h +++ b/include/ma_pvio.h @@ -18,6 +18,7 @@ struct st_ma_pvio_methods; typedef struct st_ma_pvio_methods PVIO_METHODS; +#ifdef HAVE_NONBLOCK #define IS_PVIO_ASYNC(a) \ ((a)->mysql && (a)->mysql->options.extension && (a)->mysql->options.extension->async_context) @@ -29,6 +30,12 @@ typedef struct st_ma_pvio_methods PVIO_METHODS; #define IS_MYSQL_ASYNC_ACTIVE(a) \ (IS_MYSQL_ASYNC(a)&& (a)->options.extension->async_context->active) +#else +#define IS_PVIO_ASYNC(a) (0) +#define IS_PVIO_ASYNC_ACTIVE(a) (0) +#define IS_MYSQL_ASYNC(a) (0) +#define IS_MYSQL_ASYNC_ACTIVE(a) (0) +#endif enum enum_pvio_timeout { PVIO_CONNECT_TIMEOUT= 0, @@ -75,7 +82,6 @@ struct st_ma_pvio { MYSQL *mysql; struct mysql_async_context *async_context; /* For non-blocking API */ PVIO_METHODS *methods; - FILE *fp; void (*set_error)(MYSQL *mysql, unsigned int error_nr, const char *sqlstate, const char *format, ...); void (*callback)(MARIADB_PVIO *pvio, my_bool is_read, const char *buffer, size_t length); }; diff --git a/include/mysqld_error.h b/include/ma_server_error.h similarity index 100% rename from include/mysqld_error.h rename to include/ma_server_error.h diff --git a/include/sha1.h b/include/ma_sha1.h similarity index 86% rename from include/sha1.h rename to include/ma_sha1.h index 6113d791..2748f114 100644 --- a/include/sha1.h +++ b/include/ma_sha1.h @@ -1,5 +1,6 @@ /**************************************************************************** Copyright (C) 2012 Monty Program AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -32,10 +33,10 @@ typedef struct { uint32 state[5]; /* state (ABCD) */ uint32 count[2]; /* number of bits, modulo 2^64 (lsb first) */ unsigned char buffer[64]; /* input buffer */ -} MYSQL_SHA1_CTX; +} _MA_SHA1_CTX; -void MYSQL_SHA1Init(MYSQL_SHA1_CTX *); -void MYSQL_SHA1Update(MYSQL_SHA1_CTX *, const unsigned char *, size_t); -void MYSQL_SHA1Final(unsigned char[20], MYSQL_SHA1_CTX *); +void ma_SHA1Init(_MA_SHA1_CTX *); +void ma_SHA1Update(_MA_SHA1_CTX *, const unsigned char *, size_t); +void ma_SHA1Final(unsigned char[20], _MA_SHA1_CTX *); #endif diff --git a/libmariadb/strtoull.c b/include/ma_string.h similarity index 80% rename from libmariadb/strtoull.c rename to include/ma_string.h index 104885e7..cae0fedb 100644 --- a/libmariadb/strtoull.c +++ b/include/ma_string.h @@ -1,5 +1,6 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - + 2012 by MontyProgram AB + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either @@ -15,12 +16,13 @@ Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -/* This is defines strtoull() */ +/* defines for the libmariadb library */ + +#ifndef _ma_string_h_ +#define _ma_string_h_ + +#include + +char *ma_ll2str(long long val,char *dst, int radix); -#include -#include -#if !defined(HAVE_STRTOULL) && defined(HAVE_LONG_LONG) -#define USE_UNSIGNED -#define USE_LONGLONG -#include "strto.c" #endif diff --git a/include/my_sys.h b/include/ma_sys.h similarity index 65% rename from include/my_sys.h rename to include/ma_sys.h index dabaa12e..6608eded 100644 --- a/include/my_sys.h +++ b/include/ma_sys.h @@ -29,21 +29,15 @@ typedef struct my_aio_result { } my_aio_result; #endif -#ifndef THREAD -extern int NEAR my_errno; /* Last error in mysys */ -#else -#include -#endif - -#ifndef _m_ctype_h -#include /* for CHARSET_INFO */ +#ifndef _mariadb_ctype_h +#include /* for MARIADB_CHARSET_INFO */ #endif #include -#define MYSYS_PROGRAM_USES_CURSES() { error_handler_hook = my_message_curses; mysys_uses_curses=1; } -#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;} -#define MY_INIT(name); { my_progname= name; my_init(); } +#define MYSYS_PROGRAM_USES_CURSES() { ma_error_handler_hook = ma_message_curses; mysys_uses_curses=1; } +#define MYSYS_PROGRAM_DONT_USE_CURSES() { ma_error_handler_hook = ma_message_no_curses; mysys_uses_curses=0;} +#define MY_INIT(name); { ma_progname= name; ma_init(); } #define MAXMAPS (4) /* Number of error message maps */ #define ERRMOD (1000) /* Max number of errors in a map */ @@ -68,14 +62,14 @@ extern int NEAR my_errno; /* Last error in mysys */ #define MY_REDEL_MAKE_BACKUP 256 #define MY_SEEK_NOT_DONE 32 /* my_lock may have to do a seek */ #define MY_DONT_WAIT 64 /* my_lock() don't wait if can't lock */ -#define MY_ZEROFILL 32 /* my_malloc(), fill array with zero */ -#define MY_ALLOW_ZERO_PTR 64 /* my_realloc() ; zero ptr -> malloc */ -#define MY_FREE_ON_ERROR 128 /* my_realloc() ; Free old ptr on error */ -#define MY_HOLD_ON_ERROR 256 /* my_realloc() ; Return old ptr on error */ +#define MY_ZEROFILL 32 /* ma_malloc(), fill array with zero */ +#define MY_ALLOW_ZERO_PTR 64 /* ma_realloc() ; zero ptr -> malloc */ +#define MY_FREE_ON_ERROR 128 /* ma_realloc() ; Free old ptr on error */ +#define MY_HOLD_ON_ERROR 256 /* ma_realloc() ; Return old ptr on error */ #define MY_THREADSAFE 128 /* pread/pwrite: Don't allow interrupts */ #define MY_DONT_OVERWRITE_FILE 1024 /* my_copy; Don't overwrite file */ -#define MY_CHECK_ERROR 1 /* Params to my_end; Check open-close */ +#define MY_CHECK_ERROR 1 /* Params to ma_end; Check open-close */ #define MY_GIVE_INFO 2 /* Give time info about process*/ #define ME_HIGHBYTE 8 /* Shift for colours */ @@ -119,14 +113,7 @@ extern int NEAR my_errno; /* Last error in mysys */ #define TERMINATE(A) {} #define QUICK_SAFEMALLOC #define NORMAL_SAFEMALLOC -extern gptr my_malloc(size_t Size,myf MyFlags); -#define my_malloc_ci(SZ,FLAG) my_malloc( SZ, FLAG ) -extern gptr my_realloc(gptr oldpoint, size_t Size,myf MyFlags); -extern void my_no_flags_free(void *ptr); -extern gptr my_memdup(const unsigned char *from, size_t length,myf MyFlags); -extern my_string my_strdup(const char *from,myf MyFlags); -extern my_string my_strndup(const char *from, size_t length, myf MyFlags); -#define my_free(PTR) my_no_flags_free(PTR) +#define ma_malloc_ci(SZ,FLAG) ma_malloc( SZ, FLAG ) #define CALLER_INFO_PROTO /* nothing */ #define CALLER_INFO /* nothing */ #define ORIG_CALLER_INFO /* nothing */ @@ -143,8 +130,8 @@ extern my_string my_strndup(const char *from, size_t length, myf MyFlags); #define my_alloca(SZ) alloca((size_t) (SZ)) #define my_afree(PTR) {} #else -#define my_alloca(SZ) my_malloc(SZ,MYF(0)) -#define my_afree(PTR) my_free(PTR) +#define my_alloca(SZ) ma_malloc(SZ,MYF(0)) +#define my_afree(PTR) ma_free(PTR) #endif /* HAVE_ALLOCA */ #ifdef MSDOS @@ -172,54 +159,55 @@ extern int errno; /* declare errno */ #endif extern const char ** NEAR my_errmsg[]; extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; -extern char *home_dir; /* Home directory for user */ -extern char *my_progname; /* program-name (printed in errors) */ -extern char NEAR curr_dir[]; /* Current directory for user */ -extern int (*error_handler_hook)(uint my_err, const char *str,myf MyFlags); -extern int (*fatal_error_handler_hook)(uint my_err, const char *str, +/* tbr +extern int (*ma_error_handler_hook)(uint my_err, const char *str,myf MyFlags); +extern int (*fatal_ma_error_handler_hook)(uint my_err, const char *str, myf MyFlags); +*/ /* charsets */ +/* tbr extern uint get_charset_number(const char *cs_name); extern const char *get_charset_name(uint cs_number); -extern CHARSET_INFO *get_charset(uint cs_number, myf flags); extern my_bool set_default_charset(uint cs, myf flags); -extern CHARSET_INFO *get_charset_by_name(const char *cs_name); -extern CHARSET_INFO *get_charset_by_nr(uint cs_number); extern my_bool set_default_charset_by_name(const char *cs_name, myf flags); extern void free_charsets(void); -extern char *list_charsets(myf want_flags); /* my_free() this string... */ +extern char *list_charsets(myf want_flags); extern char *get_charsets_dir(char *buf); +*/ +extern MARIADB_CHARSET_INFO *get_charset(uint cs_number, myf flags); +extern MARIADB_CHARSET_INFO *get_charset_by_name(const char *cs_name); +extern MARIADB_CHARSET_INFO *get_charset_by_nr(uint cs_number); /* statistics */ +#ifdef TBR extern ulong _my_cache_w_requests,_my_cache_write,_my_cache_r_requests, _my_cache_read; extern ulong _my_blocks_used,_my_blocks_changed; -extern ulong my_file_opened,my_stream_opened, my_tmp_file_created; +extern ulong ma_file_opened,ma_stream_opened, ma_tmp_file_created; extern my_bool key_cache_inited; - /* Point to current my_message() */ + /* Point to current ma_message() */ extern void (*my_sigtstp_cleanup)(void), /* Executed before jump to shell */ (*my_sigtstp_restart)(void), (*my_abort_hook)(int); /* Executed when comming from shell */ -extern int NEAR my_umask, /* Default creation mask */ - NEAR my_umask_dir, +extern int NEAR ma_umask, /* Default creation mask */ + NEAR ma_umask_dir, NEAR my_recived_signals, /* Signals we have got */ NEAR my_safe_to_handle_signal, /* Set when allowed to SIGTSTP */ - NEAR my_dont_interrupt; /* call remember_intr when set */ -extern my_bool NEAR mysys_uses_curses, my_use_symdir; + NEAR ma_dont_interrupt; /* call remember_intr when set */ +extern my_bool NEAR mysys_uses_curses, ma_use_symdir; extern size_t lCurMemory,lMaxMemory; /* from safemalloc */ -extern ulong my_default_record_cache_size; -extern my_bool NEAR my_disable_locking,NEAR my_disable_async_io, - NEAR my_disable_flush_key_blocks, NEAR my_disable_symlinks; +extern ulong ma_default_record_cache_size; +extern my_bool NEAR ma_disable_locking,NEAR ma_disable_async_io, + NEAR ma_disable_flush_key_blocks, NEAR ma_disable_symlinks; extern char wild_many,wild_one,wild_prefix; extern const char *charsets_dir; extern char *defaults_extra_file; - typedef struct wild_file_pack /* Struct to hold info when selecting files */ { uint wilds; /* How many wildcards */ @@ -232,6 +220,7 @@ struct my_rnd_struct { double max_value_dbl; }; +#endif typedef struct st_typelib { /* Different types saved here */ uint count; /* How many types */ const char *name; /* Name of typelib */ @@ -256,18 +245,19 @@ typedef struct st_record_cache /* Used when cacheing records */ enum cache_type type; } RECORD_CACHE; +/* enum file_type { UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN, FILE_BY_MKSTEMP }; -extern struct my_file_info +extern struct ma_file_info { my_string name; enum file_type type; #if defined(THREAD) && !defined(HAVE_PREAD) pthread_mutex_t mutex; #endif -} my_file_info[MY_NFILE]; - +} ma_file_info[MY_NFILE]; +*/ typedef struct st_dynamic_array { char *buffer; @@ -352,70 +342,30 @@ typedef struct st_changeable_var { } CHANGEABLE_VAR; -/* structs for alloc_root */ +/* structs for ma_alloc_root */ -#ifndef ST_USED_MEM_DEFINED -#define ST_USED_MEM_DEFINED -typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ +#ifndef ST_MA_USED_MEM_DEFINED +#define ST_MA_USED_MEM_DEFINED +typedef struct st_ma_used_mem { /* struct for once_alloc */ + struct st_ma_used_mem *next; /* Next block in use */ size_t left; /* memory left in block */ size_t size; /* Size of block */ -} USED_MEM; +} MA_USED_MEM; -typedef struct st_mem_root { - USED_MEM *free; - USED_MEM *used; - USED_MEM *pre_alloc; +typedef struct st_ma_mem_root { + MA_USED_MEM *free; + MA_USED_MEM *used; + MA_USED_MEM *pre_alloc; size_t min_malloc; size_t block_size; unsigned int block_num; unsigned int first_block_usage; void (*error_handler)(void); -} MEM_ROOT; +} MA_MEM_ROOT; #endif /* Prototypes for mysys and my_func functions */ -extern int my_copy(const char *from,const char *to,myf MyFlags); -extern int my_append(const char *from,const char *to,myf MyFlags); -extern int my_delete(const char *name,myf MyFlags); -extern int my_getwd(my_string buf,uint size,myf MyFlags); -extern int my_setwd(const char *dir,myf MyFlags); -extern int my_lock(File fd,int op,my_off_t start, my_off_t length,myf MyFlags); -extern gptr my_once_alloc(uint Size,myf MyFlags); -extern void my_once_free(void); -extern my_string my_tempnam(const char *dir,const char *pfx,myf MyFlags); -extern File my_open(const char *FileName,int Flags,myf MyFlags); -extern File my_register_filename(File fd, const char *FileName, - enum file_type type_of_file, - uint error_message_number, myf MyFlags); -extern File my_create(const char *FileName,int CreateFlags, - int AccsesFlags, myf MyFlags); -extern int my_close(File Filedes,myf MyFlags); -extern int my_mkdir(const char *dir, int Flags, myf MyFlags); -extern int my_readlink(char *to, const char *filename, myf MyFlags); -extern int my_realpath(char *to, const char *filename, myf MyFlags); -extern File my_create_with_symlink(const char *linkname, const char *filename, - int createflags, int access_flags, - myf MyFlags); -extern int my_delete_with_symlink(const char *name, myf MyFlags); -extern int my_rename_with_symlink(const char *from,const char *to,myf MyFlags); -extern int my_symlink(const char *content, const char *linkname, myf MyFlags); -extern uint my_read(File Filedes,unsigned char *Buffer,uint Count,myf MyFlags); -extern uint my_pread(File Filedes,unsigned char *Buffer,uint Count,my_off_t offset, - myf MyFlags); -extern int my_rename(const char *from,const char *to,myf MyFlags); -extern my_off_t my_seek(File fd,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_tell(File fd,myf MyFlags); -extern uint my_write(File Filedes,const unsigned char *Buffer,uint Count, - myf MyFlags); -extern uint my_pwrite(File Filedes,const unsigned char *Buffer,uint Count, - my_off_t offset,myf MyFlags); -extern uint my_fread(FILE *stream,unsigned char *Buffer,uint Count,myf MyFlags); -extern uint my_fwrite(FILE *stream,const unsigned char *Buffer,uint Count, - myf MyFlags); -extern my_off_t my_fseek(FILE *stream,my_off_t pos,int whence,myf MyFlags); -extern my_off_t my_ftell(FILE *stream,myf MyFlags); extern gptr _mymalloc(size_t uSize,const char *sFile, uint uLine, myf MyFlag); extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, @@ -423,30 +373,26 @@ extern gptr _myrealloc(gptr pPtr,size_t uSize,const char *sFile, extern gptr my_multi_malloc _VARARGS((myf MyFlags, ...)); extern void _myfree(gptr pPtr,const char *sFile,uint uLine, myf MyFlag); extern int _sanity(const char *sFile,unsigned int uLine); -extern gptr _my_memdup(const unsigned char *from, size_t length, - const char *sFile, uint uLine,myf MyFlag); -extern my_string _my_strdup(const char *from, const char *sFile, uint uLine, - myf MyFlag); #ifndef TERMINATE extern void TERMINATE(FILE *file); #endif -extern void init_glob_errs(void); +extern void ma_init_glob_errs(void); extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags); extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags); extern int my_fclose(FILE *fd,myf MyFlags); extern int my_chsize(File fd,my_off_t newlength,myf MyFlags); -extern int my_error _VARARGS((int nr,myf MyFlags, ...)); -extern int my_printf_error _VARARGS((uint my_err, const char *format, +extern int ma_error _VARARGS((int nr,myf MyFlags, ...)); +extern int ma_printf_error _VARARGS((uint my_err, const char *format, myf MyFlags, ...) __attribute__ ((format (printf, 2, 4)))); -extern int my_vsnprintf( char *str, size_t n, +extern int ma_vsnprintf( char *str, size_t n, const char *format, va_list ap ); -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); -extern int my_message(uint my_err, const char *str,myf MyFlags); -extern int my_message_no_curses(uint my_err, const char *str,myf MyFlags); -extern int my_message_curses(uint my_err, const char *str,myf MyFlags); -extern void my_init(void); -extern void my_end(int infoflag); +extern int ma_snprintf(char* to, size_t n, const char* fmt, ...); +extern int ma_message(uint my_err, const char *str,myf MyFlags); +extern int _mariadb_stderr_out(unsigned int error, const char *errmsg, myf MyFlags); + +extern void ma_init(void); +extern void ma_end(int infoflag); extern int my_redel(const char *from, const char *to, int MyFlags); extern int my_copystat(const char *from, const char *to, int MyFlags); extern my_string my_filename(File fd); @@ -465,23 +411,23 @@ extern void casedn(my_string str,uint length); extern void caseup_str(my_string str); extern void casedn_str(my_string str); extern void case_sort(my_string str,uint length); -extern uint dirname_part(my_string to,const char *name); -extern uint dirname_length(const char *name); +extern uint ma_dirname_part(my_string to,const char *name); +extern uint ma_dirname_length(const char *name); #define base_name(A) (A+dirname_length(A)) extern int test_if_hard_path(const char *dir_name); -extern char *convert_dirname(my_string name); +extern char *ma_convert_dirname(my_string name); extern void to_unix_path(my_string name); -extern my_string fn_ext(const char *name); +extern my_string ma_fn_ext(const char *name); extern my_string fn_same(my_string toname,const char *name,int flag); -extern my_string fn_format(my_string to,const char *name,const char *dsk, +extern my_string ma_fn_format(my_string to,const char *name,const char *dsk, const char *form,int flag); -extern size_s strlength(const char *str); -extern void pack_dirname(my_string to,const char *from); -extern uint unpack_dirname(my_string to,const char *from); -extern uint cleanup_dirname(my_string to,const char *from); -extern uint system_filename(my_string to,const char *from); -extern my_string unpack_filename(my_string to,const char *from); -extern my_string intern_filename(my_string to,const char *from); +extern size_s ma_strlength(const char *str); +extern void ma_pack_dirname(my_string to,const char *from); +extern uint unma_pack_dirname(my_string to,const char *from); +extern uint ma_cleanup_dirname(my_string to,const char *from); +extern uint ma_system_filename(my_string to,const char *from); +extern my_string ma_unpack_filename(my_string to,const char *from); +extern my_string ma_intern_filename(my_string to,const char *from); extern my_string directory_file_name(my_string dst, const char *src); extern int pack_filename(my_string to, const char *name, size_s max_length); extern my_string my_path(my_string to,const char *progname, @@ -495,6 +441,7 @@ extern int my_strsortcmp(const char *s,const char *t); extern int my_casecmp(const char *s,const char *t,uint length); extern int my_sortcmp(const char *s,const char *t,uint length); extern int my_sortncmp(const char *s,uint s_len, const char *t,uint t_len); +#ifdef TBR extern WF_PACK *wf_comp(my_string str); extern int wf_test(struct wild_file_pack *wf_pack,const char *name); extern void wf_end(struct wild_file_pack *buffer); @@ -553,65 +500,61 @@ extern my_bool real_open_cached_file(IO_CACHE *cache); extern void close_cached_file(IO_CACHE *cache); File create_temp_file(char *to, const char *dir, const char *pfx, int mode, myf MyFlags); -#define my_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO) -#define my_init_dynamic_array_ci(A,B,C,D) init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) -extern my_bool init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, +#define ma_init_dynamic_array(A,B,C,D) init_dynamic_array(A,B,C,D CALLER_INFO) +#endif +extern my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array,uint element_size, uint init_alloc,uint alloc_increment CALLER_INFO_PROTO); -extern my_bool insert_dynamic(DYNAMIC_ARRAY *array,gptr element); -extern unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array); -extern unsigned char *pop_dynamic(DYNAMIC_ARRAY*); -extern my_bool set_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); -extern void get_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); -extern void delete_dynamic(DYNAMIC_ARRAY *array); -extern void delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); -extern void freeze_size(DYNAMIC_ARRAY *array); +#define ma_init_dynamic_array_ci(A,B,C,D) ma_init_dynamic_array(A,B,C,D ORIG_CALLER_INFO) +extern my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array,gptr element); +extern unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array); +extern unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY*); +extern my_bool ma_set_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); +extern void ma_get_dynamic(DYNAMIC_ARRAY *array,gptr element,uint array_index); +extern void ma_delete_dynamic(DYNAMIC_ARRAY *array); +extern void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint array_index); +extern void ma_freeze_size(DYNAMIC_ARRAY *array); #define dynamic_array_ptr(array,array_index) ((array)->buffer+(array_index)*(array)->size_of_element) #define dynamic_element(array,array_index,type) ((type)((array)->buffer) +(array_index)) -#define push_dynamic(A,B) insert_dynamic(A,B) +#define push_dynamic(A,B) ma_insert_dynamic(A,B) -extern int find_type(my_string x,TYPELIB *typelib,uint full_name); -extern void make_type(my_string to,uint nr,TYPELIB *typelib); -extern const char *get_type(TYPELIB *typelib,uint nr); -extern my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, +extern int ma_find_type(my_string x,TYPELIB *typelib,uint full_name); +extern void ma_make_type(my_string to,uint nr,TYPELIB *typelib); +extern const char *ma_get_type(TYPELIB *typelib,uint nr); +extern my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, size_t init_alloc, size_t alloc_increment); -extern my_bool dynstr_append(DYNAMIC_STRING *str, const char *append); -my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, +extern my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append); +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t length); -extern my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str); -extern my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); -extern void dynstr_free(DYNAMIC_STRING *str); +extern my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str); +extern my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size); +extern void ma_dynstr_free(DYNAMIC_STRING *str); void set_all_changeable_vars(CHANGEABLE_VAR *vars); my_bool set_changeable_var(my_string str,CHANGEABLE_VAR *vars); my_bool set_changeable_varval(const char *var, ulong val, CHANGEABLE_VAR *vars); #ifdef HAVE_MLOCK -extern unsigned char *my_malloc_lock(size_t length,myf flags); -extern void my_free_lock(unsigned char *ptr,myf flags); +extern unsigned char *ma_malloc_lock(size_t length,myf flags); +extern void ma_free_lock(unsigned char *ptr,myf flags); #else -#define my_malloc_lock(A,B) my_malloc((A),(B)) -#define my_free_lock(A,B) my_free((A),(B)) +#define ma_malloc_lock(A,B) ma_malloc((A),(B)) +#define ma_free_lock(A,B) ma_free((A),(B)) #endif -#define alloc_root_inited(A) ((A)->min_malloc != 0) -void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); -gptr alloc_root(MEM_ROOT *mem_root, size_t Size); -void free_root(MEM_ROOT *root, myf MyFLAGS); -char *strdup_root(MEM_ROOT *root,const char *str); -char *memdup_root(MEM_ROOT *root,const char *str, size_t len); -void load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv); -void free_defaults(char **argv); -void print_defaults(const char *conf_file, const char **groups); -my_bool my_compress(unsigned char *, size_t *, size_t *); -my_bool my_uncompress(unsigned char *, size_t *, size_t *); -unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen); +#define ma_alloc_root_inited(A) ((A)->min_malloc != 0) +void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size); +gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size); +void ma_free_root(MA_MEM_ROOT *root, myf MyFLAGS); +char *ma_strdup_root(MA_MEM_ROOT *root,const char *str); +char *ma_memdup_root(MA_MEM_ROOT *root,const char *str, size_t len); +void ma_free_defaults(char **argv); +void ma_print_defaults(const char *conf_file, const char **groups); +my_bool _mariadb_compress(unsigned char *, size_t *, size_t *); +my_bool _mariadb_uncompress(unsigned char *, size_t *, size_t *); +unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen); ulong checksum(const unsigned char *mem, uint count); #if defined(_MSC_VER) && !defined(_WIN32) extern void sleep(int sec); #endif -#ifdef _WIN32 -extern my_bool have_tcpip; /* Is set if tcpip is used */ -#endif #ifdef __cplusplus } diff --git a/include/mysql_async.h b/include/mariadb_async.h similarity index 100% rename from include/mysql_async.h rename to include/mariadb_async.h diff --git a/include/mysql_com.h b/include/mariadb_com.h similarity index 89% rename from include/mysql_com.h rename to include/mariadb_com.h index 4c684d74..15e0043c 100644 --- a/include/mysql_com.h +++ b/include/mariadb_com.h @@ -48,6 +48,10 @@ #define MYSQL_SERVICENAME "MySql" #endif /* _WIN32 */ +/* for use in mysql client tools only */ +#define MYSQL_AUTODETECT_CHARSET_NAME "auto" +#define BINCMP_FLAG 131072 + enum mysql_enum_shutdown_level { SHUTDOWN_DEFAULT = 0, @@ -87,6 +91,7 @@ enum enum_server_command COM_SET_OPTION = 27, COM_STMT_FETCH = 28, COM_DAEMON, + COM_MULTI = 254, COM_END }; @@ -128,7 +133,7 @@ enum enum_server_command #define REFRESH_READ_LOCK 16384 /* Lock tables for read */ #define REFRESH_FAST 32768 /* Intern flag */ -#define CLIENT_LONG_PASSWORD 1 /* new more secure passwords */ +#define CLIENT_MYSQL 1 #define CLIENT_FOUND_ROWS 2 /* Found instead of affected rows */ #define CLIENT_LONG_FLAG 4 /* Get all column flags */ #define CLIENT_CONNECT_WITH_DB 8 /* One can specify db on connect */ @@ -154,7 +159,16 @@ enum enum_server_command #define CLIENT_SSL_VERIFY_SERVER_CERT (1UL << 30) #define CLIENT_REMEMBER_OPTIONS (1UL << 31) -#define CLIENT_SUPPORTED_FLAGS (CLIENT_LONG_PASSWORD | \ +/* MariaDB specific capabilities */ +#define MARIADB_CLIENT_FLAGS 0xFFFFFFFF00000000ULL +#define MARIADB_CLIENT_PROGRESS (1ULL << 32) +#define MARIADB_CLIENT_COM_MULTI (1ULL << 33) +//#define MARIADB_CLIENT_EXTENDED_FLAGS (1ULL << 63) + +#define MARIADB_CLIENT_SUPPORTED_FLAGS (MARIADB_CLIENT_PROGRESS |\ + MARIADB_CLIENT_COM_MULTI) + +#define CLIENT_SUPPORTED_FLAGS (CLIENT_MYSQL |\ CLIENT_FOUND_ROWS |\ CLIENT_LONG_FLAG |\ CLIENT_CONNECT_WITH_DB |\ @@ -178,7 +192,7 @@ enum enum_server_command CLIENT_PLUGIN_AUTH |\ CLIENT_CONNECT_ATTRS) -#define CLIENT_CAPABILITIES (CLIENT_LONG_PASSWORD |\ +#define CLIENT_CAPABILITIES (CLIENT_MYSQL | \ CLIENT_LONG_FLAG |\ CLIENT_TRANSACTIONS |\ CLIENT_SECURE_CONNECTION |\ @@ -209,6 +223,12 @@ enum enum_server_command #define NET_WRITE_TIMEOUT 60 /* Timeout on write */ #define NET_WAIT_TIMEOUT 8*60*60 /* Wait for new query */ +/* for server integration (mysqlbinlog) */ +#define LIST_PROCESS_HOST_LEN 64 +#define MYSQL50_TABLE_NAME_PREFIX "#mysql50#" +#define MYSQL50_TABLE_NAME_PREFIX_LENGTH (sizeof(MYSQL50_TABLE_NAME_PREFIX)-1) +#define SAFE_NAME_LEN (NAME_LEN + MYSQL50_TABLE_NAME_PREFIX_LENGTH) + struct st_ma_pvio; typedef struct st_ma_pvio MARIADB_PVIO; @@ -238,6 +258,7 @@ typedef struct st_net { MARIADB_PVIO *pvio; unsigned char *buff; unsigned char *buff_end,*write_pos,*read_pos; + unsigned char *mbuff, *mbuff_end, *mbuff_pos; my_socket fd; /* For Perl DBI/dbd */ unsigned long remain_in_buf,length; unsigned long buf_length, where_b; @@ -280,6 +301,14 @@ enum enum_field_types { MYSQL_TYPE_DECIMAL, MYSQL_TYPE_TINY, MYSQL_TYPE_DATETIME, MYSQL_TYPE_YEAR, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_BIT, + /* + the following types are not used by client, + only for mysqlbinlog!! + */ + MYSQL_TYPE_TIMESTAMP2, + MYSQL_TYPE_DATETIME2, + MYSQL_TYPE_TIME2, + /* --------------------------------------------- */ MYSQL_TYPE_NEWDECIMAL=246, MYSQL_TYPE_ENUM=247, MYSQL_TYPE_SET=248, @@ -330,11 +359,11 @@ int my_net_init(NET *net, MARIADB_PVIO *pvio); void net_end(NET *net); void net_clear(NET *net); int net_flush(NET *net); -int my_net_write(NET *net,const char *packet, size_t len); +int my_net_write(NET *net,const unsigned char *packet, size_t len); int net_write_command(NET *net,unsigned char command,const char *packet, size_t len); int net_real_write(NET *net,const char *packet, size_t len); -unsigned long my_net_read(NET *net); +extern unsigned long my_net_read(NET *net); struct rand_struct { unsigned long seed1,seed2,max_value; @@ -343,7 +372,7 @@ struct rand_struct { /* The following is for user defined functions */ -enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT}; +enum Item_result {STRING_RESULT,REAL_RESULT,INT_RESULT,ROW_RESULT,DECIMAL_RESULT}; typedef struct st_udf_args { @@ -397,10 +426,10 @@ void hash_password(unsigned long *result, const char *password, size_t len); /* Some other useful functions */ -void load_defaults(const char *conf_file, const char **groups, +void mariadb_load_defaults(const char *conf_file, const char **groups, int *argc, char ***argv); -my_bool my_thread_init(void); -void my_thread_end(void); +my_bool ma_thread_init(void); +void ma_thread_end(void); #ifdef __cplusplus } diff --git a/include/m_ctype.h b/include/mariadb_ctype.h similarity index 65% rename from include/m_ctype.h rename to include/mariadb_ctype.h index f25f1104..e5d38f3d 100644 --- a/include/m_ctype.h +++ b/include/mariadb_ctype.h @@ -20,8 +20,8 @@ Notes: my_global.h should be included before ctype.h */ -#ifndef _m_ctype_h -#define _m_ctype_h +#ifndef _mariadb_ctype_h +#define _mariadb_ctype_h #include @@ -34,9 +34,10 @@ extern "C" { #define MADB_DEFAULT_CHARSET_NAME "latin1" #define MADB_DEFAULT_COLLATION_NAME "latin1_swedish_ci" +#define MADB_AUTODETECT_CHARSET_NAME "auto" /* we use the mysqlnd implementation */ -typedef struct charset_info_st +typedef struct ma_charset_info_st { unsigned int nr; /* so far only 1 byte for charset */ unsigned int state; @@ -49,20 +50,20 @@ typedef struct charset_info_st unsigned int char_maxlen; unsigned int (*mb_charlen)(unsigned int c); unsigned int (*mb_valid)(const char *start, const char *end); -} CHARSET_INFO; +} MARIADB_CHARSET_INFO; -extern const CHARSET_INFO compiled_charsets[]; -extern CHARSET_INFO *default_charset_info; -extern CHARSET_INFO *my_charset_bin; -extern CHARSET_INFO *my_charset_latin1; -extern CHARSET_INFO *my_charset_utf8_general_ci; -extern CHARSET_INFO *my_charset_utf16le_general_ci; +extern const MARIADB_CHARSET_INFO mariadb_compiled_charsets[]; +extern MARIADB_CHARSET_INFO *ma_default_charset_info; +extern MARIADB_CHARSET_INFO *ma_charset_bin; +extern MARIADB_CHARSET_INFO *ma_charset_latin1; +extern MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci; +extern MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci; -CHARSET_INFO *find_compiled_charset(unsigned int cs_number); -CHARSET_INFO *find_compiled_charset_by_name(const char *name); +MARIADB_CHARSET_INFO *find_compiled_charset(unsigned int cs_number); +MARIADB_CHARSET_INFO *find_compiled_charset_by_name(const char *name); -size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); -size_t mysql_cset_escape_slashes(const CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); +size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char *escapestr, size_t escapestr_len); char* madb_get_os_character_set(void); #ifdef _WIN32 int madb_get_windows_cp(const char *charset); diff --git a/include/ma_dyncol.h b/include/mariadb_dyncol.h similarity index 98% rename from include/ma_dyncol.h rename to include/mariadb_dyncol.h index 3b5c8ae3..f2c13aa3 100644 --- a/include/ma_dyncol.h +++ b/include/mariadb_dyncol.h @@ -115,7 +115,7 @@ struct st_dynamic_column_value double double_value; struct { MYSQL_LEX_STRING value; - CHARSET_INFO *charset; + MARIADB_CHARSET_INFO *charset; } string; #ifndef LIBMARIADB struct { @@ -225,7 +225,7 @@ void mariadb_dyncol_free(DYNAMIC_COLUMN *str); /* conversion of values to 3 base types */ enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, - CHARSET_INFO *cs, my_bool quote); + MARIADB_CHARSET_INFO *cs, my_bool quote); enum enum_dyncol_func_result mariadb_dyncol_val_long(longlong *ll, DYNAMIC_COLUMN_VALUE *val); enum enum_dyncol_func_result diff --git a/include/my_stmt.h b/include/mariadb_stmt.h similarity index 97% rename from include/my_stmt.h rename to include/mariadb_stmt.h index 0dfb1ba1..cfe4d8d9 100644 --- a/include/my_stmt.h +++ b/include/mariadb_stmt.h @@ -172,7 +172,7 @@ typedef int (*mysql_stmt_fetch_row_func)(MYSQL_STMT *stmt, unsigned char **row) struct st_mysql_stmt { - MEM_ROOT mem_root; + MA_MEM_ROOT mem_root; MYSQL *mysql; unsigned long stmt_id; unsigned long flags;/* cursor is set here */ @@ -219,7 +219,7 @@ extern MYSQL_PS_CONVERSION mysql_ps_fetch_functions[MYSQL_TYPE_GEOMETRY + 1]; unsigned long net_safe_read(MYSQL *mysql); void mysql_init_ps_subsystem(void); unsigned long net_field_length(unsigned char **packet); -int simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, +int ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check, void *opt_arg); /* * function prototypes @@ -253,3 +253,4 @@ my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt); unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt); int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt); my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt); +int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, const char *stmt_str, size_t length); diff --git a/include/mysql_version.h.in b/include/mariadb_version.h.in similarity index 90% rename from include/mysql_version.h.in rename to include/mariadb_version.h.in index 2e9eb6f1..d0fa54f8 100644 --- a/include/mysql_version.h.in +++ b/include/mariadb_version.h.in @@ -3,6 +3,9 @@ /* Version numbers for protocol & mysqld */ +#ifndef _mariadb_version_h_ +#define _mariadb_version_h_ + #ifdef _CUSTOMCONFIG_ #include #else @@ -26,3 +29,4 @@ #endif #endif +#endif /* _mariadb_version_h_ */ diff --git a/include/my_alarm.h b/include/my_alarm.h deleted file mode 100644 index b6c5ca6a..00000000 --- a/include/my_alarm.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - File to include when we want to use alarm or a loop_counter to display - some information when a program is running -*/ -#ifndef _my_alarm_h -#define _my_alarm_h -#ifdef __cplusplus -extern "C" { -#endif - -extern int volatile my_have_got_alarm; -extern ulong my_time_to_wait_for_lock; - -#if defined(HAVE_ALARM) && !defined(NO_ALARM_LOOP) -#include -#define ALARM_VARIABLES uint alarm_old=0; \ - sig_return alarm_signal=0 -#define ALARM_INIT my_have_got_alarm=0 ; \ - alarm_old=(uint) alarm(MY_HOW_OFTEN_TO_ALARM); \ - alarm_signal=signal(SIGALRM,my_set_alarm_variable); -#define ALARM_END VOID(signal(SIGALRM,alarm_signal)); \ - VOID(alarm(alarm_old)); -#define ALARM_TEST my_have_got_alarm -#ifdef DONT_REMEMBER_SIGNAL -#define ALARM_REINIT VOID(alarm(MY_HOW_OFTEN_TO_ALARM)); \ - VOID(signal(SIGALRM,my_set_alarm_variable));\ - my_have_got_alarm=0; -#else -#define ALARM_REINIT VOID(alarm((uint) MY_HOW_OFTEN_TO_ALARM)); \ - my_have_got_alarm=0; -#endif /* DONT_REMEMBER_SIGNAL */ -#else -#define ALARM_VARIABLES long alarm_pos=0,alarm_end_pos=MY_HOW_OFTEN_TO_WRITE-1 -#define ALARM_INIT -#define ALARM_END -#define ALARM_TEST (alarm_pos++ >= alarm_end_pos) -#define ALARM_REINIT alarm_end_pos+=MY_HOW_OFTEN_TO_WRITE -#endif /* HAVE_ALARM */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/my_base.h b/include/my_base.h deleted file mode 100644 index 6275adab..00000000 --- a/include/my_base.h +++ /dev/null @@ -1,287 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This file includes constants used with all databases */ -/* Author: Michael Widenius */ - -#ifndef _my_base_h -#define _my_base_h - -#ifndef stdin /* Included first in handler */ -#define USES_TYPES /* my_dir with sys/types is included */ -#define CHSIZE_USED -#include -#include /* This includes types */ -#include -#include -#include -#ifdef MSDOS -#include /* Neaded for sopen() */ -#endif -#if !defined(USE_MY_FUNC) && !defined(THREAD) -#include /* For faster code, after test */ -#endif /* USE_MY_FUNC */ -#endif /* stdin */ -#include - -/* The following is bits in the flag parameter to ha_open() */ - -#define HA_OPEN_ABORT_IF_LOCKED 0 /* default */ -#define HA_OPEN_WAIT_IF_LOCKED 1 -#define HA_OPEN_IGNORE_IF_LOCKED 2 -#define HA_OPEN_TMP_TABLE 4 /* Table is a temp table */ -#define HA_OPEN_DELAY_KEY_WRITE 8 /* Don't update index */ -#define HA_OPEN_ABORT_IF_CRASHED 16 -#define HA_OPEN_FOR_REPAIR 32 /* open even if crashed */ - - /* The following is parameter to ha_rkey() how to use key */ - -enum ha_rkey_function { - HA_READ_KEY_EXACT, /* Find first record else error */ - HA_READ_KEY_OR_NEXT, /* Record or next record */ - HA_READ_KEY_OR_PREV, /* Record or previous */ - HA_READ_AFTER_KEY, /* Find next rec. after key-record */ - HA_READ_BEFORE_KEY, /* Find next rec. before key-record */ - HA_READ_PREFIX, /* Key which as same prefix */ - HA_READ_PREFIX_LAST /* Last key with the same prefix */ -}; - - /* The following is parameter to ha_extra() */ - -enum ha_extra_function { - HA_EXTRA_NORMAL=0, /* Optimize for space (def) */ - HA_EXTRA_QUICK=1, /* Optimize for speed */ - HA_EXTRA_RESET=2, /* Reset database to after open */ - HA_EXTRA_CACHE=3, /* Cash record in HA_rrnd() */ - HA_EXTRA_NO_CACHE=4, /* End cacheing of records (def) */ - HA_EXTRA_NO_READCHECK=5, /* No readcheck on update */ - HA_EXTRA_READCHECK=6, /* Use readcheck (def) */ - HA_EXTRA_KEYREAD=7, /* Read only key to database */ - HA_EXTRA_NO_KEYREAD=8, /* Normal read of records (def) */ - HA_EXTRA_NO_USER_CHANGE=9, /* No user is allowed to write */ - HA_EXTRA_KEY_CACHE=10, - HA_EXTRA_NO_KEY_CACHE=11, - HA_EXTRA_WAIT_LOCK=12, /* Wait until file is avalably (def) */ - HA_EXTRA_NO_WAIT_LOCK=13, /* If file is locked, return quickly */ - HA_EXTRA_WRITE_CACHE=14, /* Use write cache in ha_write() */ - HA_EXTRA_FLUSH_CACHE=15, /* flush write_record_cache */ - HA_EXTRA_NO_KEYS=16, /* Remove all update of keys */ - HA_EXTRA_KEYREAD_CHANGE_POS=17, /* Keyread, but change pos */ - /* xxxxchk -r must be used */ - HA_EXTRA_REMEMBER_POS=18, /* Remember pos for next/prev */ - HA_EXTRA_RESTORE_POS=19, - HA_EXTRA_REINIT_CACHE=20, /* init cache from current record */ - HA_EXTRA_FORCE_REOPEN=21, /* Datafile have changed on disk */ - HA_EXTRA_FLUSH, /* Flush tables to disk */ - HA_EXTRA_NO_ROWS, /* Don't write rows */ - HA_EXTRA_RESET_STATE, /* Reset positions */ - HA_EXTRA_IGNORE_DUP_KEY, /* Dup keys don't rollback everything*/ - HA_EXTRA_NO_IGNORE_DUP_KEY, - HA_EXTRA_DONT_USE_CURSOR_TO_UPDATE /* Cursor will not be used for update */ -}; - - /* The following is parameter to ha_panic() */ - -enum ha_panic_function { - HA_PANIC_CLOSE, /* Close all databases */ - HA_PANIC_WRITE, /* Unlock and write status */ - HA_PANIC_READ /* Lock and read keyinfo */ -}; - - /* The following is parameter to ha_create(); keytypes */ - -enum ha_base_keytype { - HA_KEYTYPE_END=0, - HA_KEYTYPE_TEXT=1, /* Key is sorted as letters */ - HA_KEYTYPE_BINARY=2, /* Key is sorted as unsigned chars */ - HA_KEYTYPE_SHORT_INT=3, - HA_KEYTYPE_LONG_INT=4, - HA_KEYTYPE_FLOAT=5, - HA_KEYTYPE_DOUBLE=6, - HA_KEYTYPE_NUM=7, /* Not packed num with pre-space */ - HA_KEYTYPE_USHORT_INT=8, - HA_KEYTYPE_ULONG_INT=9, - HA_KEYTYPE_LONGLONG=10, - HA_KEYTYPE_ULONGLONG=11, - HA_KEYTYPE_INT24=12, - HA_KEYTYPE_UINT24=13, - HA_KEYTYPE_INT8=14, - HA_KEYTYPE_VARTEXT=15, /* Key is sorted as letters */ - HA_KEYTYPE_VARBINARY=16 /* Key is sorted as unsigned chars */ -}; - -#define HA_MAX_KEYTYPE 31 /* Must be log2-1 */ - - /* These flags kan be OR:ed to key-flag */ - -#define HA_NOSAME 1 /* Set if not dupplicated records */ -#define HA_PACK_KEY 2 /* Pack string key to previous key */ -#define HA_AUTO_KEY 16 -#define HA_BINARY_PACK_KEY 32 /* Packing of all keys to prev key */ -#define HA_FULLTEXT 128 /* SerG: for full-text search */ -#define HA_UNIQUE_CHECK 256 /* Check the key for uniqueness */ - - /* Automatic bits in key-flag */ - -#define HA_SPACE_PACK_USED 4 /* Test for if SPACE_PACK used */ -#define HA_VAR_LENGTH_KEY 8 -#define HA_NULL_PART_KEY 64 -#ifndef ISAM_LIBRARY -#define HA_SORT_ALLOWS_SAME 512 /* Intern bit when sorting records */ -#else -/* poor old NISAM has 8-bit flags :-( */ -#define HA_SORT_ALLOWS_SAME 128 /* Intern bit when sorting records */ -#endif - - /* These flags can be order to key-seg-flag */ - -#define HA_SPACE_PACK 1 /* Pack space in key-seg */ -#define HA_PART_KEY 4 /* Used by MySQL for part-key-cols */ -#define HA_VAR_LENGTH 8 -#define HA_NULL_PART 16 -#define HA_BLOB_PART 32 -#define HA_SWAP_KEY 64 -#define HA_REVERSE_SORT 128 /* Sort key in reverse order */ - - /* optionbits for database */ -#define HA_OPTION_PACK_RECORD 1 -#define HA_OPTION_PACK_KEYS 2 -#define HA_OPTION_COMPRESS_RECORD 4 -#define HA_OPTION_LONG_BLOB_PTR 8 /* new ISAM format */ -#define HA_OPTION_TMP_TABLE 16 -#define HA_OPTION_CHECKSUM 32 -#define HA_OPTION_DELAY_KEY_WRITE 64 -#define HA_OPTION_NO_PACK_KEYS 128 /* Reserved for MySQL */ -#define HA_OPTION_TEMP_COMPRESS_RECORD ((uint) 16384) /* set by isamchk */ -#define HA_OPTION_READ_ONLY_DATA ((uint) 32768) /* Set by isamchk */ - - /* Bits in flag to create() */ - -#define HA_DONT_TOUCH_DATA 1 /* Don't empty datafile (isamchk) */ -#define HA_PACK_RECORD 2 /* Request packed record format */ -#define HA_CREATE_TMP_TABLE 4 -#define HA_CREATE_CHECKSUM 8 -#define HA_CREATE_DELAY_KEY_WRITE 64 - - /* Bits in flag to _status */ - -#define HA_STATUS_POS 1 /* Return position */ -#define HA_STATUS_NO_LOCK 2 /* Don't use external lock */ -#define HA_STATUS_TIME 4 /* Return update time */ -#define HA_STATUS_CONST 8 /* Return constants values */ -#define HA_STATUS_VARIABLE 16 -#define HA_STATUS_ERRKEY 32 -#define HA_STATUS_AUTO 64 - - /* Errorcodes given by functions */ - -#define HA_ERR_KEY_NOT_FOUND 120 /* Didn't find key on read or update */ -#define HA_ERR_FOUND_DUPP_KEY 121 /* Dupplicate key on write */ -#define HA_ERR_RECORD_CHANGED 123 /* Uppdate with is recoverable */ -#define HA_ERR_WRONG_INDEX 124 /* Wrong index given to function */ -#define HA_ERR_CRASHED 126 /* Indexfile is crashed */ -#define HA_ERR_WRONG_IN_RECORD 127 /* Record-file is crashed */ -#define HA_ERR_OUT_OF_MEM 128 /* Record-file is crashed */ -#define HA_ERR_WRONG_COMMAND 131 /* Command not supported */ -#define HA_ERR_OLD_FILE 132 /* old databasfile */ -#define HA_ERR_NO_ACTIVE_RECORD 133 /* No record read in update() */ -#define HA_ERR_RECORD_DELETED 134 /* Intern error-code */ -#define HA_ERR_RECORD_FILE_FULL 135 /* No more room in file */ -#define HA_ERR_INDEX_FILE_FULL 136 /* No more room in file */ -#define HA_ERR_END_OF_FILE 137 /* end in next/prev/first/last */ -#define HA_ERR_UNSUPPORTED 138 /* unsupported extension used */ -#define HA_ERR_TO_BIG_ROW 139 /* Too big row */ -#define HA_WRONG_CREATE_OPTION 140 /* Wrong create option */ -#define HA_ERR_FOUND_DUPP_UNIQUE 141 /* Dupplicate unique on write */ -#define HA_ERR_UNKNOWN_CHARSET 142 /* Can't open charset */ -#define HA_ERR_WRONG_TABLE_DEF 143 -#define HA_ERR_CRASHED_ON_REPAIR 144 /* Last (automatic?) repair failed */ -#define HA_ERR_CRASHED_ON_USAGE 145 /* Table must be repaired */ -#define HA_ERR_LOCK_WAIT_TIMEOUT 146 -#define HA_ERR_LOCK_TABLE_FULL 147 -#define HA_ERR_READ_ONLY_TRANSACTION 148 /* Updates not allowed */ -#define HA_ERR_LOCK_DEADLOCK 149 -#define HA_ERR_CANNOT_ADD_FOREIGN 150 /* Cannot add a foreign key constr. */ -#define HA_ERR_NO_REFERENCED_ROW 151 /* Cannot add a child row */ -#define HA_ERR_ROW_IS_REFERENCED 152 /* Cannot delete a parent row */ - - /* Other constants */ - -#define HA_NAMELEN 64 /* Max length of saved filename */ - - /* Intern constants in databases */ - - /* bits in _search */ -#define SEARCH_FIND 1 -#define SEARCH_NO_FIND 2 -#define SEARCH_SAME 4 -#define SEARCH_BIGGER 8 -#define SEARCH_SMALLER 16 -#define SEARCH_SAVE_BUFF 32 -#define SEARCH_UPDATE 64 -#define SEARCH_PREFIX 128 -#define SEARCH_LAST 256 - - /* bits in opt_flag */ -#define QUICK_USED 1 -#define READ_CACHE_USED 2 -#define READ_CHECK_USED 4 -#define KEY_READ_USED 8 -#define WRITE_CACHE_USED 16 -#define OPT_NO_ROWS 32 - - /* bits in update */ -#define HA_STATE_CHANGED 1 /* Database has changed */ -#define HA_STATE_AKTIV 2 /* Has a current record */ -#define HA_STATE_WRITTEN 4 /* Record is written */ -#define HA_STATE_DELETED 8 -#define HA_STATE_NEXT_FOUND 16 /* Next found record (record before) */ -#define HA_STATE_PREV_FOUND 32 /* Prev found record (record after) */ -#define HA_STATE_NO_KEY 64 /* Last read didn't find record */ -#define HA_STATE_KEY_CHANGED 128 -#define HA_STATE_WRITE_AT_END 256 /* set in _ps_find_writepos */ -#define HA_STATE_BUFF_SAVED 512 /* If current keybuff is info->buff */ -#define HA_STATE_ROW_CHANGED 1024 /* To invalide ROW cache */ -#define HA_STATE_EXTEND_BLOCK 2048 - -enum en_fieldtype { - FIELD_LAST=-1,FIELD_NORMAL,FIELD_SKIPP_ENDSPACE,FIELD_SKIPP_PRESPACE, - FIELD_SKIPP_ZERO,FIELD_BLOB,FIELD_CONSTANT,FIELD_INTERVALL,FIELD_ZERO, - FIELD_VARCHAR,FIELD_CHECK -}; - -enum data_file_type { - STATIC_RECORD,DYNAMIC_RECORD,COMPRESSED_RECORD -}; - -/* For number of records */ -#ifdef BIG_TABLES -typedef my_off_t ha_rows; -#else -typedef ulong ha_rows; -#endif - -#define HA_POS_ERROR (~ (ha_rows) 0) -#define HA_OFFSET_ERROR (~ (my_off_t) 0) - -#if SYSTEM_SIZEOF_OFF_T == 4 -#define MAX_FILE_SIZE INT_MAX32 -#else -#define MAX_FILE_SIZE LONGLONG_MAX -#endif - -#endif /* _my_base_h */ diff --git a/include/my_dir.h b/include/my_dir.h deleted file mode 100644 index 1961ca79..00000000 --- a/include/my_dir.h +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _my_dir_h -#define _my_dir_h -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef MY_DIR_H -#define MY_DIR_H - -#include - - /* Defines for my_dir and my_stat */ - -#define MY_S_IFMT S_IFMT /* type of file */ -#define MY_S_IFDIR S_IFDIR /* directory */ -#define MY_S_IFCHR S_IFCHR /* character special */ -#define MY_S_IFBLK S_IFBLK /* block special */ -#define MY_S_IFREG S_IFREG /* regular */ -#define MY_S_IFIFO S_IFIFO /* fifo */ -#define MY_S_ISUID S_ISUID /* set user id on execution */ -#define MY_S_ISGID S_ISGID /* set group id on execution */ -#define MY_S_ISVTX S_ISVTX /* save swapped text even after use */ -#define MY_S_IREAD S_IREAD /* read permission, owner */ -#define MY_S_IWRITE S_IWRITE /* write permission, owner */ -#define MY_S_IEXEC S_IEXEC /* execute/search permission, owner */ - -#define MY_S_ISDIR(m) (((m) & MY_S_IFMT) == MY_S_IFDIR) -#define MY_S_ISCHR(m) (((m) & MY_S_IFMT) == MY_S_IFCHR) -#define MY_S_ISBLK(m) (((m) & MY_S_IFMT) == MY_S_IFBLK) -#define MY_S_ISREG(m) (((m) & MY_S_IFMT) == MY_S_IFREG) -#define MY_S_ISFIFO(m) (((m) & MY_S_IFMT) == MY_S_IFIFO) - -#define MY_DONT_SORT 512 /* my_lib; Don't sort files */ -#define MY_WANT_STAT 1024 /* my_lib; stat files */ - - /* typedefs for my_dir & my_stat */ - -#ifdef USE_MY_STAT_STRUCT - -typedef struct my_stat -{ - dev_t st_dev; /* major & minor device numbers */ - ino_t st_ino; /* inode number */ - ushort st_mode; /* file permissons (& suid sgid .. bits) */ - short st_nlink; /* number of links to file */ - ushort st_uid; /* user id */ - ushort st_gid; /* group id */ - dev_t st_rdev; /* more major & minor device numbers (???) */ - off_t st_size; /* size of file */ - time_t st_atime; /* time for last read */ - time_t st_mtime; /* time for last contens modify */ - time_t st_ctime; /* time for last inode or contents modify */ -} MY_STAT; - -#else - -#define MY_STAT struct stat /* Orginal struct have what we need */ - -#endif /* USE_MY_STAT_STRUCT */ - -typedef struct fileinfo /* Struct returned from my_dir & my_stat */ -{ - char *name; - MY_STAT mystat; -} FILEINFO; - -typedef struct st_my_dir /* Struct returned from my_dir */ -{ - struct fileinfo *dir_entry; - uint number_off_files; -} MY_DIR; - -extern MY_DIR *my_dir(const char *path,myf MyFlags); -extern void my_dirend(MY_DIR *buffer); -extern MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags); -extern int my_fstat(int filenr, MY_STAT *stat_area, myf MyFlags); - -#endif /* MY_DIR_H */ - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/my_net.h b/include/my_net.h deleted file mode 100644 index 3c4cb8b1..00000000 --- a/include/my_net.h +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* thread safe version of some common functions */ - -/* for thread safe my_inet_ntoa */ -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#if !defined(MSDOS) && !defined(_WIN32) && !defined(__BEOS__) -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif -#endif /* !defined(MSDOS) && !defined(_WIN32) */ - - -/* On SCO you get a link error when refering to h_errno */ -#ifdef SCO -#undef h_errno -#define h_errno errno -#endif - -void my_inet_ntoa(struct in_addr in, char *buf); - -#ifdef __cplusplus -} -#endif diff --git a/include/my_no_pthread.h b/include/my_no_pthread.h deleted file mode 100644 index 328086ec..00000000 --- a/include/my_no_pthread.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - This undefs some pthread mutex locks when one isn't using threads - to make thread safe code, that should also work in single thread - environment, easier to use. -*/ - -#if !defined(_my_no_pthread_h) && !defined(THREAD) -#define _my_no_pthread_h - -#define pthread_mutex_init(A,B) -#define pthread_mutex_lock(A) -#define pthread_mutex_unlock(A) -#define pthread_mutex_destroy(A) - -#endif diff --git a/include/mysql.h b/include/mysql.h index 05365676..6d7d0c8c 100644 --- a/include/mysql.h +++ b/include/mysql.h @@ -53,29 +53,29 @@ typedef int my_socket; #endif #endif #endif -#include "mysql_com.h" -#include "mysql_version.h" -#include "my_list.h" -#include "m_ctype.h" +#include "mariadb_com.h" +#include "mariadb_version.h" +#include "ma_list.h" +#include "mariadb_ctype.h" -#ifndef ST_USED_MEM_DEFINED -#define ST_USED_MEM_DEFINED - typedef struct st_used_mem { /* struct for once_alloc */ - struct st_used_mem *next; /* Next block in use */ +#ifndef ST_MA_USED_MEM_DEFINED +#define ST_MA_USED_MEM_DEFINED + typedef struct st_ma_used_mem { /* struct for once_alloc */ + struct st_ma_used_mem *next; /* Next block in use */ size_t left; /* memory left in block */ size_t size; /* Size of block */ - } USED_MEM; + } MA_USED_MEM; - typedef struct st_mem_root { - USED_MEM *free; - USED_MEM *used; - USED_MEM *pre_alloc; + typedef struct st_ma_mem_root { + MA_USED_MEM *free; + MA_USED_MEM *used; + MA_USED_MEM *pre_alloc; size_t min_malloc; size_t block_size; unsigned int block_num; unsigned int first_block_usage; void (*error_handler)(void); - } MEM_ROOT; + } MA_MEM_ROOT; #endif extern unsigned int mysql_port; @@ -126,9 +126,6 @@ extern unsigned int mariadb_deinitialize_ssl; typedef unsigned long long my_ulonglong; #endif -/* mysql compatibility macro */ -#define mysql_options4(A,B,C,D) mysql_optionsv((A),(B),(C),(D)) - #define SET_CLIENT_ERROR(a, b, c, d) \ { \ (a)->net.last_errno= (b);\ @@ -137,7 +134,7 @@ extern unsigned int mariadb_deinitialize_ssl; } /* For mysql_async.c */ -#define set_mysql_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) +#define set_mariadb_error(A,B,C) SET_CLIENT_ERROR((A),(B),(C),0) #define unknown_sqlstate SQLSTATE_UNKNOWN #define CLEAR_CLIENT_ERROR(a) \ @@ -162,9 +159,15 @@ extern unsigned int mariadb_deinitialize_ssl; my_ulonglong rows; unsigned int fields; MYSQL_ROWS *data; - MEM_ROOT alloc; + MA_MEM_ROOT alloc; } MYSQL_DATA; + enum mariadb_com_multi { + MARIADB_COM_MULTI_END, + MARIADB_COM_MULTI_BEGIN, + MARIADB_COM_MULTI_CANCEL + }; + enum mysql_option { MYSQL_OPT_CONNECT_TIMEOUT, @@ -222,7 +225,19 @@ extern unsigned int mariadb_deinitialize_ssl; MYSQL_OPT_CONNECT_ATTRS, /* for mysql_get_optionv */ MARIADB_OPT_USERDATA, MARIADB_OPT_SSL_CIPHER_STRENGTH, - MARIADB_OPT_CONNECTION_HANDLER + MARIADB_OPT_CONNECTION_HANDLER, + MARIADB_OPT_PORT, + MARIADB_OPT_UNIXSOCKET, + MARIADB_OPT_PASSWORD, + MARIADB_OPT_HOST, + MARIADB_OPT_USER, + MARIADB_OPT_SCHEMA, + MARIADB_OPT_DEBUG, + MARIADB_OPT_FOUND_ROWS, + MARIADB_OPT_MULTI_RESULTS, + MARIADB_OPT_MULTI_STATEMENTS, + MARIADB_OPT_INTERACTIVE, + MARIADB_OPT_COM_MULTI, }; enum mariadb_value { @@ -233,7 +248,7 @@ extern unsigned int mariadb_deinitialize_ssl; MARIADB_CLIENT_VERSION_ID, MARIADB_CONNECTION_ASYNC_TIMEOUT, MARIADB_CONNECTION_ASYNC_TIMEOUT_MS, - MARIADB_CONNECTION_CHARSET_INFO, + MARIADB_CONNECTION_MARIADB_CHARSET_INFO, MARIADB_CONNECTION_ERROR, MARIADB_CONNECTION_ERROR_ID, MARIADB_CONNECTION_HOST, @@ -309,21 +324,22 @@ struct st_mysql_options { void *unused_0; char *host,*user,*passwd,*unix_socket,*server_version,*host_info; char *info,*db; - const struct charset_info_st *charset; /* character set */ + const struct ma_charset_info_st *charset; /* character set */ MYSQL_FIELD *fields; - MEM_ROOT field_alloc; + MA_MEM_ROOT field_alloc; my_ulonglong affected_rows; my_ulonglong insert_id; /* id if insert on table with NEXTNR */ my_ulonglong extra_info; /* Used by mysqlshow */ unsigned long thread_id; /* Id for connection in server */ unsigned long packet_length; - unsigned int port; - unsigned long client_flag,server_capabilities; /* changed from int to long in 4.1 protocol */ - unsigned int protocol_version; - unsigned int field_count; - unsigned int server_status; - unsigned int server_language; - unsigned int warning_count; /* warning count, added in 4.1 protocol */ + unsigned int port; + unsigned long long client_flag; + unsigned long long server_capabilities; /* changed from long to longlong in 10.2 protocol */ + unsigned int protocol_version; + unsigned int field_count; + unsigned int server_status; + unsigned int server_language; + unsigned int warning_count; /* warning count, added in 4.1 protocol */ struct st_mysql_options options; enum mysql_status status; my_bool free_me; /* If free in mysql_close */ @@ -333,7 +349,7 @@ struct st_mysql_options { my_bool unused_2; void *unused_3, *unused_4, *unused_5, *unused_6; LIST *stmts; - const struct st_mysql_methods *methods; + const struct st_mariadb_methods *methods; void *thd; my_bool *unbuffered_fetch_owner; char *info_buffer; @@ -346,7 +362,7 @@ typedef struct st_mysql_res { MYSQL_FIELD *fields; MYSQL_DATA *data; MYSQL_ROWS *data_cursor; - MEM_ROOT field_alloc; + MA_MEM_ROOT field_alloc; MYSQL_ROW row; /* If unbuffered read */ MYSQL_ROW current_row; /* buffer to current row */ unsigned long *lengths; /* column lengths of current row */ @@ -355,13 +371,13 @@ typedef struct st_mysql_res { my_bool is_ps; } MYSQL_RES; +#ifndef _mysql_time_h_ enum enum_mysql_timestamp_type { MYSQL_TIMESTAMP_NONE= -2, MYSQL_TIMESTAMP_ERROR= -1, MYSQL_TIMESTAMP_DATE= 0, MYSQL_TIMESTAMP_DATETIME= 1, MYSQL_TIMESTAMP_TIME= 2 }; - typedef struct st_mysql_time { unsigned int year, month, day, hour, minute, second; @@ -369,6 +385,7 @@ typedef struct st_mysql_time my_bool neg; enum enum_mysql_timestamp_type time_type; } MYSQL_TIME; +#endif #define AUTO_SEC_PART_DIGITS 31 #define SEC_PART_DIGITS 6 @@ -395,7 +412,7 @@ typedef struct character_set /* Local infile support functions */ #define LOCAL_INFILE_ERROR_LEN 512 -#include "my_stmt.h" +#include "mariadb_stmt.h" void STDCALL mysql_set_local_infile_handler(MYSQL *mysql, int (*local_infile_init)(void **, const char *, void *), @@ -480,6 +497,8 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql); MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql); int STDCALL mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg); +int STDCALL mysql_options4(MYSQL *mysql,enum mysql_option option, + const void *arg1, const void *arg2); void STDCALL mysql_free_result(MYSQL_RES *result); void STDCALL mysql_data_seek(MYSQL_RES *result, my_ulonglong offset); @@ -494,9 +513,6 @@ unsigned long STDCALL mysql_escape_string(char *to,const char *from, unsigned long STDCALL mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, unsigned long length); -void STDCALL mysql_debug(const char *debug); -#define mysql_debug_init(A) mysql_debug((A)); -void STDCALL mysql_debug_end(void); unsigned int STDCALL mysql_thread_safe(void); unsigned int STDCALL mysql_warning_count(MYSQL *mysql); const char * STDCALL mysql_sqlstate(MYSQL *mysql); @@ -510,10 +526,10 @@ const char * STDCALL mysql_get_client_info(void); unsigned long STDCALL mysql_get_client_version(void); my_bool STDCALL mariadb_connection(MYSQL *mysql); const char * STDCALL mysql_get_server_name(MYSQL *mysql); -CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname); -CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr); -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname); +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr); +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); int STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...); int STDCALL mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...); int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg); @@ -542,8 +558,6 @@ int STDCALL mysql_select_db_cont(int *ret, MYSQL *mysql, int ready_status); int STDCALL mysql_stmt_next_result_start(int *ret, MYSQL_STMT *stmt); int STDCALL mysql_stmt_next_result_cont(int *ret, MYSQL_STMT *stmt, int status); -int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); -int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); int STDCALL mysql_set_character_set_start(int *ret, MYSQL *mysql, const char *csname); int STDCALL mysql_set_character_set_cont(int *ret, MYSQL *mysql, @@ -603,7 +617,6 @@ int STDCALL mysql_stat_cont(const char **ret, MYSQL *mysql, int status); int STDCALL mysql_free_result_start(MYSQL_RES *result); int STDCALL mysql_free_result_cont(MYSQL_RES *result, int status); -MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *result); int STDCALL mysql_fetch_row_start(MYSQL_ROW *ret, MYSQL_RES *result); int STDCALL mysql_fetch_row_cont(MYSQL_ROW *ret, MYSQL_RES *result, @@ -622,7 +635,6 @@ int STDCALL mysql_stmt_store_result_start(int *ret, MYSQL_STMT *stmt); int STDCALL mysql_stmt_store_result_cont(int *ret, MYSQL_STMT *stmt,int status); int STDCALL mysql_stmt_close_start(my_bool *ret, MYSQL_STMT *stmt); int STDCALL mysql_stmt_close_cont(my_bool *ret, MYSQL_STMT * stmt, int status); -my_bool STDCALL mysql_stmt_reset(MYSQL_STMT * stmt); int STDCALL mysql_stmt_reset_start(my_bool *ret, MYSQL_STMT * stmt); int STDCALL mysql_stmt_reset_cont(my_bool *ret, MYSQL_STMT *stmt, int status); int STDCALL mysql_stmt_free_result_start(my_bool *ret, MYSQL_STMT *stmt); @@ -635,10 +647,9 @@ int STDCALL mysql_stmt_send_long_data_start(my_bool *ret, MYSQL_STMT *stmt, int STDCALL mysql_stmt_send_long_data_cont(my_bool *ret, MYSQL_STMT *stmt, int status); - /* API function calls (used by dynmic plugins) */ struct st_mariadb_api { - my_ulonglong (STDCALL *mysql_num_rows)(MYSQL_RES *res); + my_ulonglong (STDCALL *mysql_num_rows)(MYSQL_RES *res); unsigned int (STDCALL *mysql_num_fields)(MYSQL_RES *res); my_bool (STDCALL *mysql_eof)(MYSQL_RES *res); MYSQL_FIELD *(STDCALL *mysql_fetch_field_direct)(MYSQL_RES *res, unsigned int fieldnr); @@ -699,8 +710,6 @@ struct st_mariadb_api { MYSQL_FIELD * (STDCALL *mysql_fetch_field)(MYSQL_RES *result); unsigned long (STDCALL *mysql_escape_string)(char *to,const char *from, unsigned long from_length); unsigned long (STDCALL *mysql_real_escape_string)(MYSQL *mysql, char *to,const char *from, unsigned long length); - void (STDCALL *mysql_debug)(const char *debug); - void (STDCALL *mysql_debug_end)(void); unsigned int (STDCALL *mysql_thread_safe)(void); unsigned int (STDCALL *mysql_warning_count)(MYSQL *mysql); const char * (STDCALL *mysql_sqlstate)(MYSQL *mysql); @@ -713,9 +722,9 @@ struct st_mariadb_api { unsigned long (STDCALL *mysql_get_client_version)(void); my_bool (STDCALL *mariadb_connection)(MYSQL *mysql); const char * (STDCALL *mysql_get_server_name)(MYSQL *mysql); - CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname); - CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr); - size_t (STDCALL *mariadb_convert_string)(const char *from, size_t *from_len, CHARSET_INFO *from_cs, char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); + MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_name)(const char *csname); + MARIADB_CHARSET_INFO * (STDCALL *mariadb_get_charset_by_nr)(unsigned int csnr); + 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); int (STDCALL *mysql_optionsv)(MYSQL *mysql,enum mysql_option option, ...); int (STDCALL *mysql_get_optionv)(MYSQL *mysql, enum mysql_option option, void *arg, ...); int (STDCALL *mysql_get_option)(MYSQL *mysql, enum mysql_option option, void *arg); @@ -753,10 +762,11 @@ struct st_mariadb_api { unsigned int (STDCALL *mysql_stmt_field_count)(MYSQL_STMT *stmt); int (STDCALL *mysql_stmt_next_result)(MYSQL_STMT *stmt); my_bool (STDCALL *mysql_stmt_more_results)(MYSQL_STMT *stmt); + int (STDCALL *mariadb_stmt_execute_direct)(MYSQL_STMT *stmt, const char *stmtstr, size_t length); }; /* these methods can be overwritten by db plugins */ -struct st_mysql_methods { +struct st_mariadb_methods { MYSQL *(*db_connect)(MYSQL *mysql, const char *host, const char *user, const char *passwd, const char *db, unsigned int port, const char *unix_socket, unsigned long clientflag); void (*db_close)(MYSQL *mysql); diff --git a/include/mysql_io.h b/include/mysql_io.h deleted file mode 100644 index 6cc3ad63..00000000 --- a/include/mysql_io.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: | - +----------------------------------------------------------------------+ -*/ - -#ifndef MYSQL_IO_H -#define MYSQL_IO_H - -#ifdef _WIN32 -void mysql_io_win_init(void); -#endif - -MYSQL_STREAM * mysql_io_open(const char *name, size_t namelen); -size_t mysql_io_read(MYSQL_STREAM *stream, char *buf, size_t size); -size_t mysql_io_write(MYSQL_STREAM *stream, const char *buf, size_t count); -void mysql_io_close(MYSQL_STREAM *stream); - -#endif /* MYSQLND_IO_H */ diff --git a/include/mysql_mm.h b/include/mysql_mm.h deleted file mode 100644 index 78d1f874..00000000 --- a/include/mysql_mm.h +++ /dev/null @@ -1,44 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | - | Ulf Wendel | - +----------------------------------------------------------------------+ -*/ - -#ifndef MYSQLND_MM_H -#define MYSQLND_MM_H -#include - - -char * mnd_strndup(const char *s, size_t length); -char * mnd_strdup(const char *src); - - -#define mnd_malloc(size) malloc((size)) -#define mnd_calloc(nmemb, size) calloc((nmemb), (size)) -#define mnd_realloc(ptr, new_size) realloc((ptr), (new_size)) -#define mnd_free(ptr) free((ptr)) - -#endif /* MYSQLND_MM_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/include/mysql_priv.h b/include/mysql_priv.h deleted file mode 100644 index f0198139..00000000 --- a/include/mysql_priv.h +++ /dev/null @@ -1,4 +0,0 @@ -/* internal functions */ -MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); -void free_rows(MYSQL_DATA *cur); -MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); diff --git a/include/mysql_wireprotocol.h b/include/mysql_wireprotocol.h deleted file mode 100644 index 3417d454..00000000 --- a/include/mysql_wireprotocol.h +++ /dev/null @@ -1,295 +0,0 @@ -/* - +----------------------------------------------------------------------+ - | PHP Version 6 | - +----------------------------------------------------------------------+ - | Copyright (c) 2006-2007 The PHP Group | - +----------------------------------------------------------------------+ - | This source file is subject to version 3.01 of the PHP license, | - | that is bundled with this package in the file LICENSE, and is | - | available through the world-wide-web at the following url: | - | http://www.php.net/license/3_01.txt | - | If you did not receive a copy of the PHP license and are unable to | - | obtain it through the world-wide-web, please send a note to | - | license@php.net so we can mail you a copy immediately. | - +----------------------------------------------------------------------+ - | Authors: Georg Richter | - | Andrey Hristov | - | Ulf Wendel | - +----------------------------------------------------------------------+ -*/ - -/* $Id: mysql_wireprotocol.h,v 1.4.2.2 2007/10/05 21:23:56 andrey Exp $ */ - -#ifndef MYSQL_WIREPROTOCOL_H -#define MYSQL_WIREPROTOCOL_H - -#define MYSQL_HEADER_SIZE 4 - -#define MYSQL_NULL_LENGTH (unsigned long) ~0 - -typedef unsigned char mysql_1b; -typedef unsigned short mysql_2b; -typedef unsigned int mysql_4b; - -/* Used in mysql_debug.c */ -extern char * mysql_read_header_name; -extern char * mysql_read_body_name; - - -/* Packet handling */ -#define PACKET_INIT(packet, enum_type, c_type) \ - { \ - packet = (c_type) my_mcalloc( packet_methods[enum_type].struct_size, MYF(MY_WME | MY_ZEROFILL)); \ - ((c_type) (packet))->header.m = &packet_methods[enum_type]; \ - } -#define PACKET_WRITE(packet, conn) ((packet)->header.m->write_to_net((packet), (conn))) -#define PACKET_READ(packet, conn) ((packet)->header.m->read_from_net((packet), (conn))) -#define PACKET_FREE(packet) ((packet)->header.m->free_mem((packet), FALSE)) - -#define PACKET_INIT_ALLOCA(packet, enum_type) \ - { \ - memset(&(packet), 0, packet_methods[enum_type].struct_size); \ - (packet).header.m = &packet_methods[enum_type]; \ - } -#define PACKET_WRITE_ALLOCA(packet, conn) PACKET_WRITE(&(packet), (conn)) -#define PACKET_READ_ALLOCA(packet, conn) PACKET_READ(&(packet), (conn)) -#define PACKET_FREE_ALLOCA(packet) (packet.header.m->free_mem(&(packet), TRUE)) - -/* Enums */ -enum php_mysql_packet_type -{ - PROT_GREET_PACKET= 0, - PROT_AUTH_PACKET, - PROT_OK_PACKET, - PROT_EOF_PACKET, - PROT_CMD_PACKET, - PROT_RSET_HEADER_PACKET, - PROT_RSET_FLD_PACKET, - PROT_ROW_PACKET, - PROT_STATS_PACKET, - PROT_PREPARE_RESP_PACKET, - PROT_CHG_USER_PACKET, - PROT_LAST, /* should always be last */ -}; - - -extern const char * const mysql_command_to_text[MYSQL_COM_END]; - -/* Low-level extraction functionality */ -typedef struct st_mysql_packet_methods { - size_t struct_size; - my_bool (*read_from_net)(void *packet, MYSQL *conn); - size_t (*write_to_net)(void *packet, MYSQL *conn); - void (*free_mem)(void *packet, my_bool alloca); -} mysql_packet_methods; - -extern mysql_packet_methods packet_methods[]; - - -typedef struct st_mysql_packet_header { - size_t size; - uchar packet_no; - mysql_packet_methods *m; -} mysql_packet_header; - -/* Server greets the client */ -typedef struct st_php_mysql_packet_greet { - mysql_packet_header header; - mysql_1b protocol_version; - char *server_version; - mysql_4b thread_id; - uchar scramble_buf[SCRAMBLE_LENGTH]; - /* 1 byte pad */ - mysql_2b server_capabilities; - mysql_1b charset_no; - mysql_2b server_status; - /* 13 byte pad*/ - my_bool pre41; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_greet; - - -/* Client authenticates */ -typedef struct st_php_mysql_packet_auth { - mysql_packet_header header; - mysql_4b client_flags; - uint32 max_packet_size; - mysql_1b charset_no; - /* 23 byte pad */ - const char *user; - /* 8 byte scramble */ - const char *db; - /* 12 byte scramble */ - - /* Here the packet ends. This is user supplied data */ - const char *password; - /* +1 for \0 because of scramble() */ - unsigned char *server_scramble_buf; - size_t db_len; -} php_mysql_packet_auth; - -/* OK packet */ -typedef struct st_php_mysql_packet_ok { - mysql_packet_header header; - mysql_1b field_count; /* always 0x0 */ - my_ulonglong affected_rows; - my_ulonglong last_insert_id; - mysql_2b server_status; - mysql_2b warning_count; - char *message; - size_t message_len; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_ok; - - -/* Command packet */ -typedef struct st_php_mysql_packet_command { - mysql_packet_header header; - enum enum_server_command command; - const char *argument; - size_t arg_len; -} php_mysql_packet_command; - - -/* EOF packet */ -typedef struct st_php_mysql_packet_eof { - mysql_packet_header header; - mysql_1b field_count; /* 0xFE */ - mysql_2b warning_count; - mysql_2b server_status; - /* If error packet, we use these */ - char error[MYSQL_ERRMSG_SIZE+1]; - char sqlstate[SQLSTATE_LENGTH + 1]; - unsigned int error_no; -} php_mysql_packet_eof; -/* EOF packet */ - - -/* Result Set header*/ -typedef struct st_php_mysql_packet_rset_header { - mysql_packet_header header; - /* - 0x00 => ok - ~0 => LOAD DATA LOCAL - error_no != 0 => error - others => result set -> Read res_field packets up to field_count - */ - unsigned long field_count; - /* - These are filled if no SELECT query. For SELECT warning_count - and server status are in the last row packet, the EOF packet. - */ - mysql_2b warning_count; - mysql_2b server_status; - my_ulonglong affected_rows; - my_ulonglong last_insert_id; - /* This is for both LOAD DATA or info, when no result set */ - char *info_or_local_file; - size_t info_or_local_file_len; - /* If error packet, we use these */ - mysql_error_info error_info; -} php_mysql_packet_rset_header; - - -/* Result set field packet */ -typedef struct st_php_mysql_packet_res_field { - mysql_packet_header header; - MYSQL_FIELD *metadata; - /* For table definitions, empty for result sets */ - my_bool skip_parsing; - my_bool stupid_list_fields_eof; -} php_mysql_packet_res_field; - - -/* Row packet */ -struct st_php_mysql_packet_row { - mysql_packet_header header; - uchar **fields; /* ??? */ - mysql_4b field_count; - my_bool eof; - /* - These are, of course, only for SELECT in the EOF packet, - which is detected by this packet - */ - mysql_2b warning_count; - mysql_2b server_status; - - uchar *row_buffer; - - my_bool skip_extraction; - my_bool binary_protocol; - MYSQL_FIELD *fields_metadata; - /* We need this to alloc bigger bufs in non-PS mode */ - unsigned int bit_fields_count; - size_t bit_fields_total_len; /* trailing \0 not counted */ - - /* If error packet, we use these */ - mysql_error_info error_info; -}; -typedef struct st_php_mysql_packet_row php_mysql_packet_row; - -/* Statistics packet */ -typedef struct st_php_mysql_packet_stats { - mysql_packet_header header; - char *message; - /* message_len is not part of the packet*/ - size_t message_len; -} php_mysql_packet_stats; - - -/* COM_PREPARE response packet */ -typedef struct st_php_mysql_packet_prepare_response { - mysql_packet_header header; - /* also known as field_count 0x00=OK , 0xFF=error */ - unsigned char error_code; - unsigned long stmt_id; - unsigned int field_count; - unsigned int param_count; - unsigned int warning_count; - - /* present in case of error */ - mysql_error_info error_info; -} php_mysql_packet_prepare_response; - - -/* Statistics packet */ -typedef struct st_php_mysql_packet_chg_user_resp { - mysql_packet_header header; - mysql_4b field_count; - - /* message_len is not part of the packet*/ - mysql_2b server_capabilities; - /* If error packet, we use these */ - mysql_error_info error_info; -} php_mysql_packet_chg_user_resp; - - -size_t mysql_stream_write(MYSQL *conn, const char * buf, size_t count); -size_t mysql_stream_write_w_header(MYSQL *conn, const char * buf, size_t count); - -#ifdef MYSQL_DO_WIRE_CHECK_BEFORE_COMMAND -size_t php_mysql_consume_uneaten_data(const MYSQL *conn, enum php_mysql_server_command cmd); -#endif - - -unsigned long php_mysql_net_field_length(uchar **packet); -uchar * php_mysql_net_store_length(uchar *packet, my_ulonglong length); - -extern char * const mysql_empty_string; - -#endif /* MYSQL_WIREPROTOCOL_H */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: noet sw=4 ts=4 fdm=marker - * vim<600: noet sw=4 ts=4 - */ diff --git a/include/mysys_err.h b/include/mysys_err.h deleted file mode 100644 index 6ac5e2cc..00000000 --- a/include/mysys_err.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifndef _mysys_err_h -#define _mysys_err_h -#ifdef __cplusplus -extern "C" { -#endif - -#define GLOB 0 /* Error maps */ -#define GLOBERRS EE_LASTERROR - EE_FIRSTERROR + 1 /* Max number of error messages in map's */ -#define EE(X) globerrs[ (X) - EE_FIRSTERROR ] /* Defines to add error to right map */ - -extern const char * NEAR globerrs[]; /* my_error_messages is here */ - -/* Error message numbers in global map - -*/ -#define EE_FIRSTERROR 1 -#define EE_CANTCREATEFILE 1 -#define EE_READ 2 -#define EE_WRITE 3 -#define EE_BADCLOSE 4 -#define EE_OUTOFMEMORY 5 -#define EE_DELETE 6 -#define EE_LINK 7 -#define EE_EOFERR 9 -#define EE_CANTLOCK 10 -#define EE_CANTUNLOCK 11 -#define EE_DIR 12 -#define EE_STAT 13 -#define EE_CANT_CHSIZE 14 -#define EE_CANT_OPEN_STREAM 15 -#define EE_GETWD 16 -#define EE_SETWD 17 -#define EE_LINK_WARNING 18 -#define EE_OPEN_WARNING 19 -#define EE_DISK_FULL 20 -#define EE_CANT_MKDIR 21 -#define EE_UNKNOWN_CHARSET 22 -#define EE_OUT_OF_FILERESOURCES 23 -#define EE_CANT_READLINK 24 -#define EE_CANT_SYMLINK 25 -#define EE_REALPATH 26 -#define EE_SYNC 27 -#define EE_UNKNOWN_COLLATION 28 -#define EE_FILENOTFOUND 29 -#define EE_FILE_NOT_CLOSED 30 -#define EE_CANT_CHMOD 31 -#define EE_LASTERROR 31 - -#ifdef __cplusplus -} -#endif -#endif diff --git a/include/thr_alarm.h b/include/thr_alarm.h deleted file mode 100644 index c14deb0c..00000000 --- a/include/thr_alarm.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Prototypes when using thr_alarm library functions */ - -#ifndef _thr_alarm_h -#define _thr_alarm_h -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef USE_ALARM_THREAD -#define USE_ONE_SIGNAL_HAND /* One must call process_alarm */ -#endif -#ifdef HAVE_LINUXTHREADS -#define THR_CLIENT_ALARM SIGALRM -#else -#define THR_CLIENT_ALARM SIGUSR1 -#endif -#ifdef HAVE_rts_threads -#undef USE_ONE_SIGNAL_HAND -#define USE_ALARM_THREAD -#define THR_SERVER_ALARM SIGUSR1 -#else -#define THR_SERVER_ALARM SIGALRM -#endif - -#if defined(DONT_USE_THR_ALARM) - -#define USE_ALARM_THREAD -#undef USE_ONE_SIGNAL_HAND - -typedef struct st_thr_alarm_entry -{ - uint crono; -} thr_alarm_entry; - -#define thr_alarm_init(A) (A)->crono=0 -#define thr_alarm_in_use(A) (A)->crono -#define init_thr_alarm(A) -#define thr_alarm_kill(A) -#define end_thr_alarm() -#define thr_alarm(A,B) (((A)->crono=1)-1) -#define thr_got_alarm(A) (A)->crono -#define thr_end_alarm(A) - -#else -#if defined(_WIN32) -typedef struct st_thr_alarm_entry -{ - rf_SetTimer crono; -} thr_alarm_entry; - -#elif defined(__EMX__) || defined(OS2) - -typedef struct st_thr_alarm_entry -{ - uint crono; - uint event; -} thr_alarm_entry; - -#else /* System with posix threads */ - -typedef int thr_alarm_entry; - -#define thr_got_alarm(thr_alarm) (**(thr_alarm)) - -#endif /* _WIN32 */ - -typedef thr_alarm_entry* thr_alarm_t; - -typedef struct st_alarm { - ulong expire_time; - thr_alarm_entry alarmed; /* set when alarm is due */ - pthread_t thread; - my_bool malloced; -} ALARM; - -#define thr_alarm_init(A) (*(A))=0 -#define thr_alarm_in_use(A) (*(A)!= 0) -void init_thr_alarm(uint max_alarm); -bool thr_alarm(thr_alarm_t *alarmed, uint sec, ALARM *buff); -void thr_alarm_kill(pthread_t thread_id); -void thr_end_alarm(thr_alarm_t *alarmed); -void end_thr_alarm(void); -sig_handler process_alarm(int); -#ifndef thr_got_alarm -bool thr_got_alarm(thr_alarm_t *alrm); -#endif - - -#endif /* DONT_USE_THR_ALARM */ - -#ifdef __cplusplus -} -#endif /* __cplusplus */ -#endif /* _thr_alarm_h */ - diff --git a/libmariadb/CMakeLists.txt b/libmariadb/CMakeLists.txt index dcdb192a..fbbacc1e 100644 --- a/libmariadb/CMakeLists.txt +++ b/libmariadb/CMakeLists.txt @@ -9,56 +9,25 @@ ADD_DEFINITIONS(-D THREAD) INCLUDE(${CMAKE_SOURCE_DIR}/cmake/sign.cmake) -SET(EXPORT_SYMBOLS - load_defaults - ma_pvio_register_callback +SET(MARIADB_LIB_SYMBOLS mariadb_connection mariadb_convert_string - mariadb_dyncol_check - mariadb_dyncol_column_cmp_named - mariadb_dyncol_column_count - mariadb_dyncol_create_many_named - mariadb_dyncol_create_many_num - mariadb_dyncol_exists_named - mariadb_dyncol_exists_num - mariadb_dyncol_free - mariadb_dyncol_get_named - mariadb_dyncol_get_num - mariadb_dyncol_has_names - mariadb_dyncol_json - mariadb_dyncol_list_named - mariadb_dyncol_list_num - mariadb_dyncol_unpack - mariadb_dyncol_update_many_named - mariadb_dyncol_update_many_num - mariadb_dyncol_val_double - mariadb_dyncol_val_long - mariadb_dyncol_val_str + ma_pvio_register_callback mariadb_get_charset_by_name + mariadb_stmt_execute_direct mariadb_get_charset_by_nr mariadb_get_info mariadb_get_infov mysql_affected_rows mysql_autocommit - mysql_autocommit_cont - mysql_autocommit_start mysql_change_user - mysql_change_user_cont - mysql_change_user_start mysql_character_set_name mysql_client_find_plugin mysql_client_register_plugin mysql_close - mysql_close_cont - mysql_close_start mysql_commit - mysql_commit_cont - mysql_commit_start mysql_data_seek - mysql_debug mysql_dump_debug_info - mysql_dump_debug_info_cont - mysql_dump_debug_info_start mysql_eof mysql_errno mysql_error @@ -68,14 +37,10 @@ SET(EXPORT_SYMBOLS mysql_fetch_fields mysql_fetch_lengths mysql_fetch_row - mysql_fetch_row_cont - mysql_fetch_row_start mysql_field_count mysql_field_seek mysql_field_tell mysql_free_result - mysql_free_result_cont - mysql_free_result_start mysql_get_character_set_info mysql_get_charset_by_name mysql_get_charset_by_nr @@ -97,130 +62,73 @@ SET(EXPORT_SYMBOLS mysql_init mysql_insert_id mysql_kill - mysql_kill_cont - mysql_kill_start mysql_list_dbs - mysql_list_dbs_cont - mysql_list_dbs_start mysql_list_fields - mysql_list_fields_cont - mysql_list_fields_start mysql_list_processes - mysql_list_processes_cont - mysql_list_processes_start mysql_list_tables - mysql_list_tables_cont - mysql_list_tables_start mysql_load_plugin mysql_load_plugin_v mysql_more_results mysql_next_result - mysql_next_result_cont - mysql_next_result_start mysql_num_fields mysql_num_rows mysql_options + mysql_options4 mysql_optionsv mysql_ping - mysql_ping_cont - mysql_ping_start mysql_ps_fetch_functions mysql_query - mysql_query_cont - mysql_query_start mysql_reconnect mysql_read_query_result - mysql_read_query_result_cont - mysql_read_query_result_start mysql_real_connect - mysql_real_connect_cont - mysql_real_connect_start mysql_real_escape_string mysql_real_query - mysql_real_query_cont - mysql_real_query_start mysql_refresh - mysql_refresh_cont - mysql_refresh_start mysql_rollback - mysql_rollback_cont - mysql_rollback_start mysql_row_seek mysql_row_tell mysql_select_db - mysql_select_db_cont - mysql_select_db_start mysql_send_query - mysql_send_query_cont - mysql_send_query_start mysql_server_end mysql_server_init mysql_set_character_set - mysql_set_character_set_cont - mysql_set_character_set_start mysql_set_local_infile_default mysql_set_local_infile_handler mysql_set_server_option - mysql_set_server_option_cont - mysql_set_server_option_start mysql_shutdown - mysql_shutdown_cont - mysql_shutdown_start mysql_sqlstate mysql_ssl_set mysql_stat - mysql_stat_cont - mysql_stat_start mysql_stmt_affected_rows mysql_stmt_attr_get mysql_stmt_attr_set mysql_stmt_bind_param mysql_stmt_bind_result mysql_stmt_close - mysql_stmt_close_cont - mysql_stmt_close_start mysql_stmt_data_seek mysql_stmt_errno mysql_stmt_error mysql_stmt_execute - mysql_stmt_execute_cont - mysql_stmt_execute_start mysql_stmt_fetch mysql_stmt_fetch_column - mysql_stmt_fetch_cont - mysql_stmt_fetch_start mysql_stmt_field_count mysql_stmt_free_result - mysql_stmt_free_result_cont - mysql_stmt_free_result_start mysql_stmt_init mysql_stmt_insert_id mysql_stmt_more_results mysql_stmt_next_result - mysql_stmt_next_result_cont - mysql_stmt_next_result_start mysql_stmt_num_rows mysql_stmt_param_count mysql_stmt_param_metadata mysql_stmt_prepare - mysql_stmt_prepare_cont - mysql_stmt_prepare_start mysql_stmt_reset - mysql_stmt_reset_cont - mysql_stmt_reset_start mysql_stmt_result_metadata mysql_stmt_row_seek mysql_stmt_row_tell mysql_stmt_send_long_data - mysql_stmt_send_long_data_cont - mysql_stmt_send_long_data_start mysql_stmt_sqlstate mysql_stmt_store_result - mysql_stmt_store_result_cont - mysql_stmt_store_result_start mysql_store_result - mysql_store_result_cont - mysql_store_result_start mysql_thread_end mysql_thread_id mysql_thread_init @@ -228,120 +136,137 @@ SET(EXPORT_SYMBOLS mysql_use_result mysql_warning_count) IF(WITH_SSL) - SET(EXPORTS ${EXPORTS} mariadb_deinitialize_ssl) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} mariadb_deinitialize_ssl) ENDIF() # some gcc versions fail to compile asm parts of my_context.c, # if build type is "Release" (see CONC-133), so we need to add -g flag -IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_BUILD_TYPE MATCHES "Release") - SET_SOURCE_FILES_PROPERTIES(my_context.c PROPERTIES COMPILE_FLAGS -g) +IF(WITH_NONBLOCK) + IF(CMAKE_COMPILER_IS_GNUCC AND CMAKE_BUILD_TYPE MATCHES "Release") + SET_SOURCE_FILES_PROPERTIES(my_context.c PROPERTIES COMPILE_FLAGS -g) + ENDIF() ENDIF() -IF(WIN32) - SET(EXPORT_CONTENT "EXPORTS\n") - FOREACH(SYMBOL ${EXPORT_SYMBOLS}) - SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${SYMBOL}\n") - ENDFOREACH() - SET(EXPORT_FILE "${CMAKE_BINARY_DIR}/libmariadb/exports.def") - SET(EXPORT_LINK ${EXPORT_FILE}) -ELSE() - SET(EXPORT_CONTENT "{\nglobal:\n") - FOREACH(SYMBOL ${EXPORT_SYMBOLS}) - SET(EXPORT_CONTENT "${EXPORT_CONTENT} ${SYMBOL}\\;\n") - ENDFOREACH() - SET(EXPORT_FILE "${CMAKE_BINARY_DIR}/libmariadb/exports.txt") - SET(EXPORT_CONTENT "${EXPORT_CONTENT}local:\n *\\;\n}\\;") -ENDIF() +SET(MARIADB_DYNCOL_SYMBOLS + mariadb_dyncol_check + mariadb_dyncol_column_cmp_named + mariadb_dyncol_column_count + mariadb_dyncol_create_many_named + mariadb_dyncol_create_many_num + mariadb_dyncol_exists_named + mariadb_dyncol_exists_num + mariadb_dyncol_free + mariadb_dyncol_get_named + mariadb_dyncol_get_num + mariadb_dyncol_has_names + mariadb_dyncol_json + mariadb_dyncol_list_named + mariadb_dyncol_list_num + mariadb_dyncol_unpack + mariadb_dyncol_update_many_named + mariadb_dyncol_update_many_num + mariadb_dyncol_val_double + mariadb_dyncol_val_long + mariadb_dyncol_val_str) + +SET(MARIADB_NONBLOCK_SYMBOLS + mysql_autocommit_cont + mysql_autocommit_start + mysql_change_user_cont + mysql_change_user_start + mysql_close_cont + mysql_close_start + mysql_commit_cont + mysql_commit_start + mysql_dump_debug_info_cont + mysql_dump_debug_info_start + mysql_fetch_row_cont + mysql_fetch_row_start + mysql_free_result_cont + mysql_free_result_start + mysql_get_timeout_value + mysql_get_timeout_value_ms + mysql_kill_cont + mysql_kill_start + mysql_next_result_cont + mysql_next_result_start + mysql_ping_cont + mysql_ping_start + mysql_query_cont + mysql_query_start + mysql_read_query_result_cont + mysql_read_query_result_start + mysql_real_connect_cont + mysql_real_connect_start + mysql_real_query_cont + mysql_real_query_start + mysql_refresh_cont + mysql_refresh_start + mysql_rollback_cont + mysql_rollback_start + mysql_select_db_cont + mysql_select_db_start + mysql_send_query_cont + mysql_send_query_start + mysql_set_character_set_cont + mysql_set_character_set_start + mysql_set_server_option_cont + mysql_set_server_option_start + mysql_shutdown_cont + mysql_shutdown_start + mysql_stat_cont + mysql_stat_start + mysql_stmt_close_cont + mysql_stmt_close_start + mysql_stmt_execute_cont + mysql_stmt_execute_start + mysql_stmt_fetch_cont + mysql_stmt_fetch_start + mysql_stmt_free_result_cont + mysql_stmt_free_result_start + mysql_stmt_next_result_cont + mysql_stmt_next_result_start + mysql_stmt_prepare_cont + mysql_stmt_prepare_start + mysql_stmt_reset_cont + mysql_stmt_reset_start + mysql_stmt_send_long_data_cont + mysql_stmt_send_long_data_start + mysql_stmt_store_result_cont + mysql_stmt_store_result_start + mysql_store_result_cont + mysql_store_result_start +) -FILE(WRITE ${EXPORT_FILE} ${EXPORT_CONTENT}) SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} -array.c -ma_dyncol.c -bchange.c -bmove.c -bmove_upp.c -my_charset.c -hash.c -net.c -charset.c +ma_array.c +ma_charset.c +ma_hash.c +ma_net.c +mariadb_charset.c ma_time.c -dbug.c -default.c -errmsg.c -my_vsnprintf.c -errors.c -getopt1.c -getopt.c -int2str.c -is_prefix.c -libmariadb.c -list.c -llstr.c -longlong2str.c +ma_default.c +ma_errmsg.c +mariadb_lib.c +ma_list.c ma_pvio.c ma_ssl.c -mf_dirname.c -mf_fn_ext.c -mf_format.c -mf_loadpath.c -mf_pack.c -mf_path.c -mf_unixpath.c -mf_wcomp.c -mulalloc.c -my_alloc.c -my_compress.c -my_context.c -my_div.c -my_error.c -my_fopen.c -my_fstream.c -my_getwd.c -my_init.c -my_lib.c -my_malloc.c -my_messnc.c -my_net.c -my_once.c -my_open.c -my_port.c -my_pthread.c -my_read.c -my_realloc.c -my_seek.c -my_static.c -my_symlink.c -my_thr_init.c -my_write.c -mysql_async.c -password.c -str2int.c -strcend.c -strcont.c -strend.c -strfill.c -string.c -strinstr.c -strmake.c -strmov.c -strnmov.c -strtoll.c -strtoull.c -strxmov.c -strxnmov.c -thr_mutex.c -typelib.c -sha1.c -my_stmt.c -my_loaddata.c -my_stmt_codec.c -${CMAKE_BINARY_DIR}/libmariadb/client_plugin.c +ma_alloc.c +ma_compress.c +ma_init.c +ma_password.c +ma_string.c +ma_ll2str.c +ma_sha1.c +mariadb_stmt.c +ma_loaddata.c +ma_stmt_codec.c +${CMAKE_BINARY_DIR}/libmariadb/ma_client_plugin.c ma_io.c ${SSL_SOURCES} ) - IF(WIN32) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/win-iconv) SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} @@ -373,6 +298,25 @@ SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} ${ZLIB_SOURCES}) INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/zlib) ENDIF() +IF(WITH_DYNCOL) + MESSAGE(STATUS "Dynamic column API support=ON") + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_DYNCOL_SYMBOLS}) + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_dyncol.c) +ENDIF() + +IF(WITH_NONBLOCK) + MESSAGE(STATUS "Non blocking API support=ON") + SET(LIBMARIADB_SOURCES ${LIBMARIADB_SOURCES} mariadb_async.c ma_context.c) + SET(MARIADB_LIB_SYMBOLS ${MARIADB_LIB_SYMBOLS} ${MARIADB_NONBLOCK_SYMBOLS}) + ADD_DEFINITIONS(-DHAVE_NONBLOCK) +ENDIF() + +INCLUDE(${CMAKE_SOURCE_DIR}/cmake/export.cmake) +CREATE_EXPORT_FILE(mariadbclient + ${CMAKE_CURRENT_BINARY_DIR} + "${MARIADB_LIB_SYMBOLS}") + + # CREATE OBJECT LIBRARY ADD_LIBRARY(mariadb_obj OBJECT ${LIBMARIADB_SOURCES}) IF(UNIX) @@ -399,9 +343,9 @@ IF(WIN32) "FILE_DESCRIPTION:Static lib for client/server communication") ENDIF() -ADD_LIBRARY(mariadbclient STATIC ${ariadbclient_RC} $ ${EMPTY_FILE} ${EXPORT_LINK}) +ADD_LIBRARY(mariadbclient STATIC ${mariadbclient_RC} $ ${EMPTY_FILE} mariadbclient.def) TARGET_LINK_LIBRARIES(mariadbclient ${SYSTEM_LIBS}) -ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $ ${EMPTY_FILE} ${EXPORT_LINK}) +ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $ ${EMPTY_FILE} mariadbclient.def) TARGET_LINK_LIBRARIES(libmariadb ${SYSTEM_LIBS}) IF(UNIX) SET_TARGET_PROPERTIES(libmariadb PROPERTIES COMPILE_FLAGS "${CMAKE_SHARED_LIBRARY_C_FLAGS}") @@ -410,11 +354,13 @@ SIGN_TARGET(libmariadb) IF(CMAKE_SYSTEM_NAME MATCHES "Linux") TARGET_LINK_LIBRARIES (libmariadb "-Wl,--no-undefined") - TARGET_LINK_LIBRARIES (libmariadb "-Wl,--version-script=${EXPORT_FILE}") + TARGET_LINK_LIBRARIES (libmariadb "-Wl,--version-script=${CMAKE_BINARY_DIR}/libmariadb/mariadbclient.def") TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--no-undefined") - TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--version-script=${EXPORT_FILE}") + TARGET_LINK_LIBRARIES (mariadbclient "-Wl,--version-script=${CMAKE_BINARY_DIR}/libmariadb/mariadbclient.def") ENDIF() +SET_TARGET_PROPERTIES(mariadbclient PROPERTIES INTERFACE_LINK_LIBRARIES "${SYSTEM_LIBS}") + SET_TARGET_PROPERTIES(libmariadb PROPERTIES PREFIX "") SET_TARGET_PROPERTIES(libmariadb PROPERTIES VERSION @@ -440,16 +386,9 @@ ENDIF() INSTALL(TARGETS - libmariadb mariadbclient + libmariadb mariadbclient RUNTIME DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}" LIBRARY DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}" ARCHIVE DESTINATION "${LIB_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}") -INSTALL(DIRECTORY ${CMAKE_SOURCE_DIR}/include/ - DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) -INSTALL(FILES - ${CMAKE_BINARY_DIR}/include/my_config.h - ${CMAKE_BINARY_DIR}/include/mysql_version.h - DESTINATION ${INCLUDE_INSTALL_DIR}/${SUFFIX_INSTALL_DIR}) - diff --git a/libmariadb/bchange.c b/libmariadb/bchange.c deleted file mode 100644 index f71bcf53..00000000 --- a/libmariadb/bchange.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : bchange.c - Author : Michael widenius - Updated: 1987-03-20 - Defines: bchange() - - bchange(dst, old_length, src, new_length, tot_length) - replaces old_length characters at dst to new_length characters from - src in a buffer with tot_length bytes. -*/ - -#include -#include "m_string.h" - -void bchange(register char *dst, size_t old_length, register const char *src, size_t new_length, size_t tot_length) -{ - size_t rest=tot_length-old_length; - if (old_length < new_length) - bmove_upp(dst+rest+new_length,dst+tot_length,rest); - else - bmove(dst+new_length,dst+old_length,rest); - memcpy(dst,src,new_length); -} diff --git a/libmariadb/bmove.c b/libmariadb/bmove.c deleted file mode 100644 index 09fe067a..00000000 --- a/libmariadb/bmove.c +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : bmove.c - Author : Richard A. O'Keefe. - Michael Widenius; ifdef MC68000 - Updated: 23 April 1984 - Defines: bmove() - - bmove(dst, src, len) moves exactly "len" bytes from the source "src" - to the destination "dst". It does not check for NUL characters as - strncpy() and strnmov() do. Thus if your C compiler doesn't support - structure assignment, you can simulate it with - bmove(&to, &from, sizeof from); - The standard 4.2bsd routine for this purpose is bcopy. But as bcopy - has its first two arguments the other way around you may find this a - bit easier to get right. - No value is returned. - - Note: the "b" routines are there to exploit certain VAX order codes, - but the MOVC3 instruction will only move 65535 characters. The asm - code is presented for your interest and amusement. -*/ - -#include -#include "m_string.h" - -#if !defined(HAVE_BMOVE) && !defined(bmove) - -#if VaxAsm - -void bmove(dst, src, len) - char *dst, *src; - uint len; - { - asm("movc3 12(ap),*8(ap),*4(ap)"); - } - -#else -#if defined(MC68000) && defined(DS90) - -void bmove(dst, src, len) -char *dst,*src; -uint len; /* 0 <= len <= 65535 */ -{ -asm(" movl 12(a7),d0 "); -asm(" subql #1,d0 "); -asm(" blt .L5 "); -asm(" movl 4(a7),a1 "); -asm(" movl 8(a7),a0 "); -asm(".L4: movb (a0)+,(a1)+ "); -asm(" dbf d0,.L4 "); -asm(".L5: "); -} -#else - -void bmove(dst, src, len) -register char *dst; -register const char *src; -register uint len; -{ - while (len-- != 0) *dst++ = *src++; -} -#endif -#endif -#endif diff --git a/libmariadb/bmove_upp.c b/libmariadb/bmove_upp.c index 92df08ec..ee7798bc 100644 --- a/libmariadb/bmove_upp.c +++ b/libmariadb/bmove_upp.c @@ -24,28 +24,10 @@ "src-len" to the destination "dst-len" counting downwards. */ -#include -#include "m_string.h" +#include +#include "ma_string.h" -#if defined(MC68000) && defined(DS90) - -/* 0 <= len <= 65535 */ -void bmove_upp(byte *dst, const byte *src, size_t len) -{ -asm(" movl 12(a7),d0 "); -asm(" subql #1,d0 "); -asm(" blt .L5 "); -asm(" movl 4(a7),a1 "); -asm(" movl 8(a7),a0 "); -asm(".L4: movb -(a0),-(a1) "); -asm(" dbf d0,.L4 "); -asm(".L5: "); -} -#else - -void bmove_upp(register char *dst, register const char *src, register size_t len) +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) { while (len-- != 0) *--dst = *--src; } - -#endif diff --git a/libmariadb/charset.c b/libmariadb/charset.c deleted file mode 100644 index 9d8a4224..00000000 --- a/libmariadb/charset.c +++ /dev/null @@ -1,79 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#include - -CHARSET_INFO *default_charset_info = (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *my_charset_bin= (CHARSET_INFO *)&compiled_charsets[32]; -CHARSET_INFO *my_charset_latin1= (CHARSET_INFO *)&compiled_charsets[5]; -CHARSET_INFO *my_charset_utf8_general_ci= (CHARSET_INFO *)&compiled_charsets[21]; -CHARSET_INFO *my_charset_utf16le_general_ci= (CHARSET_INFO *)&compiled_charsets[68]; - -CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) -{ - int i= 0; - - while (compiled_charsets[i].nr && cs_number != compiled_charsets[i].nr) - i++; - - return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; -} - -my_bool set_default_charset(uint cs, myf flags) -{ - CHARSET_INFO *new_charset; - DBUG_ENTER("set_default_charset"); - DBUG_PRINT("enter",("character set: %d",(int) cs)); - new_charset = mysql_get_charset_by_nr(cs); - if (!new_charset) - { - DBUG_PRINT("error",("Couldn't set default character set")); - DBUG_RETURN(TRUE); /* error */ - } - default_charset_info = new_charset; - DBUG_RETURN(FALSE); -} - -CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) -{ - int i= 0; - - while (compiled_charsets[i].nr && strcmp(cs_name, compiled_charsets[i].csname) != 0) - i++; - - return (compiled_charsets[i].nr) ? (CHARSET_INFO *)&compiled_charsets[i] : NULL; -} - -my_bool set_default_charset_by_name(const char *cs_name, myf flags) -{ - CHARSET_INFO *new_charset; - DBUG_ENTER("set_default_charset_by_name"); - DBUG_PRINT("enter",("character set: %s", cs_name)); - new_charset = mysql_get_charset_by_name(cs_name); - if (!new_charset) - { - DBUG_PRINT("error",("Couldn't set default character set")); - DBUG_RETURN(TRUE); /* error */ - } - - default_charset_info = new_charset; - DBUG_RETURN(FALSE); -} diff --git a/libmariadb/dbug.c b/libmariadb/dbug.c deleted file mode 100644 index 5e848c44..00000000 --- a/libmariadb/dbug.c +++ /dev/null @@ -1,2456 +0,0 @@ -/****************************************************************************** - * * - * N O T I C E * - * * - * Copyright Abandoned, 1987, Fred Fish * - * * - * * - * This previously copyrighted work has been placed into the public * - * domain by the author and may be freely used for any purpose, * - * private or commercial. * - * * - * Because of the number of inquiries I was receiving about the use * - * of this product in commercially developed works I have decided to * - * simply make it public domain to further its unrestricted use. I * - * specifically would be most happy to see this material become a * - * part of the standard Unix distributions by AT&T and the Berkeley * - * Computer Science Research Group, and a standard part of the GNU * - * system from the Free Software Foundation. * - * * - * I would appreciate it, as a courtesy, if this notice is left in * - * all copies and derivative works. Thank you. * - * * - * The author makes no warranty of any kind with respect to this * - * product and explicitly disclaims any implied warranties of mer- * - * chantability or fitness for any particular purpose. * - * * - ****************************************************************************** - */ - -/* - * FILE - * - * dbug.c runtime support routines for dbug package - * - * SCCS - * - * @(#)dbug.c 1.25 7/25/89 - * - * DESCRIPTION - * - * These are the runtime support routines for the dbug package. - * The dbug package has two main components; the user include - * file containing various macro definitions, and the runtime - * support routines which are called from the macro expansions. - * - * Externally visible functions in the runtime support module - * use the naming convention pattern "_db_xx...xx_", thus - * they are unlikely to collide with user defined function names. - * - * AUTHOR(S) - * - * Fred Fish (base code) - * Enhanced Software Technologies, Tempe, AZ - * asuvax!mcdphx!estinc!fnf - * - * Binayak Banerjee (profiling enhancements) - * seismo!bpa!sjuvax!bbanerje - * - * Michael Widenius: - * DBUG_DUMP - To dump a block of memory. - * PUSH_FLAG "O" - To be used insted of "o" if we - * want flushing after each write - * PUSH_FLAG "A" - as 'O', but we will append to the out file instead - * of creating a new one. - * Check of malloc on entry/exit (option "S") - * - * Sergei Golubchik: - * DBUG_EXECUTE_IF - * incremental mode (-#+t:-d,info ...) - * DBUG_SET, _db_explain_ - * thread-local settings - * negative lists (-#-d,info => everything but "info") - * - * function/ syntax - * (the logic is - think of a call stack as of a path. - * "function" means only this function, "function/" means the hierarchy. - * in the future, filters like function1/function2 could be supported. - * following this logic glob(7) wildcards are supported.) - * - */ - -/* - We can't have SAFE_MUTEX defined here as this will cause recursion - in pthread_mutex_lock -*/ - -#undef SAFE_MUTEX -#include -#include -#include - -#ifdef HAVE_FNMATCH_H -#include -#else -#define fnmatch(A,B,C) strcmp(A,B) -#endif - -#if defined(_WIN32) -#include -#else -#include -#endif - -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); - -char _dig_vec_upper[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; -char _dig_vec_lower[] = - "0123456789abcdefghijklmnopqrstuvwxyz"; - -#ifndef DBUG_OFF - - -/* - * Manifest constants which may be "tuned" if desired. - */ - -#define PRINTBUF 1024 /* Print buffer size */ -#define INDENT 2 /* Indentation per trace level */ -#define MAXDEPTH 200 /* Maximum trace depth default */ - -/* - * The following flags are used to determine which - * capabilities the user has enabled with the settings - * push macro. - * - * TRACE_ON is also used in _db_stack_frame_->level - * (until we add flags to _db_stack_frame_, increasing it by 4 bytes) - */ - -#define DEBUG_ON (1 << 1) /* Debug enabled */ -#define FILE_ON (1 << 2) /* File name print enabled */ -#define LINE_ON (1 << 3) /* Line number print enabled */ -#define DEPTH_ON (1 << 4) /* Function nest level print enabled */ -#define PROCESS_ON (1 << 5) /* Process name print enabled */ -#define NUMBER_ON (1 << 6) /* Number each line of output */ -#define PROFILE_ON (1 << 7) /* Print out profiling code */ -#define PID_ON (1 << 8) /* Identify each line with process id */ -#define TIMESTAMP_ON (1 << 9) /* timestamp every line of output */ -#define FLUSH_ON_WRITE (1 << 10) /* Flush on every write */ -#define OPEN_APPEND (1 << 11) /* Open for append */ -#define TRACE_ON ((uint)1 << 31) /* Trace enabled. MUST be the highest bit!*/ - -#define TRACING (cs->stack->flags & TRACE_ON) -#define DEBUGGING (cs->stack->flags & DEBUG_ON) -#define PROFILING (cs->stack->flags & PROFILE_ON) - -/* - * Typedefs to make things more obvious. - */ - -#define BOOLEAN my_bool - -/* - * Make it easy to change storage classes if necessary. - */ - -#define IMPORT extern /* Names defined externally */ -#define EXPORT /* Allocated here, available globally */ - -/* - * The default file for profiling. Could also add another flag - * (G?) which allowed the user to specify this. - * - * If the automatic variables get allocated on the stack in - * reverse order from their declarations, then define AUTOS_REVERSE to 1. - * This is used by the code that keeps track of stack usage. For - * forward allocation, the difference in the dbug frame pointers - * represents stack used by the callee function. For reverse allocation, - * the difference represents stack used by the caller function. - * - */ - -#define PROF_FILE "dbugmon.out" -#define PROF_EFMT "E\t%ld\t%s\n" -#define PROF_SFMT "S\t%lx\t%lx\t%s\n" -#define PROF_XFMT "X\t%ld\t%s\n" - -#ifdef M_I386 /* predefined by xenix 386 compiler */ -#define AUTOS_REVERSE 1 -#else -#define AUTOS_REVERSE 0 -#endif - -/* - * Externally supplied functions. - */ - -#ifndef HAVE_PERROR -static void perror(); /* Fake system/library error print routine */ -#endif - -/* - * The user may specify a list of functions to trace or - * debug. These lists are kept in a linear linked list, - * a very simple implementation. - */ - -struct link { - struct link *next_link; /* Pointer to the next link */ - char flags; - char str[1]; /* Pointer to link's contents */ -}; - -/* flags for struct link and return flags of InList */ -#define SUBDIR 1 /* this MUST be 1 */ -#define INCLUDE 2 -#define EXCLUDE 4 -/* this is not a struct link flag, but only a return flags of InList */ -#define MATCHED 65536 -#define NOT_MATCHED 0 - -/* - * Debugging settings can be pushed or popped off of a - * stack which is implemented as a linked list. Note - * that the head of the list is the current settings and the - * stack is pushed by adding a new settings to the head of the - * list or popped by removing the first link. - * - * Note: if out_file is NULL, the other fields are not initialized at all! - */ - -struct settings { - uint flags; /* Current settings flags */ - uint maxdepth; /* Current maximum trace depth */ - uint delay; /* Delay after each output line */ - uint sub_level; /* Sub this from code_state->level */ - FILE *out_file; /* Current output stream */ - FILE *prof_file; /* Current profiling stream */ - char name[FN_REFLEN]; /* Name of output file */ - struct link *functions; /* List of functions */ - struct link *p_functions; /* List of profiled functions */ - struct link *keywords; /* List of debug keywords */ - struct link *processes; /* List of process names */ - struct settings *next; /* Next settings in the list */ -}; - -#define is_shared(S, V) ((S)->next && (S)->next->V == (S)->V) - -/* - * Local variables not seen by user. - */ - - -static BOOLEAN init_done= FALSE; /* Set to TRUE when initialization done */ -/** - Global debugging settings. - This structure shared between all threads, - and is the last element in each thread @c CODE_STATE::stack chain. - Protected by @c THR_LOCK_init_settings. -*/ -static struct settings init_settings; -static const char *db_process= 0;/* Pointer to process name; argv[0] */ -my_bool _dbug_on_= TRUE; /* FALSE if no debugging at all */ - -typedef struct _db_code_state_ { - const char *process; /* Pointer to process name; usually argv[0] */ - const char *func; /* Name of current user function */ - const char *file; /* Name of current user file */ - struct _db_stack_frame_ *framep; /* Pointer to current frame */ - struct settings *stack; /* debugging settings */ - const char *jmpfunc; /* Remember current function for setjmp */ - const char *jmpfile; /* Remember current file for setjmp */ - int lineno; /* Current debugger output line number */ - uint level; /* Current function nesting level */ - int jmplevel; /* Remember nesting level at setjmp() */ - -/* - * The following variables are used to hold the state information - * between the call to _db_pargs_() and _db_doprnt_(), during - * expansion of the DBUG_PRINT macro. This is the only macro - * that currently uses these variables. - * - * These variables are currently used only by _db_pargs_() and - * _db_doprnt_(). - */ - - uint u_line; /* User source code line number */ - int locked; /* If locked with _db_lock_file_ */ - const char *u_keyword; /* Keyword for current macro */ - uint m_read_lock_count; -} CODE_STATE; - -/* - The test below is so we could call functions with DBUG_ENTER before - my_thread_init(). -*/ -#define get_code_state_if_not_set_or_return if (!cs && !((cs=code_state()))) return -#define get_code_state_or_return if (!((cs=code_state()))) return - - /* Handling lists */ -#define ListAdd(A,B,C) ListAddDel(A,B,C,INCLUDE) -#define ListDel(A,B,C) ListAddDel(A,B,C,EXCLUDE) -static struct link *ListAddDel(struct link *, const char *, const char *, int); -static struct link *ListCopy(struct link *); -static int InList(struct link *linkp,const char *cp); -static uint ListFlags(struct link *linkp); -static void FreeList(struct link *linkp); - - /* OpenClose debug output stream */ -static void DBUGOpenFile(CODE_STATE *,const char *, const char *, int); -static void DBUGCloseFile(CODE_STATE *cs, FILE *fp); - /* Push current debug settings */ -static void PushState(CODE_STATE *cs); - /* Free memory associated with debug state. */ -static void FreeState (CODE_STATE *cs, struct settings *state, int free_state); - /* Test for tracing enabled */ -static int DoTrace(CODE_STATE *cs); -/* - return values of DoTrace. - Can also be used as bitmask: ret & DO_TRACE -*/ -#define DO_TRACE 1 -#define DONT_TRACE 2 -#define ENABLE_TRACE 3 -#define DISABLE_TRACE 4 - - /* Test to see if file is writable */ -#if defined(HAVE_ACCESS) -static BOOLEAN Writable(const char *pathname); -#endif - -static void DoPrefix(CODE_STATE *cs, uint line); - -static char *DbugMalloc(size_t size); -static const char *BaseName(const char *pathname); -static void Indent(CODE_STATE *cs, int indent); -static void DbugFlush(CODE_STATE *); -static void DbugExit(const char *why); -static const char *DbugStrTok(const char *s); - -/* - * Miscellaneous printf format strings. - */ - -#define ERR_MISSING_RETURN "missing DBUG_RETURN or DBUG_VOID_RETURN macro in function \"%s\"\n" -#define ERR_MISSING_UNLOCK "missing DBUG_UNLOCK_FILE macro in function \"%s\"\n" -#define ERR_OPEN "%s: can't open debug output stream \"%s\": " -#define ERR_CLOSE "%s: can't close debug file: " -#define ERR_ABORT "%s: debugger aborting because %s\n" - -/* - * Macros and defines for testing file accessibility under UNIX and MSDOS. - */ - -#undef EXISTS -#if !defined(HAVE_ACCESS) -#define EXISTS(pathname) (FALSE) /* Assume no existance */ -#define Writable(name) (TRUE) -#else -#define EXISTS(pathname) (access(pathname, F_OK) == 0) -#define WRITABLE(pathname) (access(pathname, W_OK) == 0) -#endif - - -/* -** Macros to allow dbugging with threads -*/ - -#include -static pthread_mutex_t THR_LOCK_dbug; - -/** - A mutex protecting flushing of gcov data, see _db_flush_gcov_(). - We don't re-use THR_LOCK_dbug, because that would disallow: - DBUG_LOCK_FILE; ..... DBUG_SUICIDE(); .... DBUG_UNLOCK_FILE; -*/ -static pthread_mutex_t THR_LOCK_gcov; -static pthread_mutex_t THR_LOCK_init_settings; - -static CODE_STATE *code_state(void) -{ - CODE_STATE *cs, **cs_ptr; - - /* - _dbug_on_ is reset if we don't plan to use any debug commands at all and - we want to run on maximum speed - */ - if (!_dbug_on_) - return 0; - - if (!init_done) - { - init_done=TRUE; - pthread_mutex_init(&THR_LOCK_dbug, NULL); - pthread_mutex_init(&THR_LOCK_gcov, NULL); - pthread_mutex_init(&THR_LOCK_init_settings, NULL); - memset(&init_settings, 0, sizeof(init_settings)); - init_settings.out_file=stderr; - init_settings.flags=OPEN_APPEND; - } - - if (!(cs_ptr= (CODE_STATE**) my_thread_var_dbug())) - return 0; /* Thread not initialised */ - if (!(cs= *cs_ptr)) - { - cs=(CODE_STATE*) DbugMalloc(sizeof(*cs)); - memset(cs, 0, sizeof(*cs)); - cs->process= db_process ? db_process : "dbug"; - cs->func="?func"; - cs->file="?file"; - cs->stack=&init_settings; - cs->m_read_lock_count= 0; - *cs_ptr= cs; - } - return cs; -} - -/** - Lock the stack debugging settings. - Only the shared (global) settings are locked if necessary, - per thread settings are local and safe to use. - This lock is re entrant. - @sa unlock_stack -*/ -static void read_lock_stack(CODE_STATE *cs) -{ - if (cs->stack == &init_settings) - { - if (++(cs->m_read_lock_count) == 1) - pthread_mutex_lock(&THR_LOCK_init_settings); - } -} - -/** - Unlock the stack debugging settings. - @sa read_lock_stack -*/ -static void unlock_stack(CODE_STATE *cs) -{ - if (cs->stack == &init_settings) - { - if (--(cs->m_read_lock_count) == 0) - pthread_mutex_unlock(&THR_LOCK_init_settings); - } -} - -/* - * Translate some calls among different systems. - */ - -#ifdef HAVE_SLEEP -/* sleep() wants seconds */ -#define Delay(A) sleep(((uint) A)/10) -#else -#define Delay(A) (0) -#endif - -/* - * FUNCTION - * - * _db_process_ give the name to the current process/thread - * - * SYNOPSIS - * - * VOID _process_(name) - * char *name; - * - */ - -void _db_process_(const char *name) -{ - CODE_STATE *cs; - - if (!db_process) - db_process= name; - - get_code_state_or_return; - cs->process= name; -} - -/* - * FUNCTION - * - * DbugParse parse control string and set current debugger settings - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", - * parses the control string, and sets - * up a current debug settings. - * - * The debug control string is a sequence of colon separated fields - * as follows: - * - * [+]::...: - * - * Each field consists of a mandatory flag character followed by - * an optional "," and comma separated list of modifiers: - * - * [sign]flag[,modifier,modifier,...,modifier] - * - * See the manual for the list of supported signs, flags, and modifiers - * - * For convenience, any leading "-#" is stripped off. - * - * RETURN - * 1 - a list of functions ("f" flag) was possibly changed - * 0 - a list of functions was not changed - */ - -int DbugParse(CODE_STATE *cs, const char *control) -{ - const char *end; - int rel, f_used=0; - struct settings *stack; - - /* - Make sure we are not changing settings while inside a - DBUG_LOCK_FILE - DBUG_UNLOCK_FILE - section, that is a mis use, that would cause changing - DBUG_FILE while the caller prints to it. - */ - assert(! cs->locked); - - stack= cs->stack; - - /* - When parsing the global init_settings itself, - make sure to block every other thread using dbug functions. - */ - assert(cs->m_read_lock_count == 0); - if (stack == &init_settings) - pthread_mutex_lock(&THR_LOCK_init_settings); - - if (control[0] == '-' && control[1] == '#') - control+=2; - - rel= control[0] == '+' || control[0] == '-'; - if ((!rel || (!stack->out_file && !stack->next))) - { - /* Free memory associated with the state before resetting its members */ - FreeState(cs, stack, 0); - stack->flags= 0; - stack->delay= 0; - stack->maxdepth= 0; - stack->sub_level= 0; - stack->out_file= stderr; - stack->prof_file= NULL; - stack->functions= NULL; - stack->p_functions= NULL; - stack->keywords= NULL; - stack->processes= NULL; - } - else if (!stack->out_file) - { - stack->flags= stack->next->flags; - stack->delay= stack->next->delay; - stack->maxdepth= stack->next->maxdepth; - stack->sub_level= stack->next->sub_level; - strcpy(stack->name, stack->next->name); - stack->prof_file= stack->next->prof_file; - if (stack->next == &init_settings) - { - assert(stack != &init_settings); - pthread_mutex_lock(&THR_LOCK_init_settings); - - /* - Never share with the global parent - it can change under your feet. - - Reset out_file to stderr to prevent sharing of trace files between - global and session settings. - */ - stack->out_file= stderr; - stack->functions= ListCopy(init_settings.functions); - stack->p_functions= ListCopy(init_settings.p_functions); - stack->keywords= ListCopy(init_settings.keywords); - stack->processes= ListCopy(init_settings.processes); - - pthread_mutex_unlock(&THR_LOCK_init_settings); - } - else - { - stack->out_file= stack->next->out_file; - stack->functions= stack->next->functions; - stack->p_functions= stack->next->p_functions; - stack->keywords= stack->next->keywords; - stack->processes= stack->next->processes; - } - } - - end= DbugStrTok(control); - while (control < end) - { - int c, sign= (*control == '+') ? 1 : (*control == '-') ? -1 : 0; - if (sign) control++; - c= *control++; - if (*control == ',') control++; - /* XXX when adding new cases here, don't forget _db_explain_ ! */ - switch (c) { - case 'd': - if (sign < 0 && control == end) - { - if (!is_shared(stack, keywords)) - FreeList(stack->keywords); - stack->keywords=NULL; - stack->flags &= ~DEBUG_ON; - break; - } - if (rel && is_shared(stack, keywords)) - stack->keywords= ListCopy(stack->keywords); - if (sign < 0) - { - if (DEBUGGING) - stack->keywords= ListDel(stack->keywords, control, end); - break; - } - stack->keywords= ListAdd(stack->keywords, control, end); - stack->flags |= DEBUG_ON; - break; - case 'D': - stack->delay= atoi(control); - break; - case 'f': - f_used= 1; - if (sign < 0 && control == end) - { - if (!is_shared(stack,functions)) - FreeList(stack->functions); - stack->functions=NULL; - break; - } - if (rel && is_shared(stack,functions)) - stack->functions= ListCopy(stack->functions); - if (sign < 0) - stack->functions= ListDel(stack->functions, control, end); - else - stack->functions= ListAdd(stack->functions, control, end); - break; - case 'F': - if (sign < 0) - stack->flags &= ~FILE_ON; - else - stack->flags |= FILE_ON; - break; - case 'i': - if (sign < 0) - stack->flags &= ~PID_ON; - else - stack->flags |= PID_ON; - break; - case 'L': - if (sign < 0) - stack->flags &= ~LINE_ON; - else - stack->flags |= LINE_ON; - break; - case 'n': - if (sign < 0) - stack->flags &= ~DEPTH_ON; - else - stack->flags |= DEPTH_ON; - break; - case 'N': - if (sign < 0) - stack->flags &= ~NUMBER_ON; - else - stack->flags |= NUMBER_ON; - break; - case 'A': - case 'O': - stack->flags |= FLUSH_ON_WRITE; - /* fall through */ - case 'a': - case 'o': - /* In case we already have an open file. */ - if (!is_shared(stack, out_file)) - DBUGCloseFile(cs, stack->out_file); - if (sign < 0) - { - stack->flags &= ~FLUSH_ON_WRITE; - stack->out_file= stderr; - break; - } - if (c == 'a' || c == 'A') - stack->flags |= OPEN_APPEND; - else - stack->flags &= ~OPEN_APPEND; - if (control != end) - DBUGOpenFile(cs, control, end, stack->flags & OPEN_APPEND); - else - DBUGOpenFile(cs, "-",0,0); - break; - case 'p': - if (sign < 0 && control == end) - { - if (!is_shared(stack,processes)) - FreeList(stack->processes); - stack->processes=NULL; - break; - } - if (rel && is_shared(stack, processes)) - stack->processes= ListCopy(stack->processes); - if (sign < 0) - stack->processes= ListDel(stack->processes, control, end); - else - stack->processes= ListAdd(stack->processes, control, end); - break; - case 'P': - if (sign < 0) - stack->flags &= ~PROCESS_ON; - else - stack->flags |= PROCESS_ON; - break; - case 'r': - stack->sub_level= cs->level; - break; - case 't': - if (sign < 0) - { - if (control != end) - stack->maxdepth-= atoi(control); - else - stack->maxdepth= 0; - } - else - { - if (control != end) - stack->maxdepth+= atoi(control); - else - stack->maxdepth= MAXDEPTH; - } - if (stack->maxdepth > 0) - stack->flags |= TRACE_ON; - else - stack->flags &= ~TRACE_ON; - break; - case 'T': - if (sign < 0) - stack->flags &= ~TIMESTAMP_ON; - else - stack->flags |= TIMESTAMP_ON; - break; - } - if (!*end) - break; - control=end+1; - end= DbugStrTok(control); - } - - if (stack->next == &init_settings) - { - /* - Enforce nothing is shared with the global init_settings - */ - assert((stack->functions == NULL) || (stack->functions != init_settings.functions)); - assert((stack->p_functions == NULL) || (stack->p_functions != init_settings.p_functions)); - assert((stack->keywords == NULL) || (stack->keywords != init_settings.keywords)); - assert((stack->processes == NULL) || (stack->processes != init_settings.processes)); - } - - if (stack == &init_settings) - pthread_mutex_unlock(&THR_LOCK_init_settings); - - return !rel || f_used; -} - -#define framep_trace_flag(cs, frp) (frp ? \ - frp->level & TRACE_ON : \ - (ListFlags(cs->stack->functions) & INCLUDE) ? \ - 0 : (uint)TRACE_ON) - -void FixTraceFlags_helper(CODE_STATE *cs, const char *func, - struct _db_stack_frame_ *framep) -{ - if (framep->prev) - FixTraceFlags_helper(cs, framep->func, framep->prev); - - cs->func= func; - cs->level= framep->level & ~TRACE_ON; - framep->level= cs->level | framep_trace_flag(cs, framep->prev); - /* - we don't set cs->framep correctly, even though DoTrace uses it. - It's ok, because cs->framep may only affect DO_TRACE/DONT_TRACE return - values, but we ignore them here anyway - */ - switch(DoTrace(cs)) { - case ENABLE_TRACE: - framep->level|= TRACE_ON; - break; - case DISABLE_TRACE: - framep->level&= ~TRACE_ON; - break; - } -} - -#define fflags(cs) cs->stack->out_file ? ListFlags(cs->stack->functions) : TRACE_ON; - -void FixTraceFlags(uint old_fflags, CODE_STATE *cs) -{ - const char *func; - uint new_fflags, traceon, level; - struct _db_stack_frame_ *framep; - - /* - first (a.k.a. safety) check: - if we haven't started tracing yet, no call stack at all - we're safe. - */ - framep=cs->framep; - if (framep == 0) - return; - - /* - Ok, the tracing has started, call stack isn't empty. - - second check: does the new list have a SUBDIR rule ? - */ - new_fflags=fflags(cs); - if (new_fflags & SUBDIR) - goto yuck; - - /* - Ok, new list doesn't use SUBDIR. - - third check: we do NOT need to re-scan if - neither old nor new lists used SUBDIR flag and if a default behavior - (whether an unlisted function is traced) hasn't changed. - Default behavior depends on whether there're INCLUDE elements in the list. - */ - if (!(old_fflags & SUBDIR) && !((new_fflags^old_fflags) & INCLUDE)) - return; - - /* - Ok, old list may've used SUBDIR, or defaults could've changed. - - fourth check: are we inside a currently active SUBDIR rule ? - go up the call stack, if TRACE_ON flag ever changes its value - we are. - */ - for (traceon=framep->level; framep; framep=framep->prev) - if ((traceon ^ framep->level) & TRACE_ON) - goto yuck; - - /* - Ok, TRACE_ON flag doesn't change in the call stack. - - fifth check: but is the top-most value equal to a default one ? - */ - if (((traceon & TRACE_ON) != 0) == ((new_fflags & INCLUDE) == 0)) - return; - -yuck: - /* - Yuck! function list was changed, and one of the currently active rules - was possibly affected. For example, a tracing could've been enabled or - disabled for a function somewhere up the call stack. - To react correctly, we must go up the call stack all the way to - the top and re-match rules to set TRACE_ON bit correctly. - - We must traverse the stack forwards, not backwards. - That's what a recursive helper is doing. - It'll destroy two CODE_STATE fields, save them now. - */ - func= cs->func; - level= cs->level; - FixTraceFlags_helper(cs, func, cs->framep); - /* now we only need to restore CODE_STATE fields, and we're done */ - cs->func= func; - cs->level= level; -} - -/* - * FUNCTION - * - * _db_set_ set current debugger settings - * - * SYNOPSIS - * - * VOID _db_set_(control) - * char *control; - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", - * parses the control string, and sets up a current debug - * settings. Pushes a new debug settings if the current is - * set to the initial debugger settings. - * - */ - -void _db_set_(const char *control) -{ - CODE_STATE *cs; - uint old_fflags; - get_code_state_or_return; - - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - if (cs->stack == &init_settings) - PushState(cs); - - if (DbugParse(cs, control)) - { - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - -/* - * FUNCTION - * - * _db_push_ push current debugger settings and set up new one - * - * SYNOPSIS - * - * VOID _db_push_(control) - * char *control; - * - * DESCRIPTION - * - * Given pointer to a debug control string in "control", pushes - * the current debug settings, parses the control string, and sets - * up a new debug settings with DbugParse() - * - */ - -void _db_push_(const char *control) -{ - CODE_STATE *cs; - uint old_fflags; - get_code_state_or_return; - - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - PushState(cs); - - if (DbugParse(cs, control)) - { - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - - -/** - Returns TRUE if session-local settings have been set. -*/ - -int _db_is_pushed_() -{ - CODE_STATE *cs= NULL; - get_code_state_or_return FALSE; - return (cs->stack != &init_settings); -} - -/* - * FUNCTION - * - * _db_set_init_ set initial debugger settings - * - * SYNOPSIS - * - * VOID _db_set_init_(control) - * char *control; - * - * DESCRIPTION - * see _db_set_ - * - */ - -void _db_set_init_(const char *control) -{ - CODE_STATE tmp_cs; - memset(&tmp_cs, 0, sizeof(tmp_cs)); - tmp_cs.stack= &init_settings; - tmp_cs.process= db_process ? db_process : "dbug"; - DbugParse(&tmp_cs, control); -} - -/* - * FUNCTION - * - * _db_pop_ pop the debug stack - * - * DESCRIPTION - * - * Pops the debug stack, returning the debug settings to its - * condition prior to the most recent _db_push_ invocation. - * Note that the pop will fail if it would remove the last - * valid settings from the stack. This prevents user errors - * in the push/pop sequence from screwing up the debugger. - * Maybe there should be some kind of warning printed if the - * user tries to pop too many states. - * - */ - -void _db_pop_() -{ - struct settings *discard; - uint old_fflags; - CODE_STATE *cs; - - get_code_state_or_return; - - discard= cs->stack; - if (discard != &init_settings) - { - read_lock_stack(cs); - old_fflags=fflags(cs); - unlock_stack(cs); - - cs->stack= discard->next; - FreeState(cs, discard, 1); - - read_lock_stack(cs); - FixTraceFlags(old_fflags, cs); - unlock_stack(cs); - } -} - -/* - * FUNCTION - * - * _db_explain_ generates 'control' string for the current settings - * - * RETURN - * 0 - ok - * 1 - buffer too short, output truncated - * - */ - -/* helper macros */ -#define char_to_buf(C) do { \ - *buf++=(C); \ - if (buf >= end) goto overflow; \ - } while (0) -#define str_to_buf(S) do { \ - char_to_buf(','); \ - buf=strnmov(buf, (S), len+1); \ - if (buf >= end) goto overflow; \ - } while (0) -#define list_to_buf(l, f) do { \ - struct link *listp=(l); \ - while (listp) \ - { \ - if (listp->flags & (f)) \ - { \ - str_to_buf(listp->str); \ - if (listp->flags & SUBDIR) \ - char_to_buf('/'); \ - } \ - listp=listp->next_link; \ - } \ - } while (0) -#define int_to_buf(i) do { \ - char b[50]; \ - int10_to_str((i), b, 10); \ - str_to_buf(b); \ - } while (0) -#define colon_to_buf do { \ - if (buf != start) char_to_buf(':'); \ - } while(0) -#define op_int_to_buf(C, val, def) do { \ - if ((val) != (def)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - int_to_buf(val); \ - } \ - } while (0) -#define op_intf_to_buf(C, val, def, cond) do { \ - if ((cond)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - if ((val) != (def)) int_to_buf(val); \ - } \ - } while (0) -#define op_str_to_buf(C, val, cond) do { \ - if ((cond)) \ - { \ - char *s=(val); \ - colon_to_buf; \ - char_to_buf((C)); \ - if (*s) str_to_buf(s); \ - } \ - } while (0) -#define op_list_to_buf(C, val, cond) do { \ - if ((cond)) \ - { \ - int f=ListFlags(val); \ - colon_to_buf; \ - char_to_buf((C)); \ - if (f & INCLUDE) \ - list_to_buf(val, INCLUDE); \ - if (f & EXCLUDE) \ - { \ - colon_to_buf; \ - char_to_buf('-'); \ - char_to_buf((C)); \ - list_to_buf(val, EXCLUDE); \ - } \ - } \ - } while (0) -#define op_bool_to_buf(C, cond) do { \ - if ((cond)) \ - { \ - colon_to_buf; \ - char_to_buf((C)); \ - } \ - } while (0) - -int _db_explain_ (CODE_STATE *cs, char *buf, size_t len) -{ - char *start=buf, *end=buf+len-4; - - get_code_state_if_not_set_or_return *buf=0; - - read_lock_stack(cs); - - op_list_to_buf('d', cs->stack->keywords, DEBUGGING); - op_int_to_buf ('D', cs->stack->delay, 0); - op_list_to_buf('f', cs->stack->functions, cs->stack->functions); - op_bool_to_buf('F', cs->stack->flags & FILE_ON); - op_bool_to_buf('i', cs->stack->flags & PID_ON); - op_list_to_buf('g', cs->stack->p_functions, PROFILING); - op_bool_to_buf('L', cs->stack->flags & LINE_ON); - op_bool_to_buf('n', cs->stack->flags & DEPTH_ON); - op_bool_to_buf('N', cs->stack->flags & NUMBER_ON); - op_str_to_buf( - ((cs->stack->flags & FLUSH_ON_WRITE ? 0 : 32) | - (cs->stack->flags & OPEN_APPEND ? 'A' : 'O')), - cs->stack->name, cs->stack->out_file != stderr); - op_list_to_buf('p', cs->stack->processes, cs->stack->processes); - op_bool_to_buf('P', cs->stack->flags & PROCESS_ON); - op_bool_to_buf('r', cs->stack->sub_level != 0); - op_intf_to_buf('t', cs->stack->maxdepth, MAXDEPTH, TRACING); - op_bool_to_buf('T', cs->stack->flags & TIMESTAMP_ON); - - unlock_stack(cs); - - *buf= '\0'; - return 0; - -overflow: - *end++= '.'; - *end++= '.'; - *end++= '.'; - *end= '\0'; - - unlock_stack(cs); - return 1; -} - -#undef char_to_buf -#undef str_to_buf -#undef list_to_buf -#undef int_to_buf -#undef colon_to_buf -#undef op_int_to_buf -#undef op_intf_to_buf -#undef op_str_to_buf -#undef op_list_to_buf -#undef op_bool_to_buf - -/* - * FUNCTION - * - * _db_explain_init_ explain initial debugger settings - * - * DESCRIPTION - * see _db_explain_ - */ - -int _db_explain_init_(char *buf, size_t len) -{ - CODE_STATE cs; - memset(&cs, 0, sizeof(cs)); - cs.stack=&init_settings; - return _db_explain_(&cs, buf, len); -} - -/* - * FUNCTION - * - * _db_enter_ process entry point to user function - * - * SYNOPSIS - * - * VOID _db_enter_(_func_, _file_, _line_, _stack_frame_) - * char *_func_; points to current function name - * char *_file_; points to current file name - * int _line_; called from source line number - * struct _db_stack_frame_ allocated on the caller's stack - * - * DESCRIPTION - * - * Called at the beginning of each user function to tell - * the debugger that a new function has been entered. - * Note that the pointers to the previous user function - * name and previous user file name are stored on the - * caller's stack (this is why the ENTER macro must be - * the first "executable" code in a function, since it - * allocates these storage locations). The previous nesting - * level is also stored on the callers stack for internal - * self consistency checks. - * - * Also prints a trace line if tracing is enabled and - * increments the current function nesting depth. - * - * Note that this mechanism allows the debugger to know - * what the current user function is at all times, without - * maintaining an internal stack for the function names. - * - */ - -void _db_enter_(const char *_func_, const char *_file_, - uint _line_, struct _db_stack_frame_ *_stack_frame_) -{ - int save_errno; - CODE_STATE *cs; - if (!((cs=code_state()))) - { - _stack_frame_->level= 0; /* Set to avoid valgrind warnings if dbug is enabled later */ - _stack_frame_->prev= 0; - return; - } - save_errno= errno; - - read_lock_stack(cs); - - _stack_frame_->func= cs->func; - _stack_frame_->file= cs->file; - cs->func= _func_; - cs->file= _file_; - _stack_frame_->prev= cs->framep; - _stack_frame_->level= ++cs->level | framep_trace_flag(cs, cs->framep); - cs->framep= _stack_frame_; - - switch (DoTrace(cs)) { - case ENABLE_TRACE: - cs->framep->level|= TRACE_ON; - if (!TRACING) break; - /* fall through */ - case DO_TRACE: - if (TRACING) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - Indent(cs, cs->level); - (void) fprintf(cs->stack->out_file, ">%s\n", cs->func); - DbugFlush(cs); /* This does a unlock */ - } - break; - case DISABLE_TRACE: - cs->framep->level&= ~TRACE_ON; - /* fall through */ - case DONT_TRACE: - break; - } - errno=save_errno; - - unlock_stack(cs); -} - -/* - * FUNCTION - * - * _db_return_ process exit from user function - * - * SYNOPSIS - * - * VOID _db_return_(_line_, _stack_frame_) - * int _line_; current source line number - * struct _db_stack_frame_ allocated on the caller's stack - * - * DESCRIPTION - * - * Called just before user function executes an explicit or implicit - * return. Prints a trace line if trace is enabled, decrements - * the current nesting level, and restores the current function and - * file names from the defunct function's stack. - * - */ - -void _db_return_(uint _line_, struct _db_stack_frame_ *_stack_frame_) -{ - int save_errno=errno; - uint _slevel_= _stack_frame_->level & ~TRACE_ON; - CODE_STATE *cs; - get_code_state_or_return; - - if (cs->framep != _stack_frame_) - { - char buf[512]; - my_snprintf(buf, sizeof(buf), ERR_MISSING_RETURN, cs->func); - DbugExit(buf); - } - - read_lock_stack(cs); - - if (DoTrace(cs) & DO_TRACE) - { - if (TRACING) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - Indent(cs, cs->level); - (void) fprintf(cs->stack->out_file, "<%s %u\n", cs->func, _line_); - DbugFlush(cs); - } - } - /* - Check to not set level < 0. This can happen if DBUG was disabled when - function was entered and enabled in function. - */ - cs->level= _slevel_ != 0 ? _slevel_ - 1 : 0; - cs->func= _stack_frame_->func; - cs->file= _stack_frame_->file; - if (cs->framep != NULL) - cs->framep= cs->framep->prev; - errno=save_errno; - - unlock_stack(cs); -} - - -/* - * FUNCTION - * - * _db_pargs_ log arguments for subsequent use by _db_doprnt_() - * - * SYNOPSIS - * - * VOID _db_pargs_(_line_, keyword) - * int _line_; - * char *keyword; - * - * DESCRIPTION - * - * The new universal printing macro DBUG_PRINT, which replaces - * all forms of the DBUG_N macros, needs two calls to runtime - * support routines. The first, this function, remembers arguments - * that are used by the subsequent call to _db_doprnt_(). - * - */ - -void _db_pargs_(uint _line_, const char *keyword) -{ - CODE_STATE *cs; - get_code_state_or_return; - cs->u_line= _line_; - cs->u_keyword= keyword; -} - - -/* - * FUNCTION - * - * _db_doprnt_ handle print of debug lines - * - * SYNOPSIS - * - * VOID _db_doprnt_(format, va_alist) - * char *format; - * va_dcl; - * - * DESCRIPTION - * - * When invoked via one of the DBUG macros, tests the current keyword - * set by calling _db_pargs_() to see if that macro has been selected - * for processing via the debugger control string, and if so, handles - * printing of the arguments via the format string. The line number - * of the DBUG macro in the source is found in u_line. - * - * Note that the format string SHOULD NOT include a terminating - * newline, this is supplied automatically. - * - */ - -#include - -void _db_doprnt_(const char *format,...) -{ - va_list args; - CODE_STATE *cs; - get_code_state_or_return; - - /* Dirty read, for DBUG_PRINT() performance. */ - if (! DEBUGGING) - return; - - va_start(args,format); - read_lock_stack(cs); - - if (_db_keyword_(cs, cs->u_keyword, 0)) - { - int save_errno=errno; - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, cs->u_line); - if (TRACING) - Indent(cs, cs->level + 1); - else - (void) fprintf(cs->stack->out_file, "%s: ", cs->func); - (void) fprintf(cs->stack->out_file, "%s: ", cs->u_keyword); - (void) vfprintf(cs->stack->out_file, format, args); - DbugFlush(cs); - errno=save_errno; - } - unlock_stack(cs); - va_end(args); -} - -/* - * FUNCTION - * - * _db_dump_ dump a string in hex - * - * SYNOPSIS - * - * void _db_dump_(_line_,keyword,memory,length) - * int _line_; current source line number - * char *keyword; - * char *memory; Memory to print - * int length; Bytes to print - * - * DESCRIPTION - * Dump N characters in a binary array. - * Is used to examine corrupted memory or arrays. - */ - -void _db_dump_(uint _line_, const char *keyword, - const unsigned char *memory, size_t length) -{ - int pos; - CODE_STATE *cs; - get_code_state_or_return; - - /* Dirty read, for DBUG_DUMP() performance. */ - if (! DEBUGGING) - return; - - read_lock_stack(cs); - - if (_db_keyword_(cs, keyword, 0)) - { - if (!cs->locked) - pthread_mutex_lock(&THR_LOCK_dbug); - DoPrefix(cs, _line_); - if (TRACING) - { - Indent(cs, cs->level + 1); - pos= MIN(MAX(cs->level-cs->stack->sub_level,0)*INDENT,80); - } - else - { - fprintf(cs->stack->out_file, "%s: ", cs->func); - } - (void) fprintf(cs->stack->out_file, "%s: Memory: 0x%lx Bytes: (%ld)\n", - keyword, (ulong) memory, (long) length); - - pos=0; - while (length-- > 0) - { - uint tmp= *((unsigned char*) memory++); - if ((pos+=3) >= 80) - { - fputc('\n',cs->stack->out_file); - pos=3; - } - fputc(_dig_vec_upper[((tmp >> 4) & 15)], cs->stack->out_file); - fputc(_dig_vec_upper[tmp & 15], cs->stack->out_file); - fputc(' ',cs->stack->out_file); - } - (void) fputc('\n',cs->stack->out_file); - DbugFlush(cs); - } - - unlock_stack(cs); -} - - -/* - * FUNCTION - * - * ListAddDel modify the list according to debug control string - * - * DESCRIPTION - * - * Given pointer to a comma separated list of strings in "cltp", - * parses the list, and modifies "listp", returning a pointer - * to the new list. - * - * The mode of operation is defined by "todo" parameter. - * - * If it is INCLUDE, elements (strings from "cltp") are added to the - * list, they will have INCLUDE flag set. If the list already contains - * the string in question, new element is not added, but a flag of - * the existing element is adjusted (INCLUDE bit is set, EXCLUDE bit - * is removed). - * - * If it is EXCLUDE, elements are added to the list with the EXCLUDE - * flag set. If the list already contains the string in question, - * it is removed, new element is not added. - */ - -static struct link *ListAddDel(struct link *head, const char *ctlp, - const char *end, int todo) -{ - const char *start; - struct link **cur; - size_t len; - int subdir; - - ctlp--; -next: - while (++ctlp < end) - { - start= ctlp; - subdir=0; - while (ctlp < end && *ctlp != ',') - ctlp++; - len=ctlp-start; - if (start[len-1] == '/') - { - len--; - subdir=SUBDIR; - } - if (len == 0) continue; - for (cur=&head; *cur; cur=&((*cur)->next_link)) - { - if (!strncmp((*cur)->str, start, len)) - { - if ((*cur)->flags & todo) /* same action ? */ - (*cur)->flags|= subdir; /* just merge the SUBDIR flag */ - else if (todo == EXCLUDE) - { - struct link *delme=*cur; - *cur=(*cur)->next_link; - free((void*) delme); - } - else - { - (*cur)->flags&=~(EXCLUDE | SUBDIR); - (*cur)->flags|=INCLUDE | subdir; - } - goto next; - } - } - *cur= (struct link *) DbugMalloc(sizeof(struct link)+len); - memcpy((*cur)->str, start, len); - (*cur)->str[len]=0; - (*cur)->flags=todo | subdir; - (*cur)->next_link=0; - } - return head; -} - -/* - * FUNCTION - * - * ListCopy make a copy of the list - * - * SYNOPSIS - * - * static struct link *ListCopy(orig) - * struct link *orig; - * - * DESCRIPTION - * - * Given pointer to list, which contains a copy of every element from - * the original list. - * - * the orig pointer can be NULL - * - * Note that since each link is added at the head of the list, - * the final list will be in "reverse order", which is not - * significant for our usage here. - * - */ - -static struct link *ListCopy(struct link *orig) -{ - struct link *new_malloc; - struct link *head; - size_t len; - - head= NULL; - while (orig != NULL) - { - len= strlen(orig->str); - new_malloc= (struct link *) DbugMalloc(sizeof(struct link)+len); - memcpy(new_malloc->str, orig->str, len); - new_malloc->str[len]= 0; - new_malloc->flags=orig->flags; - new_malloc->next_link= head; - head= new_malloc; - orig= orig->next_link; - } - return head; -} - -/* - * FUNCTION - * - * InList test a given string for member of a given list - * - * DESCRIPTION - * - * Tests the string pointed to by "cp" to determine if it is in - * the list pointed to by "linkp". Linkp points to the first - * link in the list. If linkp is NULL or contains only EXCLUDE - * elements then the string is treated as if it is in the list. - * This may seem rather strange at first but leads to the desired - * operation if no list is given. The net effect is that all - * strings will be accepted when there is no list, and when there - * is a list, only those strings in the list will be accepted. - * - * RETURN - * combination of SUBDIR, INCLUDE, EXCLUDE, MATCHED flags - * - */ - -static int InList(struct link *linkp, const char *cp) -{ - int result; - - for (result=MATCHED; linkp != NULL; linkp= linkp->next_link) - { - if (!fnmatch(linkp->str, cp, 0)) - return linkp->flags; - if (!(linkp->flags & EXCLUDE)) - result=NOT_MATCHED; - if (linkp->flags & SUBDIR) - result|=SUBDIR; - } - return result; -} - -/* - * FUNCTION - * - * ListFlags returns aggregated list flags (ORed over all elements) - * - */ - -static uint ListFlags(struct link *linkp) -{ - uint f; - for (f=0; linkp != NULL; linkp= linkp->next_link) - f|= linkp->flags; - return f; -} - -/* - * FUNCTION - * - * PushState push current settings onto stack and set up new one - * - * SYNOPSIS - * - * static VOID PushState() - * - * DESCRIPTION - * - * Pushes the current settings on the settings stack, and creates - * a new settings. The new settings is NOT initialized - * - * The settings stack is a linked list of settings, with the new - * settings added at the head. This allows the stack to grow - * to the limits of memory if necessary. - * - */ - -static void PushState(CODE_STATE *cs) -{ - struct settings *new_malloc; - - new_malloc= (struct settings *) DbugMalloc(sizeof(struct settings)); - memset(new_malloc, 0, sizeof(struct settings)); - new_malloc->next= cs->stack; - cs->stack= new_malloc; -} - -/* - * FUNCTION - * - * FreeState Free memory associated with a struct state. - * - * SYNOPSIS - * - * static void FreeState (state) - * struct state *state; - * int free_state; - * - * DESCRIPTION - * - * Deallocates the memory allocated for various information in a - * state. If free_state is set, also free 'state' - * - */ -static void FreeState(CODE_STATE *cs, struct settings *state, int free_state) -{ - if (!is_shared(state, keywords)) - FreeList(state->keywords); - if (!is_shared(state, functions)) - FreeList(state->functions); - if (!is_shared(state, processes)) - FreeList(state->processes); - if (!is_shared(state, p_functions)) - FreeList(state->p_functions); - - if (!is_shared(state, out_file)) - DBUGCloseFile(cs, state->out_file); - else - (void) fflush(state->out_file); - - if (!is_shared(state, prof_file)) - DBUGCloseFile(cs, state->prof_file); - else - (void) fflush(state->prof_file); - - if (free_state) - free((void*) state); -} - - -/* - * FUNCTION - * - * _db_end_ End debugging, freeing state stack memory. - * - * SYNOPSIS - * - * static VOID _db_end_ () - * - * DESCRIPTION - * - * Ends debugging, de-allocating the memory allocated to the - * state stack. - * - * To be called at the very end of the program. - * - */ -void _db_end_() -{ - struct settings *discard; - static struct settings tmp; - CODE_STATE *cs; - /* - Set _dbug_on_ to be able to do full reset even when DEBUGGER_OFF was - called after dbug was initialized - */ - _dbug_on_= 1; - get_code_state_or_return; - - /* - The caller may have missed a DBUG_UNLOCK_FILE, - we are breaking this lock to enforce DBUG_END can proceed. - */ - if (cs->locked) - { - fprintf(stderr, ERR_MISSING_UNLOCK, "(unknown)"); - cs->locked= 0; - pthread_mutex_unlock(&THR_LOCK_dbug); - } - - while ((discard= cs->stack)) - { - if (discard == &init_settings) - break; - cs->stack= discard->next; - FreeState(cs, discard, 1); - } - - pthread_mutex_lock(&THR_LOCK_init_settings); - tmp= init_settings; - init_settings.flags= OPEN_APPEND; - init_settings.out_file= stderr; - init_settings.prof_file= stderr; - init_settings.maxdepth= 0; - init_settings.delay= 0; - init_settings.sub_level= 0; - init_settings.functions= 0; - init_settings.p_functions= 0; - init_settings.keywords= 0; - init_settings.processes= 0; - pthread_mutex_unlock(&THR_LOCK_init_settings); - FreeState(cs, &tmp, 0); -} - - -/* - * FUNCTION - * - * DoTrace check to see if tracing is current enabled - * - * DESCRIPTION - * - * Checks to see if dbug in this function is enabled based on - * whether the maximum trace depth has been reached, the current - * function is selected, and the current process is selected. - * - */ - -static int DoTrace(CODE_STATE *cs) -{ - if ((cs->stack->maxdepth == 0 || cs->level <= cs->stack->maxdepth) && - InList(cs->stack->processes, cs->process) & (MATCHED|INCLUDE)) - switch(InList(cs->stack->functions, cs->func)) { - case INCLUDE|SUBDIR: return ENABLE_TRACE; - case INCLUDE: return DO_TRACE; - case MATCHED|SUBDIR: - case NOT_MATCHED|SUBDIR: - case MATCHED: return (framep_trace_flag(cs, cs->framep)) ? - DO_TRACE : DONT_TRACE; - case EXCLUDE: - case NOT_MATCHED: return DONT_TRACE; - case EXCLUDE|SUBDIR: return DISABLE_TRACE; - } - return DONT_TRACE; -} - -FILE *_db_fp_(void) -{ - CODE_STATE *cs; - get_code_state_or_return NULL; - return cs->stack->out_file; -} - -/* - * FUNCTION - * - * _db_keyword_ test keyword for member of keyword list - * - * DESCRIPTION - * - * Test a keyword to determine if it is in the currently active - * keyword list. If strict=0, a keyword is accepted - * if the list is null, otherwise it must match one of the list - * members. When debugging is not on, no keywords are accepted. - * After the maximum trace level is exceeded, no keywords are - * accepted (this behavior subject to change). Additionally, - * the current function and process must be accepted based on - * their respective lists. - * - * Returns TRUE if keyword accepted, FALSE otherwise. - * - */ - -BOOLEAN _db_keyword_(CODE_STATE *cs, const char *keyword, int strict) -{ - BOOLEAN result; - get_code_state_if_not_set_or_return FALSE; - - /* Dirty read, for DBUG_EXECUTE(), DBUG_EXECUTE_IF() ... performance. */ - if (! DEBUGGING) - return FALSE; - - read_lock_stack(cs); - - strict=strict ? INCLUDE : INCLUDE|MATCHED; - result= DoTrace(cs) & DO_TRACE && - InList(cs->stack->keywords, keyword) & strict; - - unlock_stack(cs); - - return result; -} - -/* - * FUNCTION - * - * Indent indent a line to the given indentation level - * - * SYNOPSIS - * - * static VOID Indent(indent) - * int indent; - * - * DESCRIPTION - * - * Indent a line to the given level. Note that this is - * a simple minded but portable implementation. - * There are better ways. - * - * Also, the indent must be scaled by the compile time option - * of character positions per nesting level. - * - */ - -static void Indent(CODE_STATE *cs, int indent) -{ - int count; - - indent= MAX(indent-1-cs->stack->sub_level,0)*INDENT; - for (count= 0; count < indent ; count++) - { - if ((count % INDENT) == 0) - fputc('|',cs->stack->out_file); - else - fputc(' ',cs->stack->out_file); - } -} - - -/* - * FUNCTION - * - * FreeList free all memory associated with a linked list - * - * SYNOPSIS - * - * static VOID FreeList(linkp) - * struct link *linkp; - * - * DESCRIPTION - * - * Given pointer to the head of a linked list, frees all - * memory held by the list and the members of the list. - * - */ - -static void FreeList(struct link *linkp) -{ - struct link *old; - - while (linkp != NULL) - { - old= linkp; - linkp= linkp->next_link; - free((void*) old); - } -} - - -/* - * FUNCTION - * - * DoPrefix print debugger line prefix prior to indentation - * - * SYNOPSIS - * - * static VOID DoPrefix(_line_) - * int _line_; - * - * DESCRIPTION - * - * Print prefix common to all debugger output lines, prior to - * doing indentation if necessary. Print such information as - * current process name, current source file name and line number, - * and current function nesting depth. - * - */ - -static void DoPrefix(CODE_STATE *cs, uint _line_) -{ - cs->lineno++; - if (cs->stack->flags & PID_ON) - { - (void) fprintf(cs->stack->out_file, "%-7s: ", my_thread_name()); - } - if (cs->stack->flags & NUMBER_ON) - (void) fprintf(cs->stack->out_file, "%5d: ", cs->lineno); - if (cs->stack->flags & TIMESTAMP_ON) - { -#ifdef _WIN32 - /* FIXME This doesn't give microseconds as in Unix case, and the resolution is - in system ticks, 10 ms intervals. See my_getsystime.c for high res */ - SYSTEMTIME loc_t; - GetLocalTime(&loc_t); - (void) fprintf (cs->stack->out_file, - /* "%04d-%02d-%02d " */ - "%02d:%02d:%02d.%06d ", - /*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/ - loc_t.wHour, loc_t.wMinute, loc_t.wSecond, loc_t.wMilliseconds); -#else - struct timeval tv; - struct tm *tm_p; - if (gettimeofday(&tv, NULL) != -1) - { - if ((tm_p= localtime((const time_t *)&tv.tv_sec))) - { - (void) fprintf (cs->stack->out_file, - /* "%04d-%02d-%02d " */ - "%02d:%02d:%02d.%06d ", - /*tm_p->tm_year + 1900, tm_p->tm_mon + 1, tm_p->tm_mday,*/ - tm_p->tm_hour, tm_p->tm_min, tm_p->tm_sec, - (int) (tv.tv_usec)); - } - } -#endif - } - if (cs->stack->flags & PROCESS_ON) - (void) fprintf(cs->stack->out_file, "%s: ", cs->process); - if (cs->stack->flags & FILE_ON) - (void) fprintf(cs->stack->out_file, "%14s: ", BaseName(cs->file)); - if (cs->stack->flags & LINE_ON) - (void) fprintf(cs->stack->out_file, "%5d: ", _line_); - if (cs->stack->flags & DEPTH_ON) - (void) fprintf(cs->stack->out_file, "%4d: ", cs->level); -} - - -/* - * FUNCTION - * - * DBUGOpenFile open new output stream for debugger output - * - * SYNOPSIS - * - * static VOID DBUGOpenFile(name) - * char *name; - * - * DESCRIPTION - * - * Given name of a new file (or "-" for stdout) opens the file - * and sets the output stream to the new file. - * - */ - -static void DBUGOpenFile(CODE_STATE *cs, - const char *name,const char *end,int append) -{ - FILE *fp; - - if (name != NULL) - { - if (end) - { - size_t len=end-name; - memcpy(cs->stack->name, name, len); - cs->stack->name[len]=0; - } - else - strmov(cs->stack->name,name); - name=cs->stack->name; - if (strcmp(name, "-") == 0) - { - cs->stack->out_file= stdout; - cs->stack->flags |= FLUSH_ON_WRITE; - cs->stack->name[0]=0; - } - else - { - if (!Writable(name)) - { - (void) fprintf(stderr, ERR_OPEN, cs->process, name); - perror(""); - fflush(stderr); - } - else - { -#ifdef _WIN32 - if (fopen_s(&fp, name, append ? "a+" : "w")) -#else - if (!(fp= fopen(name, append ? "a+" : "w"))) -#endif - { - (void) fprintf(stderr, ERR_OPEN, cs->process, name); - perror(""); - fflush(stderr); - } - else - { - cs->stack->out_file= fp; - } - } - } - } -} - -/* - * FUNCTION - * - * DBUGCloseFile close the debug output stream - * - * SYNOPSIS - * - * static VOID DBUGCloseFile(fp) - * FILE *fp; - * - * DESCRIPTION - * - * Closes the debug output stream unless it is standard output - * or standard error. - * - */ - -static void DBUGCloseFile(CODE_STATE *cs, FILE *fp) -{ - if (fp != NULL && fp != stderr && fp != stdout && fclose(fp) == EOF) - { - pthread_mutex_lock(&THR_LOCK_dbug); - (void) fprintf(cs->stack->out_file, ERR_CLOSE, cs->process); - perror(""); - DbugFlush(cs); - } -} - - -/* - * FUNCTION - * - * DbugExit print error message and exit - * - * SYNOPSIS - * - * static VOID DbugExit(why) - * char *why; - * - * DESCRIPTION - * - * Prints error message using current process name, the reason for - * aborting (typically out of memory), and exits with status 1. - * This should probably be changed to use a status code - * defined in the user's debugger include file. - * - */ - -static void DbugExit(const char *why) -{ - CODE_STATE *cs=code_state(); - (void) fprintf(stderr, ERR_ABORT, cs ? cs->process : "(null)", why); - (void) fflush(stderr); - DBUG_ABORT(); -} - - -/* - * FUNCTION - * - * DbugMalloc allocate memory for debugger runtime support - * - * SYNOPSIS - * - * static long *DbugMalloc(size) - * int size; - * - * DESCRIPTION - * - * Allocate more memory for debugger runtime support functions. - * Failure to to allocate the requested number of bytes is - * immediately fatal to the current process. This may be - * rather unfriendly behavior. It might be better to simply - * print a warning message, freeze the current debugger cs, - * and continue execution. - * - */ - -static char *DbugMalloc(size_t size) -{ - char *new_malloc; - - if (!(new_malloc= (char*) malloc(size))) - DbugExit("out of memory"); - return new_malloc; -} - - -/* - * strtok lookalike - splits on ':', magically handles ::, :\ and :/ - */ - -static const char *DbugStrTok(const char *s) -{ - while (s[0] && (s[0] != ':' || - (s[1] == '\\' || s[1] == '/' || (s[1] == ':' && s++)))) - s++; - return s; -} - - -/* - * FUNCTION - * - * BaseName strip leading pathname components from name - * - * SYNOPSIS - * - * static char *BaseName(pathname) - * char *pathname; - * - * DESCRIPTION - * - * Given pointer to a complete pathname, locates the base file - * name at the end of the pathname and returns a pointer to - * it. - * - */ - -static const char *BaseName(const char *pathname) -{ - const char *base; - - base= strrchr(pathname, FN_LIBCHAR); - if (base++ == NullS) - base= pathname; - return base; -} - - -/* - * FUNCTION - * - * Writable test to see if a pathname is writable/creatable - * - * SYNOPSIS - * - * static BOOLEAN Writable(pathname) - * char *pathname; - * - * DESCRIPTION - * - * Because the debugger might be linked in with a program that - * runs with the set-uid-bit (suid) set, we have to be careful - * about opening a user named file for debug output. This consists - * of checking the file for write access with the real user id, - * or checking the directory where the file will be created. - * - * Returns TRUE if the user would normally be allowed write or - * create access to the named file. Returns FALSE otherwise. - * - */ - - -#ifndef Writable - -static BOOLEAN Writable(const char *pathname) -{ - BOOLEAN granted; - char *lastslash; - - granted= FALSE; - if (EXISTS(pathname)) - { - if (WRITABLE(pathname)) - granted= TRUE; - } - else - { - lastslash= strrchr(pathname, '/'); - if (lastslash != NULL) - *lastslash= '\0'; - else - pathname= "."; - if (WRITABLE(pathname)) - granted= TRUE; - if (lastslash != NULL) - *lastslash= '/'; - } - return granted; -} -#endif - - -/* - * FUNCTION - * - * _db_setjmp_ save debugger environment - * - * SYNOPSIS - * - * VOID _db_setjmp_() - * - * DESCRIPTION - * - * Invoked as part of the user's DBUG_SETJMP macro to save - * the debugger environment in parallel with saving the user's - * environment. - * - */ - -#ifdef HAVE_LONGJMP - -EXPORT void _db_setjmp_() -{ - CODE_STATE *cs; - get_code_state_or_return; - - cs->jmplevel= cs->level; - cs->jmpfunc= cs->func; - cs->jmpfile= cs->file; -} - -/* - * FUNCTION - * - * _db_longjmp_ restore previously saved debugger environment - * - * SYNOPSIS - * - * VOID _db_longjmp_() - * - * DESCRIPTION - * - * Invoked as part of the user's DBUG_LONGJMP macro to restore - * the debugger environment in parallel with restoring the user's - * previously saved environment. - * - */ - -EXPORT void _db_longjmp_() -{ - CODE_STATE *cs; - get_code_state_or_return; - - cs->level= cs->jmplevel; - if (cs->jmpfunc) - cs->func= cs->jmpfunc; - if (cs->jmpfile) - cs->file= cs->jmpfile; -} -#endif - -/* - * FUNCTION - * - * perror perror simulation for systems that don't have it - * - * SYNOPSIS - * - * static VOID perror(s) - * char *s; - * - * DESCRIPTION - * - * Perror produces a message on the standard error stream which - * provides more information about the library or system error - * just encountered. The argument string s is printed, followed - * by a ':', a blank, and then a message and a newline. - * - * An undocumented feature of the unix perror is that if the string - * 's' is a null string (NOT a NULL pointer!), then the ':' and - * blank are not printed. - * - * This version just complains about an "unknown system error". - * - */ - -#ifndef HAVE_PERROR -static void perror(s) -char *s; -{ - if (s && *s != '\0') - (void) fprintf(stderr, "%s: ", s); - (void) fprintf(stderr, "\n"); -} -#endif /* HAVE_PERROR */ - - - /* flush dbug-stream, free mutex lock & wait delay */ - /* This is because some systems (MSDOS!!) dosn't flush fileheader */ - /* and dbug-file isn't readable after a system crash !! */ - -static void DbugFlush(CODE_STATE *cs) -{ - if (cs->stack->flags & FLUSH_ON_WRITE) - { - (void) fflush(cs->stack->out_file); - if (cs->stack->delay) - (void) Delay(cs->stack->delay); - } - if (!cs->locked) - pthread_mutex_unlock(&THR_LOCK_dbug); -} /* DbugFlush */ - - -/* For debugging */ - -void _db_flush_() -{ - CODE_STATE *cs= NULL; - get_code_state_or_return; - (void) fflush(cs->stack->out_file); -} - - -#ifndef _WIN32 - -#ifdef HAVE_GCOV -extern void __gcov_flush(); -#endif - -void _db_flush_gcov_() -{ -#ifdef HAVE_GCOV - // Gcov will assert() if we try to flush in parallel. - pthread_mutex_lock(&THR_LOCK_gcov); - __gcov_flush(); - pthread_mutex_unlock(&THR_LOCK_gcov); -#endif -} - -void _db_suicide_() -{ - int retval; - sigset_t new_mask; - sigfillset(&new_mask); - -#ifdef HAVE_GCOV - fprintf(stderr, "Flushing gcov data\n"); - fflush(stderr); - _db_flush_gcov_(); -#endif - - fprintf(stderr, "SIGKILL myself\n"); - fflush(stderr); - - retval= kill(getpid(), SIGKILL); - assert(retval == 0); - retval= sigsuspend(&new_mask); - fprintf(stderr, "sigsuspend returned %d errno %d \n", retval, errno); - assert(FALSE); /* With full signal mask, we should never return here. */ -} -#endif /* ! _WIN32 */ - - -void _db_lock_file_() -{ - CODE_STATE *cs; - get_code_state_or_return; - pthread_mutex_lock(&THR_LOCK_dbug); - cs->locked=1; -} - -void _db_unlock_file_() -{ - CODE_STATE *cs; - get_code_state_or_return; - cs->locked=0; - pthread_mutex_unlock(&THR_LOCK_dbug); -} - -const char* _db_get_func_(void) -{ - CODE_STATE *cs; - get_code_state_or_return NULL; - return cs->func; -} - - -#else - -/* - * Dummy function, workaround for MySQL bug#14420 related - * build failure on a platform where linking with an empty - * archive fails. - * - * This block can be removed as soon as a fix for bug#14420 - * is implemented. - */ -int i_am_a_dummy_function() { - return 0; -} - -#endif diff --git a/libmariadb/default.c b/libmariadb/default.c deleted file mode 100644 index 20fa4cf3..00000000 --- a/libmariadb/default.c +++ /dev/null @@ -1,442 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/**************************************************************************** -** Add all options from files named "group".cnf from the default_directories -** before the command line arguments. -** On Windows defaults will also search in the Windows directory for a file -** called 'group'.ini -** As long as the program uses the last argument for conflicting -** options one only have to add a call to "load_defaults" to enable -** use of default values. -** pre- and end 'blank space' are removed from options and values. The -** following escape sequences are recognized in values: \b \t \n \r \\ -** -** The following arguments are handled automaticly; If used, they must be -** first argument on the command line! -** --no-defaults ; no options are read. -** --defaults-file=full-path-to-default-file ; Only this file will be read. -** --defaults-extra-file=full-path-to-default-file ; Read this file before ~/ -** --print-defaults ; Print the modified command line and exit -****************************************************************************/ - -#undef SAFEMALLOC /* safe_malloc is not yet initailized */ - -#include "mysys_priv.h" -#include "m_string.h" -#include -#include "m_ctype.h" -#include -#include -#include - -char *defaults_extra_file=0; - -/* Which directories are searched for options (and in which order) */ - -const char *default_directories[]= { -#ifdef _WIN32 -"C:/", -#else -"/etc/", -#endif -#ifdef DATADIR -DATADIR, -#endif -"", /* Place for defaults_extra_dir */ -#ifndef _WIN32 -"~/", -#endif -NullS, -}; - -#define default_ext ".cnf" /* extension for config file */ -#ifdef _WIN32 -#include -#define windows_ext ".ini" -#endif - -static my_bool search_default_file(DYNAMIC_ARRAY *args,MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group); - - -void load_defaults(const char *conf_file, const char **groups, - int *argc, char ***argv) -{ - DYNAMIC_ARRAY args; - const char **dirs, *forced_default_file; - TYPELIB group; - my_bool found_print_defaults=0; - uint args_used=0; - MEM_ROOT alloc; - char *ptr,**res; - DBUG_ENTER("load_defaults"); - - init_alloc_root(&alloc,128,0); - if (*argc >= 2 && !strcmp(argv[0][1],"--no-defaults")) - { - /* remove the --no-defaults argument and return only the other arguments */ - uint i; - if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ - (*argc + 1)*sizeof(char*)))) - goto err; - res= (char**) (ptr+sizeof(alloc)); - res[0]= **argv; /* Copy program name */ - for (i=2 ; i < (uint) *argc ; i++) - res[i-1]=argv[0][i]; - (*argc)--; - *argv=res; - *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ - DBUG_VOID_RETURN; - } - - /* Check if we want to force the use a specific default file */ - forced_default_file=0; - if (*argc >= 2) - { - if (is_prefix(argv[0][1],"--defaults-file=")) - { - forced_default_file=strchr(argv[0][1],'=')+1; - args_used++; - } - else if (is_prefix(argv[0][1],"--defaults-extra-file=")) - { - defaults_extra_file=strchr(argv[0][1],'=')+1; - args_used++; - } - } - - group.count=0; - group.name= "defaults"; - group.type_names= groups; - for (; *groups ; groups++) - group.count++; - - if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32)) - goto err; - if (forced_default_file) - { - if (search_default_file(&args, &alloc, "", forced_default_file, "", - &group)) - goto err; - } - else if (dirname_length(conf_file)) - { - if (search_default_file(&args, &alloc, NullS, conf_file, default_ext, - &group)) - goto err; - } - else - { -#ifdef _WIN32 - char system_dir[FN_REFLEN]; - GetWindowsDirectory(system_dir,sizeof(system_dir)); - if (search_default_file(&args, &alloc, system_dir, conf_file, windows_ext, - &group)) - goto err; -#endif -#if defined(__EMX__) || defined(OS2) - if (getenv("ETC") && - search_default_file(&args, &alloc, getenv("ETC"), conf_file, - default_ext, &group)) - goto err; -#endif - for (dirs=default_directories ; *dirs; dirs++) - { - int error=0; - if (**dirs) - error=search_default_file(&args, &alloc, *dirs, conf_file, - default_ext, &group); - else if (defaults_extra_file) - error=search_default_file(&args, &alloc, NullS, defaults_extra_file, - default_ext, &group); - if (error) - goto err; - } - } - if (!(ptr=(char*) alloc_root(&alloc,sizeof(alloc)+ - (args.elements + *argc +1) *sizeof(char*)))) - goto err; - res= (char**) (ptr+sizeof(alloc)); - - /* copy name + found arguments + command line arguments to new array */ - res[0]=argv[0][0]; - memcpy((gptr) (res+1), args.buffer, args.elements*sizeof(char*)); - /* Skipp --defaults-file and --defaults-extra-file */ - (*argc)-= args_used; - (*argv)+= args_used; - - /* Check if we wan't to see the new argument list */ - if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults")) - { - found_print_defaults=1; - --*argc; ++*argv; /* skipp argument */ - } - - memcpy((gptr) (res+1+args.elements), (char*) ((*argv)+1), - (*argc-1)*sizeof(char*)); - res[args.elements+ *argc]=0; /* last null */ - - (*argc)+=args.elements; - *argv= (char**) res; - *(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */ - delete_dynamic(&args); - if (found_print_defaults) - { - int i; - printf("%s would have been started with the following arguments:\n", - **argv); - for (i=1 ; i < *argc ; i++) - printf("%s ", (*argv)[i]); - puts(""); - exit(1); - } - DBUG_VOID_RETURN; - - err: - fprintf(stderr,"Program aborted\n"); - exit(1); -} - - -void free_defaults(char **argv) -{ - MEM_ROOT ptr; - memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr)); - free_root(&ptr,MYF(0)); -} - - -static my_bool search_default_file(DYNAMIC_ARRAY *args, MEM_ROOT *alloc, - const char *dir, const char *config_file, - const char *ext, TYPELIB *group) -{ - char name[FN_REFLEN+10],buff[4096],*ptr,*end,*value,*tmp; - MA_FILE *file; - uint line=0; - my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; - - if (!strstr(config_file, "://")) - { - if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3) - return 0; /* Ignore wrong paths */ - if (dir) - { - strmov(name,dir); - convert_dirname(name); - if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */ - strcat(name,"."); - strxmov(strend(name),config_file,ext,NullS); - } - else - { - strmov(name,config_file); - } - fn_format(name,name,"","",4); -#if !defined(_WIN32) && !defined(OS2) - { - MY_STAT stat_info; - if (!my_stat(name,&stat_info,MYF(0))) - return 0; - if (stat_info.st_mode & S_IWOTH) /* ignore world-writeable files */ - { - fprintf(stderr, "warning: World-writeable config file %s is ignored\n", - name); - return 0; - } - } -#endif - if (!(file = ma_open(fn_format(name,name,"","",4),"r", NULL))) - return 0; - } - else { - if (!(file = ma_open(config_file, "r", NULL))) - return 0; - } - - while (ma_gets(buff,sizeof(buff)-1,file)) - { - line++; - /* Ignore comment and empty lines */ - for (ptr=buff ; isspace(*ptr) ; ptr++ ); - if (!is_escaped && (*ptr == '\"' || *ptr== '\'')) - { - is_quoted= !is_quoted; - continue; - } - if (*ptr == '#' || *ptr == ';' || !*ptr) - continue; - is_escaped= (*ptr == '\\'); - if (*ptr == '[') /* Group name */ - { - found_group=1; - if (!(end=(char *) strchr(++ptr,']'))) - { - fprintf(stderr, - "error: Wrong group definition in config file: %s at line %d\n", - name,line); - goto err; - } - for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ - end[0]=0; - read_values=find_type(ptr,group,3) > 0; - continue; - } - if (!found_group) - { - fprintf(stderr, - "error: Found option without preceding group in config file: %s at line: %d\n", - name,line); - goto err; - } - if (!read_values) - continue; - if (!(end=value=strchr(ptr,'='))) - end=strend(ptr); /* Option without argument */ - for ( ; isspace(end[-1]) ; end--) ; - if (!value) - { - if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3))) - goto err; - strmake(strmov(tmp,"--"),ptr,(uint) (end-ptr)); - if (insert_dynamic(args,(gptr) &tmp)) - goto err; - } - else - { - /* Remove pre- and end space */ - char *value_end; - for (value++ ; isspace(*value); value++) ; - value_end=strend(value); - for ( ; isspace(value_end[-1]) ; value_end--) ; - /* remove possible quotes */ - if (*value == '\'' || *value == '\"') - { - value++; - if (value_end[-1] == '\'' || value_end[-1] == '\"') - value_end--; - } - if (value_end < value) /* Empty string */ - value_end=value; - if (!(tmp=alloc_root(alloc,(uint) (end-ptr)+3 + - (uint) (value_end-value)+1))) - goto err; - if (insert_dynamic(args,(gptr) &tmp)) - goto err; - ptr=strnmov(strmov(tmp,"--"),ptr,(uint) (end-ptr)); - *ptr++= '='; - for ( ; value != value_end; value++) - { - if (*value == '\\' && value != value_end-1) - { - switch(*++value) { - case 'n': - *ptr++='\n'; - break; - case 't': - *ptr++= '\t'; - break; - case 'r': - *ptr++ = '\r'; - break; - case 'b': - *ptr++ = '\b'; - break; - case 's': - *ptr++= ' '; /* space */ - break; - case '\"': - *ptr++= '\"'; - break; - case '\'': - *ptr++= '\''; - break; - case '\\': - *ptr++= '\\'; - break; - default: /* Unknown; Keep '\' */ - *ptr++= '\\'; - *ptr++= *value; - break; - } - } - else - *ptr++= *value; - } - *ptr=0; - } - } - ma_close(file); - return(0); - - err: - ma_close(file); - return 1; -} - - -void print_defaults(const char *conf_file, const char **groups) -{ -#ifdef _WIN32 - bool have_ext=fn_ext(conf_file)[0] != 0; -#endif - char name[FN_REFLEN]; - const char **dirs; - puts("\nDefault options are read from the following files in the given order:"); - - if (dirname_length(conf_file)) - fputs(conf_file,stdout); - else - { -#ifdef _WIN32 - GetWindowsDirectory(name,sizeof(name)); - printf("%s\\%s%s ",name,conf_file,have_ext ? "" : windows_ext); -#endif -#if defined(__EMX__) || defined(OS2) - if (getenv("ETC")) - printf("%s\\%s%s ", getenv("ETC"), conf_file, default_ext); -#endif - for (dirs=default_directories ; *dirs; dirs++) - { - if (**dirs) - strmov(name,*dirs); - else if (defaults_extra_file) - strmov(name,defaults_extra_file); - else - continue; - convert_dirname(name); - if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ - strcat(name,"."); - strxmov(strend(name),conf_file,default_ext," ",NullS); - fputs(name,stdout); - } - puts(""); - } - fputs("The following groups are read:",stdout); - for ( ; *groups ; groups++) - { - fputc(' ',stdout); - fputs(*groups,stdout); - } - puts("\nThe following options may be given as the first argument:\n\ ---print-defaults Print the program argument list and exit\n\ ---no-defaults Don't read default options from any options file\n\ ---defaults-file=# Only read default options from the given file #\n\ ---defaults-extra-file=# Read this file after the global files are read"); -} - diff --git a/libmariadb/errors.c b/libmariadb/errors.c deleted file mode 100644 index 393f628b..00000000 --- a/libmariadb/errors.c +++ /dev/null @@ -1,96 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" - -#ifndef SHARED_LIBRARY - -const char * NEAR globerrs[GLOBERRS]= -{ - "Can't create/write to file '%s' (Errcode: %d)", - "Error reading file '%s' (Errcode: %d)", - "Error writing file '%s' (Errcode: %d)", - "Error on close of '%s' (Errcode: %d)", - "Out of memory (Needed %u bytes)", - "Error on delete of '%s' (Errcode: %d)", - "Error on rename of '%s' to '%s' (Errcode: %d)", - "", - "Unexpected eof found when reading file '%s' (Errcode: %d)", - "Can't lock file (Errcode: %d)", - "Can't unlock file (Errcode: %d)", - "Can't read dir of '%s' (Errcode: %d)", - "Can't get stat of '%s' (Errcode: %d)", - "Can't change size of file (Errcode: %d)", - "Can't open stream from handle (Errcode: %d)", - "Can't get working dirctory (Errcode: %d)", - "Can't change dir to '%s' (Errcode: %d)", - "Warning: '%s' had %d links", - "Warning: %d files and %d streams is left open\n", - "Disk is full writing '%s' (Errcode: %d). Waiting for someone to free space... (Expect up to %d secs delay for server to continue after freeing disk space)", - "Can't create directory '%s' (Errcode: %d)", - "Character set '%s' is not a compiled character set and is not specified in the '%s' file", - "Out of resources when opening file '%s' (Errcode: %d)", - "Can't read value for symlink '%s' (Error %d)", - "Can't create symlink '%s' pointing at '%s' (Error %d)", - "Error on realpath() on '%s' (Error %d)", - "Can't sync file '%s' to disk (Errcode: %d)", - "Collation '%s' is not a compiled collation and is not specified in the '%s' file", - "File '%s' not found (Errcode: %d)", - "File '%s' (fileno: %d) was not closed", - "Can't change mode for file '%s' to 0x%lx (Error: %d)" -}; - -void init_glob_errs(void) -{ - my_errmsg[GLOB] = & globerrs[0]; -} /* init_glob_errs */ - -#else - -void init_glob_errs() -{ - my_errmsg[GLOB] = & globerrs[0]; - - EE(EE_FILENOTFOUND) = "File '%s' not found (Errcode: %d)"; - EE(EE_CANTCREATEFILE) = "Can't create/write to file '%s' (Errcode: %d)"; - EE(EE_READ) = "Error reading file '%s' (Errcode: %d)"; - EE(EE_WRITE) = "Error writing file '%s' (Errcode: %d)"; - EE(EE_BADCLOSE) = "Error on close of '%'s (Errcode: %d)"; - EE(EE_OUTOFMEMORY) = "Out of memory (Needed %u bytes)"; - EE(EE_DELETE) = "Error on delete of '%s' (Errcode: %d)"; - EE(EE_LINK) = "Error on rename of '%s' to '%s' (Errcode: %d)"; - EE(EE_EOFERR) = "Unexpected eof found when reading file '%s' (Errcode: %d)"; - EE(EE_CANTLOCK) = "Can't lock file (Errcode: %d)"; - EE(EE_CANTUNLOCK) = "Can't unlock file (Errcode: %d)"; - EE(EE_DIR) = "Can't read dir of '%s' (Errcode: %d)"; - EE(EE_STAT) = "Can't get stat of '%s' (Errcode: %d)"; - EE(EE_CANT_CHSIZE) = "Can't change size of file (Errcode: %d)"; - EE(EE_CANT_OPEN_STREAM)= "Can't open stream from handle (Errcode: %d)"; - EE(EE_GETWD) = "Can't get working dirctory (Errcode: %d)"; - EE(EE_SETWD) = "Can't change dir to '%s' (Errcode: %d)"; - EE(EE_LINK_WARNING) = "Warning: '%s' had %d links"; - EE(EE_OPEN_WARNING) = "%d files and %d streams is left open\n"; - EE(EE_DISK_FULL) = "Disk is full writing '%s'. Waiting for someone to free space..."; - EE(EE_CANT_MKDIR) ="Can't create directory '%s' (Errcode: %d)"; - EE(EE_UNKNOWN_CHARSET)= "Character set is not a compiled character set and is not specified in the %s file"; - EE(EE_OUT_OF_FILERESOURCES)="Out of resources when opening file '%s' (Errcode: %d)"; - EE(EE_CANT_READLINK)="Can't read value for symlink '%s' (Error %d)"; - EE(EE_CANT_SYMLINK)="Can't create symlink '%s' pointing at '%s' (Error %d)"; - EE(EE_REALPATH)="Error on realpath() on '%s' (Error %d)"; -} -#endif diff --git a/libmariadb/get_password.c b/libmariadb/get_password.c index 2eafb7a8..230a38de 100644 --- a/libmariadb/get_password.c +++ b/libmariadb/get_password.c @@ -16,11 +16,11 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include -#include +#include +#include #include "mysql.h" -#include -#include +#include +#include #include #include diff --git a/libmariadb/getopt1.c b/libmariadb/getopt1.c deleted file mode 100644 index d89f7bcc..00000000 --- a/libmariadb/getopt1.c +++ /dev/null @@ -1,170 +0,0 @@ -/* getopt_long and getopt_long_only entry points for GNU getopt. - Copyright (C) 1987, 88, 89, 90, 91, 92, 1993, 1994 - Free Software Foundation, Inc. - -This file is part of the GNU C Library. Its master source is NOT part of -the C library, however. The master source lives in /gd/gnu/lib. - -The GNU C Library is free software; you can redistribute it and/or -modify it under the terms of the GNU Library General Public License as -published by the Free Software Foundation; either version 2 of the -License, or (at your option) any later version. - -The GNU C Library is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -Library General Public License for more details. - -You should have received a copy of the GNU Library General Public -License along with the GNU C Library; see the file COPYING.LIB. If -not, write to the Free Software Foundation, Inc., 675 Mass Ave, -Cambridge, MA 02139, USA. */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include "getopt.h" - -#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) -/* This is a separate conditional since some stdc systems - reject `defined (const)'. */ -#ifndef const -#define const -#endif -#endif - -#include - -/* Comment out all this code if we are using the GNU C Library, and are not - actually compiling the library itself. This code is part of the GNU C - Library, but also included in many other GNU distributions. Compiling - and linking in this code is a waste when using the GNU C library - (especially if it is a shared library). Rather than having every GNU - program understand `configure --with-gnu-libc' and omit the object files, - it is simpler to just do this in the source for each such file. */ - -#if defined (_LIBC) || !defined (__GNU_LIBRARY__) - -#ifndef _WIN32 -#include -#endif /* _WIN32 */ - -#ifndef NULL -#define NULL 0 -#endif - -int -getopt_long (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 0); -} - -/* Like getopt_long, but '-' as well as '--' can indicate a long option. - If an option that starts with '-' (not '--') doesn't match a long option, - but does match a short option, it is parsed as a short option - instead. */ - -int -getopt_long_only (int argc, char *const *argv, const char *options, const struct option *long_options, int *opt_index) -{ - return _getopt_internal (argc, argv, options, long_options, opt_index, 1); -} - - -#endif /* _LIBC or not __GNU_LIBRARY__. */ - -#ifdef TEST - -#include - -int -main (argc, argv) - int argc; - char **argv; -{ - int c; - int digit_optind = 0; - - while (1) - { - int this_option_optind = optind ? optind : 1; - int option_index = 0; - static struct option long_options[] = - { - {"add", 1, 0, 0}, - {"append", 0, 0, 0}, - {"delete", 1, 0, 0}, - {"verbose", 0, 0, 0}, - {"create", 0, 0, 0}, - {"file", 1, 0, 0}, - {0, 0, 0, 0} - }; - - c = getopt_long (argc, argv, "abc:d:0123456789", - long_options, &option_index); - if (c == EOF) - break; - - switch (c) - { - case 0: - printf ("option %s", long_options[option_index].name); - if (optarg) - printf (" with arg %s", optarg); - printf ("\n"); - break; - - case '0': - case '1': - case '2': - case '3': - case '4': - case '5': - case '6': - case '7': - case '8': - case '9': - if (digit_optind != 0 && digit_optind != this_option_optind) - printf ("digits occur in two different argv-elements.\n"); - digit_optind = this_option_optind; - printf ("option %c\n", c); - break; - - case 'a': - printf ("option a\n"); - break; - - case 'b': - printf ("option b\n"); - break; - - case 'c': - printf ("option c with value `%s'\n", optarg); - break; - - case 'd': - printf ("option d with value `%s'\n", optarg); - break; - - case '?': - break; - - default: - printf ("?? getopt returned character code 0%o ??\n", c); - } - } - - if (optind < argc) - { - printf ("non-option ARGV-elements: "); - while (optind < argc) - printf ("%s ", argv[optind++]); - printf ("\n"); - } - - exit (0); -} - -#endif /* TEST */ diff --git a/libmariadb/int2str.c b/libmariadb/int2str.c deleted file mode 100644 index 17bcb3fc..00000000 --- a/libmariadb/int2str.c +++ /dev/null @@ -1,153 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: int2str(), itoa(), ltoa() - - int2str(dst, radix, val) - converts the (long) integer "val" to character form and moves it to - the destination string "dst" followed by a terminating NUL. The - result is normally a pointer to this NUL character, but if the radix - is dud the result will be NullS and nothing will be changed. - - If radix is -2..-36, val is taken to be SIGNED. - If radix is 2.. 36, val is taken to be UNSIGNED. - That is, val is signed if and only if radix is. You will normally - use radix -10 only through itoa and ltoa, for radix 2, 8, or 16 - unsigned is what you generally want. - - _dig_vec is public just in case someone has a use for it. - The definitions of itoa and ltoa are actually macros in m_string.h, - but this is where the code is. - - Note: The standard itoa() returns a pointer to the argument, when int2str - returns the pointer to the end-null. - itoa assumes that 10 -base numbers are allways signed and other arn't. -*/ - -#include -#include "m_string.h" - -char NEAR _dig_vec[] = - "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; - - -char *int2str(register long int val, register char *dst, register int radix) -{ - char buffer[65]; - register char *p; - long int new_val; - - if (radix < 0) { - if (radix < -36 || radix > -2) return NullS; - if (val < 0) { - *dst++ = '-'; - val = -val; - } - radix = -radix; - } else { - if (radix > 36 || radix < 2) return NullS; - } - /* The slightly contorted code which follows is due to the - fact that few machines directly support unsigned long / and %. - Certainly the VAX C compiler generates a subroutine call. In - the interests of efficiency (hollow laugh) I let this happen - for the first digit only; after that "val" will be in range so - that signed integer division will do. Sorry 'bout that. - CHECK THE CODE PRODUCED BY YOUR C COMPILER. The first % and / - should be unsigned, the second % and / signed, but C compilers - tend to be extraordinarily sensitive to minor details of style. - This works on a VAX, that's all I claim for it. - */ - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - new_val=(ulong) val / (ulong) radix; - *--p = _dig_vec[(uchar) ((ulong) val- (ulong) new_val*(ulong) radix)]; - val = new_val; -#ifdef HAVE_LDIV - while (val != 0) - { - ldiv_t res; - res=ldiv(val,radix); - *--p = _dig_vec[res.rem]; - val= res.quot; - } -#else - while (val != 0) - { - new_val=val/radix; - *--p = _dig_vec[(uchar) (val-new_val*radix)]; - val= new_val; - } -#endif - while ((*dst++ = *p++) != 0) ; - return dst-1; -} - - -/* - This is a faster version of the above optimized for the normal case of - radix 10 / -10 -*/ - -char *int10_to_str(long int val, char *dst, int radix) -{ - char buffer[65]; - register char *p; - long int new_val; - unsigned long int uval= (unsigned long int)val; - - if (radix < 0 && val < 0) /* -10 */ - { - *dst++ = '-'; - uval = (unsigned long int)0-uval; - } - - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - new_val= (long)(uval / 10); - *--p = '0'+ (char)(uval - (unsigned long)new_val * 10); - val = new_val; - - while (val != 0) - { - new_val=val/10; - *--p = '0' + (char) (val-new_val*10); - val= new_val; - } - while ((*dst++ = *p++) != 0) ; - return dst-1; -} - - -#ifdef USE_MY_ITOA - - /* Change to less general itoa interface */ - -char *my_itoa(int val, char *dst, int radix) -{ - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -char *my_ltoa(long int val, char *dst, int radix) -{ - VOID(int2str((long) val,dst,(radix == 10 ? -10 : radix))); - return dst; -} - -#endif diff --git a/libmariadb/is_prefix.c b/libmariadb/is_prefix.c deleted file mode 100644 index 5fb29f87..00000000 --- a/libmariadb/is_prefix.c +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : is_prefix.c - Author : Michael Widenius - Defines: is_prefix() - - is_prefix(s, t) returns 1 if s starts with t. - A empty t is allways a prefix. -*/ - -#include -#include "m_string.h" - -int is_prefix(register const char *s, register const char *t) -{ - while (*t) - if (*s++ != *t++) return 0; - return 1; /* WRONG */ -} diff --git a/libmariadb/llstr.c b/libmariadb/llstr.c deleted file mode 100644 index 3e935c69..00000000 --- a/libmariadb/llstr.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: llstr(); - - llstr(value, buff); - - This function saves a longlong value in a buffer and returns the pointer to - the buffer. This is useful when trying to portable print longlong - variables with printf() as there is no usable printf() standard one can use. -*/ - - -#include -#include "m_string.h" - -char *llstr(longlong value,char *buff) -{ - longlong2str(value,buff,-10); - return buff; -} diff --git a/libmariadb/longlong2str.c b/libmariadb/longlong2str.c deleted file mode 100644 index fe4d419a..00000000 --- a/libmariadb/longlong2str.c +++ /dev/null @@ -1,143 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Defines: longlong2str(); - - longlong2str(dst, radix, val) - converts the (longlong) integer "val" to character form and moves it to - the destination string "dst" followed by a terminating NUL. The - result is normally a pointer to this NUL character, but if the radix - is dud the result will be NullS and nothing will be changed. - - If radix is -2..-36, val is taken to be SIGNED. - If radix is 2.. 36, val is taken to be UNSIGNED. - That is, val is signed if and only if radix is. You will normally - use radix -10 only through itoa and ltoa, for radix 2, 8, or 16 - unsigned is what you generally want. - - _dig_vec is public just in case someone has a use for it. - The definitions of itoa and ltoa are actually macros in m_string.h, - but this is where the code is. - - Note: The standard itoa() returns a pointer to the argument, when int2str - returns the pointer to the end-null. - itoa assumes that 10 -base numbers are allways signed and other arn't. -*/ - -#include -#include "m_string.h" - -#if defined(HAVE_LONG_LONG) && !defined(longlong2str) && !defined(HAVE_LONGLONG2STR) - -extern char NEAR _dig_vec[]; - -/* - This assumes that longlong multiplication is faster than longlong division. -*/ - -char *longlong2str(longlong val,char *dst,int radix) -{ - char buffer[65]; - register char *p; - long long_val; - - if (radix < 0) - { - if (radix < -36 || radix > -2) return (char*) 0; - if (val < 0) { - *dst++ = '-'; - val = -val; - } - radix = -radix; - } - else - { - if (radix > 36 || radix < 2) return (char*) 0; - } - if (val == 0) - { - *dst++='0'; - *dst='\0'; - return dst; - } - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - - while ((ulonglong) val > (ulonglong) LONG_MAX) - { - ulonglong quo=(ulonglong) val/(uint) radix; - uint rem= (uint) (val- quo* (uint) radix); - *--p = _dig_vec[rem]; - val= quo; - } - long_val= (long) val; - while (long_val != 0) - { - long quo= long_val/radix; - *--p = _dig_vec[(uchar) (long_val - quo*radix)]; - long_val= quo; - } - while ((*dst++ = *p++) != 0) ; - return dst-1; -} - -#endif - -#ifndef longlong10_to_str -char *longlong10_to_str(longlong val,char *dst,int radix) -{ - char buffer[65]; - register char *p; - long long_val; - - if (radix < 0) - { - if (val < 0) - { - *dst++ = '-'; - val = -val; - } - } - - if (val == 0) - { - *dst++='0'; - *dst='\0'; - return dst; - } - p = &buffer[sizeof(buffer)-1]; - *p = '\0'; - - while ((ulonglong) val > (ulonglong) LONG_MAX) - { - ulonglong quo=(ulonglong) val/(uint) 10; - uint rem= (uint) (val- quo* (uint) 10); - *--p = _dig_vec[rem]; - val= quo; - } - long_val= (long) val; - while (long_val != 0) - { - long quo= long_val/10; - *--p = _dig_vec[(uchar) (long_val - quo*10)]; - long_val= quo; - } - while ((*dst++ = *p++) != 0) ; - return dst-1; -} -#endif diff --git a/libmariadb/my_alloc.c b/libmariadb/ma_alloc.c similarity index 68% rename from libmariadb/my_alloc.c rename to libmariadb/ma_alloc.c index 1434b912..b516179d 100644 --- a/libmariadb/my_alloc.c +++ b/libmariadb/ma_alloc.c @@ -17,24 +17,23 @@ /* Routines to handle mallocing of results which will be freed the same time */ -#include -#include -#include +#include +#include +#include -void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) +void ma_init_ma_alloc_root(MA_MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_size) { mem_root->free=mem_root->used=0; mem_root->min_malloc=32; - mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(USED_MEM)-8; + mem_root->block_size=block_size-MALLOC_OVERHEAD-sizeof(MA_USED_MEM)-8; mem_root->error_handler=0; #if !(defined(HAVE_purify) && defined(EXTRA_DEBUG)) if (pre_alloc_size) { if ((mem_root->free = mem_root->pre_alloc= - (USED_MEM*) my_malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(USED_MEM)), - MYF(0)))) + (MA_USED_MEM*) malloc(pre_alloc_size+ ALIGN_SIZE(sizeof(MA_USED_MEM))))) { - mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(USED_MEM)); + mem_root->free->size=pre_alloc_size+ALIGN_SIZE(sizeof(MA_USED_MEM)); mem_root->free->left=pre_alloc_size; mem_root->free->next=0; } @@ -42,13 +41,13 @@ void init_alloc_root(MEM_ROOT *mem_root, size_t block_size, size_t pre_alloc_siz #endif } -gptr alloc_root(MEM_ROOT *mem_root, size_t Size) +gptr ma_alloc_root(MA_MEM_ROOT *mem_root, size_t Size) { #if defined(HAVE_purify) && defined(EXTRA_DEBUG) - reg1 USED_MEM *next; - Size+=ALIGN_SIZE(sizeof(USED_MEM)); + reg1 MA_USED_MEM *next; + Size+=ALIGN_SIZE(sizeof(MA_USED_MEM)); - if (!(next = (USED_MEM*) my_malloc(Size,MYF(MY_WME)))) + if (!(next = (MA_USED_MEM*) malloc(Size))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -56,12 +55,12 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) } next->next=mem_root->used; mem_root->used=next; - return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(USED_MEM))); + return (gptr) (((char*) next)+ALIGN_SIZE(sizeof(MA_USED_MEM))); #else size_t get_size,max_left; gptr point; - reg1 USED_MEM *next; - reg2 USED_MEM **prev; + reg1 MA_USED_MEM *next; + reg2 MA_USED_MEM **prev; Size= ALIGN_SIZE(Size); prev= &mem_root->free; @@ -74,11 +73,11 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) } if (! next) { /* Time to alloc new block */ - get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); + get_size= Size+ALIGN_SIZE(sizeof(MA_USED_MEM)); if (max_left*4 < mem_root->block_size && get_size < mem_root->block_size) get_size=mem_root->block_size; /* Normal alloc */ - if (!(next = (USED_MEM*) my_malloc(get_size,MYF(MY_WME | MY_ZEROFILL)))) + if (!(next = (MA_USED_MEM*) calloc(1, get_size))) { if (mem_root->error_handler) (*mem_root->error_handler)(); @@ -86,7 +85,7 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) } next->next= *prev; next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); + next->left= get_size-ALIGN_SIZE(sizeof(MA_USED_MEM)); *prev=next; } point= (gptr) ((char*) next+ (next->size-next->left)); @@ -100,15 +99,14 @@ gptr alloc_root(MEM_ROOT *mem_root, size_t Size) #endif } - /* deallocate everything used by alloc_root */ + /* deallocate everything used by ma_alloc_root */ -void free_root(MEM_ROOT *root, myf MyFlags) +void ma_free_root(MA_MEM_ROOT *root, myf MyFlags) { - reg1 USED_MEM *next,*old; - DBUG_ENTER("free_root"); + reg1 MA_USED_MEM *next,*old; if (!root) - DBUG_VOID_RETURN; /* purecov: inspected */ + return; /* purecov: inspected */ if (!(MyFlags & MY_KEEP_PREALLOC)) root->pre_alloc=0; @@ -116,40 +114,40 @@ void free_root(MEM_ROOT *root, myf MyFlags) { old=next; next= next->next ; if (old != root->pre_alloc) - my_free(old); + free(old); } for (next= root->free ; next ; ) { old=next; next= next->next ; if (old != root->pre_alloc) - my_free(old); + free(old); } root->used=root->free=0; if (root->pre_alloc) { root->free=root->pre_alloc; - root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(USED_MEM)); + root->free->left=root->pre_alloc->size-ALIGN_SIZE(sizeof(MA_USED_MEM)); root->free->next=0; } - DBUG_VOID_RETURN; + return; } -char *strdup_root(MEM_ROOT *root,const char *str) +char *ma_strdup_root(MA_MEM_ROOT *root,const char *str) { size_t len= strlen(str)+1; char *pos; - if ((pos=alloc_root(root,len))) + if ((pos=ma_alloc_root(root,len))) memcpy(pos,str,len); pos[len]= 0; return pos; } -char *memdup_root(MEM_ROOT *root, const char *str, size_t len) +char *ma_memdup_root(MA_MEM_ROOT *root, const char *str, size_t len) { char *pos; - if ((pos=alloc_root(root,len))) + if ((pos=ma_alloc_root(root,len))) memcpy(pos,str,len); return pos; } diff --git a/libmariadb/array.c b/libmariadb/ma_array.c similarity index 68% rename from libmariadb/array.c rename to libmariadb/ma_array.c index d52a58c8..56cbbfdd 100644 --- a/libmariadb/array.c +++ b/libmariadb/ma_array.c @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -19,18 +20,19 @@ #undef SAFEMALLOC /* Problems with threads */ -#include "mysys_priv.h" -#include "m_string.h" +#include +#include +#include "ma_string.h" +#include /* Initiate array and alloc space for init_alloc elements. Array is usable even if space allocation failed */ -my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, - uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) +my_bool ma_init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, + uint init_alloc, uint alloc_increment CALLER_INFO_PROTO) { - DBUG_ENTER("init_dynamic_array"); if (!alloc_increment) { alloc_increment=max((8192-MALLOC_OVERHEAD)/element_size,16); @@ -44,21 +46,21 @@ my_bool init_dynamic_array(DYNAMIC_ARRAY *array, uint element_size, array->max_element=init_alloc; array->alloc_increment=alloc_increment; array->size_of_element=element_size; - if (!(array->buffer=(char*) my_malloc_ci(element_size*init_alloc,MYF(MY_WME)))) + if (!(array->buffer=(char*) malloc(element_size*init_alloc))) { array->max_element=0; - DBUG_RETURN(TRUE); + return(TRUE); } - DBUG_RETURN(FALSE); + return(FALSE); } -my_bool insert_dynamic(DYNAMIC_ARRAY *array, gptr element) +my_bool ma_insert_dynamic(DYNAMIC_ARRAY *array, gptr element) { gptr buffer; if (array->elements == array->max_element) { /* Call only when nessesary */ - if (!(buffer=alloc_dynamic(array))) + if (!(buffer=ma_alloc_dynamic(array))) return TRUE; } else @@ -73,15 +75,14 @@ my_bool insert_dynamic(DYNAMIC_ARRAY *array, gptr element) /* Alloc room for one element */ -unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array) +unsigned char *ma_alloc_dynamic(DYNAMIC_ARRAY *array) { if (array->elements == array->max_element) { char *new_ptr; - if (!(new_ptr=(char*) my_realloc(array->buffer,(array->max_element+ - array->alloc_increment)* - array->size_of_element, - MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) + if (!(new_ptr=(char*) realloc(array->buffer,(array->max_element+ + array->alloc_increment)* + array->size_of_element))) return 0; array->buffer=new_ptr; array->max_element+=array->alloc_increment; @@ -92,7 +93,7 @@ unsigned char *alloc_dynamic(DYNAMIC_ARRAY *array) /* remove last element from array and return it */ -unsigned char *pop_dynamic(DYNAMIC_ARRAY *array) +unsigned char *ma_pop_dynamic(DYNAMIC_ARRAY *array) { if (array->elements) return array->buffer+(--array->elements * array->size_of_element); @@ -100,7 +101,7 @@ unsigned char *pop_dynamic(DYNAMIC_ARRAY *array) } -my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) +my_bool ma_set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) { if (idx >= array->elements) { @@ -110,14 +111,13 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) char *new_ptr; size=(idx+array->alloc_increment)/array->alloc_increment; size*= array->alloc_increment; - if (!(new_ptr=(char*) my_realloc(array->buffer,size* - array->size_of_element, - MYF(MY_WME | MY_ALLOW_ZERO_PTR)))) + if (!(new_ptr=(char*) realloc(array->buffer,size* + array->size_of_element))) return TRUE; array->buffer=new_ptr; array->max_element=size; } - bzero((gptr) (array->buffer+array->elements*array->size_of_element), + memset((array->buffer+array->elements*array->size_of_element), 0, (idx - array->elements)*array->size_of_element); array->elements=idx+1; } @@ -127,13 +127,11 @@ my_bool set_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) } -void get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) +void ma_get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) { if (idx >= array->elements) { - DBUG_PRINT("warning",("To big array idx: %d, array size is %d", - idx,array->elements)); - bzero(element,array->size_of_element); + memset(element, 0, array->size_of_element); return; } memcpy(element,array->buffer+idx*array->size_of_element, @@ -141,18 +139,18 @@ void get_dynamic(DYNAMIC_ARRAY *array, gptr element, uint idx) } -void delete_dynamic(DYNAMIC_ARRAY *array) +void ma_delete_dynamic(DYNAMIC_ARRAY *array) { if (array->buffer) { - my_free(array->buffer); + free(array->buffer); array->buffer=0; array->elements=array->max_element=0; } } -void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) +void ma_delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) { char *ptr=array->buffer+array->size_of_element*idx; array->elements--; @@ -161,15 +159,14 @@ void delete_dynamic_element(DYNAMIC_ARRAY *array, uint idx) } -void freeze_size(DYNAMIC_ARRAY *array) +void ma_freeze_size(DYNAMIC_ARRAY *array) { uint elements=max(array->elements,1); if (array->buffer && array->max_element != elements) { - array->buffer=(char*) my_realloc(array->buffer, - elements*array->size_of_element, - MYF(MY_WME)); + array->buffer=(char*) realloc(array->buffer, + elements*array->size_of_element); array->max_element=elements; } } diff --git a/libmariadb/my_charset.c b/libmariadb/ma_charset.c similarity index 96% rename from libmariadb/my_charset.c rename to libmariadb/ma_charset.c index b38ddf21..d57cc83b 100644 --- a/libmariadb/my_charset.c +++ b/libmariadb/ma_charset.c @@ -49,13 +49,12 @@ #else #include #endif -#include -#include -#include +#include +#include +#include #include -extern int my_snprintf(char* to, size_t n, const char* fmt, ...); /* +----------------------------------------------------------------------+ | PHP Version 5 | @@ -494,7 +493,7 @@ mysql_mbcharlen_utf32(unsigned int utf32 __attribute((unused))) #define UTF8_MB3 "utf8" /* {{{ mysql_charsets */ -const CHARSET_INFO compiled_charsets[] = +const MARIADB_CHARSET_INFO mariadb_compiled_charsets[] = { { 1, 1, "big5","big5_chinese_ci", "", 950, "BIG5", 1, 2, mysql_mbcharlen_big5, check_mb_big5}, { 3, 1, "dec8", "dec8_swedisch_ci", "", 0, "DEC", 1, 1, NULL, NULL}, @@ -668,43 +667,39 @@ const CHARSET_INFO compiled_charsets[] = /* {{{ mysql_find_charset_nr */ -const CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) +const MARIADB_CHARSET_INFO * mysql_find_charset_nr(unsigned int charsetnr) { - const CHARSET_INFO * c = compiled_charsets; - DBUG_ENTER("mysql_find_charset_nr"); + const MARIADB_CHARSET_INFO * c = mariadb_compiled_charsets; do { if (c->nr == charsetnr) { - DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); - DBUG_RETURN(c); + return(c); } ++c; } while (c[0].nr != 0); - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ /* {{{ mysql_find_charset_name */ -CHARSET_INFO * mysql_find_charset_name(const char *name) +MARIADB_CHARSET_INFO * mysql_find_charset_name(const char *name) { - CHARSET_INFO *c = (CHARSET_INFO *)compiled_charsets; - DBUG_ENTER("mysql_find_charset_name"); + MARIADB_CHARSET_INFO *c = (MARIADB_CHARSET_INFO *)mariadb_compiled_charsets; do { if (!strcasecmp(c->csname, name)) { - DBUG_PRINT("info", ("found character set %d %s", c->nr, c->csname)); - DBUG_RETURN(c); + return(c); } ++c; } while (c[0].nr != 0); - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ /* {{{ mysql_cset_escape_quotes */ -size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, +size_t mysql_cset_escape_quotes(const MARIADB_CHARSET_INFO *cset, char *newstr, const char * escapestr, size_t escapestr_len ) { const char *newstr_s = newstr; @@ -712,8 +707,6 @@ size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, const char *end = escapestr + escapestr_len; my_bool escape_overflow = FALSE; - DBUG_ENTER("mysql_cset_escape_quotes"); - for (;escapestr < end; escapestr++) { unsigned int len = 0; /* check unicode characters */ @@ -750,15 +743,15 @@ size_t mysql_cset_escape_quotes(const CHARSET_INFO *cset, char *newstr, *newstr = '\0'; if (escape_overflow) { - DBUG_RETURN((size_t)~0); + return((size_t)~0); } - DBUG_RETURN((size_t)(newstr - newstr_s)); + return((size_t)(newstr - newstr_s)); } /* }}} */ /* {{{ mysql_cset_escape_slashes */ -size_t mysql_cset_escape_slashes(const CHARSET_INFO * cset, char *newstr, +size_t mysql_cset_escape_slashes(const MARIADB_CHARSET_INFO * cset, char *newstr, const char * escapestr, size_t escapestr_len ) { const char *newstr_s = newstr; @@ -766,9 +759,6 @@ size_t mysql_cset_escape_slashes(const CHARSET_INFO * cset, char *newstr, const char *end = escapestr + escapestr_len; my_bool escape_overflow = FALSE; - DBUG_ENTER("mysql_cset_escape_slashes"); - DBUG_PRINT("info", ("charset=%s", cset->name)); - for (;escapestr < end; escapestr++) { char esc = '\0'; unsigned int len = 0; @@ -830,9 +820,9 @@ size_t mysql_cset_escape_slashes(const CHARSET_INFO * cset, char *newstr, *newstr = '\0'; if (escape_overflow) { - DBUG_RETURN((size_t)~0); + return((size_t)~0); } - DBUG_RETURN((size_t)(newstr - newstr_s)); + return((size_t)(newstr - newstr_s)); } /* }}} */ @@ -1086,8 +1076,8 @@ char *madb_get_os_character_set() char *p= NULL; #ifdef _WIN32 char codepage[FN_REFLEN]; - my_snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? - GetConsoleCP() : GetACP()); + snprintf(codepage, FN_REFLEN, "%u", GetConsoleWindow() ? + GetConsoleCP() : GetACP()); p= codepage; #elif defined(HAVE_NL_LANGINFO) && defined(HAVE_SETLOCALE) if (setlocale(LC_CTYPE, "") && (p= nl_langinfo(CODESET))); @@ -1130,24 +1120,22 @@ int madb_get_windows_cp(const char *charset) */ static void map_charset_name(const char *cs_name, my_bool target_cs, char *buffer, size_t buff_len) { - char *ptr= buffer, digits[3], endianness[3]= "BE"; + char digits[3], endianness[3]= "BE"; if (sscanf(cs_name, "UTF%2[0-9]%2[LBE]", digits, endianness)) { /* We should have at least digits. Endianness we write either default(BE), or what we found in the string */ - ptr= strnmov(ptr, "UTF-", (uint)buff_len); - ptr= strnmov(ptr, digits, (uint)(buff_len - (ptr - buffer))); - ptr= strnmov(ptr, endianness, (uint)(buff_len - (ptr - buffer))); + snprintf(buffer, buff_len, "UTF-%s%s", digits, endianness); } else { /* Not our client - copy as is*/ - ptr= strnmov(ptr, cs_name, (uint)buff_len); + strncpy(buffer, cs_name, buff_len); } if (target_cs) { - strnmov(ptr, "//TRANSLIT", (uint)(buff_len - (ptr - buffer))); + strncat(buffer, "//TRANSLIT", buff_len); } } /* }}} */ @@ -1164,8 +1152,8 @@ 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, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode) +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) { iconv_t conv= 0; size_t rc= -1; diff --git a/libmariadb/client_plugin.c.in b/libmariadb/ma_client_plugin.c.in similarity index 94% rename from libmariadb/client_plugin.c.in rename to libmariadb/ma_client_plugin.c.in index 0e2d5952..12522cc4 100644 --- a/libmariadb/client_plugin.c.in +++ b/libmariadb/ma_client_plugin.c.in @@ -1,4 +1,5 @@ /* Copyright (C) 2010 - 2012 Sergei Golubchik and Monty Program Ab + 2015-2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -34,17 +35,13 @@ #define FORCE_INIT_OF_VARS 1 #endif -#include -#include +#include +#include #include -#include -#ifdef THREAD -#include -#else -#include -#endif +#include +#include -#include "errmsg.h" +#include "ma_errmsg.h" #include struct st_client_plugin_int { @@ -54,7 +51,7 @@ struct st_client_plugin_int { }; static my_bool initialized= 0; -static MEM_ROOT mem_root; +static MA_MEM_ROOT mem_root; static uint valid_plugins[][2]= { {MYSQL_CLIENT_AUTHENTICATION_PLUGIN, MYSQL_CLIENT_AUTHENTICATION_PLUGIN_INTERFACE_VERSION}, @@ -197,7 +194,7 @@ add_plugin(MYSQL *mysql, struct st_mysql_client_plugin *plugin, void *dlhandle, } p= (struct st_client_plugin_int *) - memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); + ma_memdup_root(&mem_root, (char *)&plugin_int, sizeof(plugin_int)); if (!p) { @@ -250,16 +247,16 @@ static void load_env_plugins(MYSQL *mysql) if (!s) return; - free_env= plugs= my_strdup(s, MYF(MY_WME)); + free_env= plugs= strdup(s); do { - if ((s= strchr(plugs, ';'))) + if (s= strchr(plugs, ';')) *s= '\0'; mysql_load_plugin(mysql, plugs, -1, 0); plugs= s + 1; } while (s); - my_free(free_env); + free(free_env); } /********** extern functions to be used by libmariadb *********************/ @@ -283,12 +280,12 @@ int mysql_client_plugin_init() if (initialized) return 0; - bzero(&mysql, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ + memset(&mysql, 0, sizeof(mysql)); /* dummy mysql for set_mysql_extended_error */ pthread_mutex_init(&LOCK_load_client_plugin, MY_MUTEX_INIT_SLOW); - init_alloc_root(&mem_root, 128, 128); + ma_init_ma_alloc_root(&mem_root, 128, 128); - bzero(&plugin_list, sizeof(plugin_list)); + memset(&plugin_list, 0, sizeof(plugin_list)); initialized= 1; @@ -327,9 +324,9 @@ void mysql_client_plugin_deinit() (void)dlclose(p->dlhandle); } - bzero(&plugin_list, sizeof(plugin_list)); + memset(&plugin_list, 0, sizeof(plugin_list)); initialized= 0; - free_root(&mem_root, MYF(0)); + ma_free_root(&mem_root, MYF(0)); pthread_mutex_destroy(&LOCK_load_client_plugin); } @@ -391,11 +388,11 @@ mysql_load_plugin_v(MYSQL *mysql, const char *name, int type, } /* Compile dll path */ - strxnmov(dlpath, sizeof(dlpath) - 1, + snprintf(dlpath, sizeof(dlpath) - 1, "%s/%s%s", mysql->options.extension && mysql->options.extension->plugin_dir ? mysql->options.extension->plugin_dir : (env_plugin_dir) ? env_plugin_dir : PLUGINDIR, "/", - name, SO_EXT, NullS); + name, SO_EXT); /* Open new dll handle */ if (!(dlhandle= dlopen((const char *)dlpath, RTLD_NOW))) diff --git a/libmariadb/my_compress.c b/libmariadb/ma_compress.c similarity index 75% rename from libmariadb/my_compress.c rename to libmariadb/ma_compress.c index c9498842..c040af87 100644 --- a/libmariadb/my_compress.c +++ b/libmariadb/ma_compress.c @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -17,10 +18,10 @@ /* Written by Sinisa Milivojevic */ -#include +#include #ifdef HAVE_COMPRESS -#include -#include +#include +#include #include /* @@ -29,59 +30,59 @@ ** *complen is 0 if the packet wasn't compressed */ -my_bool my_compress(unsigned char *packet, size_t *len, size_t *complen) +my_bool _mariadb_compress(unsigned char *packet, size_t *len, size_t *complen) { if (*len < MIN_COMPRESS_LENGTH) *complen=0; else { - unsigned char *compbuf=my_compress_alloc(packet,len,complen); + unsigned char *compbuf=_mariadb_compress_alloc(packet,len,complen); if (!compbuf) return *complen ? 0 : 1; memcpy(packet,compbuf,*len); - my_free(compbuf); + free(compbuf); } return 0; } -unsigned char *my_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen) +unsigned char *_mariadb_compress_alloc(const unsigned char *packet, size_t *len, size_t *complen) { unsigned char *compbuf; *complen = *len * 120 / 100 + 12; - if (!(compbuf = (unsigned char *) my_malloc(*complen,MYF(MY_WME)))) + if (!(compbuf = (unsigned char *) malloc(*complen))) return 0; /* Not enough memory */ if (compress((Bytef*) compbuf,(ulong *) complen, (Bytef*) packet, (uLong) *len ) != Z_OK) { - my_free(compbuf); + free(compbuf); return 0; } if (*complen >= *len) { *complen=0; - my_free(compbuf); + free(compbuf); return 0; } swap(size_t,*len,*complen); /* *len is now packet length */ return compbuf; } -my_bool my_uncompress (unsigned char *packet, size_t *len, size_t *complen) +my_bool _mariadb_uncompress (unsigned char *packet, size_t *len, size_t *complen) { if (*complen) /* If compressed */ { - unsigned char *compbuf = (unsigned char *) my_malloc (*complen,MYF(MY_WME)); + unsigned char *compbuf = (unsigned char *) malloc (*complen); if (!compbuf) return 1; /* Not enough memory */ if (uncompress((Bytef*) compbuf, (uLongf *)complen, (Bytef*) packet, (uLongf)*len) != Z_OK) { /* Probably wrong packet */ - my_free (compbuf); + free(compbuf); return 1; } *len = *complen; memcpy(packet,compbuf,*len); - my_free(compbuf); + free(compbuf); } else *complen= *len; return 0; diff --git a/libmariadb/my_context.c b/libmariadb/ma_context.c similarity index 94% rename from libmariadb/my_context.c rename to libmariadb/ma_context.c index 0fda2a73..5012c4e1 100644 --- a/libmariadb/my_context.c +++ b/libmariadb/ma_context.c @@ -1,5 +1,6 @@ /* Copyright 2011, 2012 Kristian Nielsen and Monty Program Ab + 2016 MariaDB Corporation AB This file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -20,10 +21,9 @@ swapcontext(). */ -#include "my_global.h" -#include "mysys_priv.h" -#include "m_string.h" -#include "my_context.h" +#include "ma_global.h" +#include "ma_string.h" +#include "ma_context.h" #ifdef HAVE_VALGRIND #include @@ -73,9 +73,7 @@ my_context_continue(struct my_context *c) if (!c->active) return 0; - DBUG_SWAP_CODE_STATE(&c->dbug_state); err= swapcontext(&c->base_context, &c->spawned_context); - DBUG_SWAP_CODE_STATE(&c->dbug_state); if (err) { fprintf(stderr, "Aieie, swapcontext() failed: %d (errno=%d)\n", @@ -130,7 +128,7 @@ my_context_init(struct my_context *c, size_t stack_size) #if SIZEOF_CHARP > SIZEOF_INT*2 #error Error: Unable to store pointer in 2 ints on this architecture #endif - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); if (!(c->stack= malloc(stack_size))) return -1; /* Out of memory */ c->stack_size= stack_size; @@ -151,7 +149,6 @@ my_context_destroy(struct my_context *c) #endif free(c->stack); } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_UCONTEXT */ @@ -191,8 +188,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - /* There are 6 callee-save registers we need to save and restore when suspending and continuing, plus stack pointer %rsp and instruction pointer @@ -254,8 +249,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "rcx", "rdx", "r8", "r9", "r10", "r11", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -264,8 +257,6 @@ my_context_continue(struct my_context *c) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - __asm__ __volatile__ ( "movq (%[save]), %%rax\n\t" @@ -323,8 +314,6 @@ my_context_continue(struct my_context *c) : "rcx", "rdx", "rsi", "rdi", "r8", "r9", "r10", "r11", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -372,7 +361,7 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); if (!(c->stack_bot= malloc(stack_size))) return -1; /* Out of memory */ @@ -382,7 +371,7 @@ my_context_init(struct my_context *c, size_t stack_size) */ c->stack_top= (void *) (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); - bzero(c->stack_top, 16); + memset(c->stack_top, 0, 16); #ifdef HAVE_VALGRIND c->valgrind_stack_id= @@ -401,7 +390,6 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_X86_64_GCC_ASM */ @@ -439,8 +427,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - /* There are 4 callee-save registers we need to save and restore when suspending and continuing, plus stack pointer %esp and instruction pointer @@ -501,8 +487,6 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) : "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -511,8 +495,6 @@ my_context_continue(struct my_context *c) { int ret; - DBUG_SWAP_CODE_STATE(&c->dbug_state); - __asm__ __volatile__ ( "movl (%[save]), %%eax\n\t" @@ -566,8 +548,6 @@ my_context_continue(struct my_context *c) : "ecx", "edx", "memory", "cc" ); - DBUG_SWAP_CODE_STATE(&c->dbug_state); - return ret; } @@ -613,12 +593,12 @@ my_context_yield(struct my_context *c) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); if (!(c->stack_bot= malloc(stack_size))) return -1; /* Out of memory */ c->stack_top= (void *) (( ((intptr)c->stack_bot + stack_size) & ~(intptr)0xf) - 16); - bzero(c->stack_top, 16); + memset(c->stack_top, 0, 16); #ifdef HAVE_VALGRIND c->valgrind_stack_id= @@ -637,7 +617,6 @@ my_context_destroy(struct my_context *c) VALGRIND_STACK_DEREGISTER(c->valgrind_stack_id); #endif } - DBUG_FREE_CODE_STATE(&c->dbug_state); } #endif /* MY_CONTEXT_USE_I386_GCC_ASM */ @@ -675,7 +654,7 @@ my_context_trampoline(void *p) int my_context_init(struct my_context *c, size_t stack_size) { - bzero(c, sizeof(*c)); + memset(c, 0, sizeof(*c)); c->lib_fiber= CreateFiber(stack_size, my_context_trampoline, c); if (c->lib_fiber) return 0; @@ -685,7 +664,6 @@ my_context_init(struct my_context *c, size_t stack_size) void my_context_destroy(struct my_context *c) { - DBUG_FREE_CODE_STATE(&c->dbug_state); if (c->lib_fiber) { DeleteFiber(c->lib_fiber); @@ -708,18 +686,14 @@ my_context_spawn(struct my_context *c, void (*f)(void *), void *d) if (current_fiber == NULL || current_fiber == (void *)0x1e00) current_fiber= ConvertThreadToFiber(c); c->app_fiber= current_fiber; - DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); - DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } int my_context_continue(struct my_context *c) { - DBUG_SWAP_CODE_STATE(&c->dbug_state); SwitchToFiber(c->lib_fiber); - DBUG_SWAP_CODE_STATE(&c->dbug_state); return c->return_value; } diff --git a/libmariadb/ma_default.c b/libmariadb/ma_default.c new file mode 100644 index 00000000..7d6931a0 --- /dev/null +++ b/libmariadb/ma_default.c @@ -0,0 +1,224 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include +#include "ma_string.h" +#include +#include "mariadb_ctype.h" +#include +#include +#include + +#ifdef _WIN32 +#include +static const char *ini_exts[]= {"ini", "cnf", 0}; +static const char *ini_dirs[]= {"C:", ".", 0}; +static const char *ini_env_dirs[]= {"WINDOWS", "HOMEPATH", 0}; +#define R_OK 4 +#else +#include +static const char *ini_exts[]= {"cnf", 0}; +static const char *ini_dirs[]= {"/etc", "/etc/mysql", ".", 0}; +static const char *ini_env_dirs[]= {"HOME", "SYSCONFDIR", 0}; +#endif + +extern my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value); + +char *_mariadb_get_default_file(char *filename, size_t length) +{ + int dirs; int exts; + + for (dirs= 0; ini_dirs[dirs]; dirs++) + { + for (exts= 0; ini_exts[exts]; exts++) + { + snprintf(filename, length, + "%s%cmy.%s", ini_dirs[dirs], FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + return filename; + } + } + for (dirs= 0; ini_env_dirs[dirs]; dirs++) + { + for (exts= 0; ini_exts[exts]; exts++) + { + char *env= getenv(ini_env_dirs[dirs]); + snprintf(filename, length, + "%s%cmy.%s", env, FN_LIBCHAR, ini_exts[exts]); + if (!access(filename, R_OK)) + return filename; + } + } + return NULL; +} + +my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file, + const char *group) +{ + char buff[4096],*ptr,*end,*value, *key= 0, *optval; + MA_FILE *file= NULL; + char *filename; + uint line=0; + my_bool rc= 1; + my_bool read_values= 0, found_group= 0, is_escaped= 0, is_quoted= 0; + my_bool (*set_option)(MYSQL *mysql, const char *config_option, const char *config_value); + + /* if a plugin registered a hook we will call this hook, otherwise + * default (_mariadb_set_conf_option) will be called */ + if (mysql->options.extension && mysql->options.extension->set_option) + set_option= mysql->options.extension->set_option; + else + set_option= _mariadb_set_conf_option; + + if (config_file) + filename= strdup(config_file); + else + { + filename= (char *)malloc(FN_REFLEN + 10); + if (!_mariadb_get_default_file(filename, FN_REFLEN + 10)) + { + free(filename); + goto err; + } + } + + if (!(file = ma_open(filename, "r", NULL))) + return 1; + + while (ma_gets(buff,sizeof(buff)-1,file)) + { + line++; + key= 0; + /* Ignore comment and empty lines */ + for (ptr=buff ; isspace(*ptr) ; ptr++ ); + if (!is_escaped && (*ptr == '\"' || *ptr== '\'')) + { + is_quoted= !is_quoted; + continue; + } + if (*ptr == '#' || *ptr == ';' || !*ptr) + continue; + is_escaped= (*ptr == '\\'); + if (*ptr == '[') /* Group name */ + { + found_group=1; + if (!(end=(char *) strchr(++ptr,']'))) + { + /* todo: set error */ + goto err; + } + for ( ; isspace(end[-1]) ; end--) ; /* Remove end space */ + end[0]=0; + read_values= test(strcmp(ptr, group) == 0); + continue; + } + if (!found_group) + { + /* todo: set error */ + goto err; + } + if (!read_values) + continue; + if (!(end=value=strchr(ptr,'='))) + { + end=strchr(ptr, '\0'); /* Option without argument */ + set_option(mysql, ptr, NULL); + } + if (!key) + key= ptr; + for ( ; isspace(end[-1]) ; end--) ; + + if (!value) + { + if (!key) + key= ptr; + } + else + { + /* Remove pre- and end space */ + char *value_end; + *value= 0; + value++; + ptr= value; + for ( ; isspace(*value); value++) ; + optval= value; + value_end=strchr(value, '\0'); + for ( ; isspace(value_end[-1]) ; value_end--) ; + /* remove possible quotes */ + if (*value == '\'' || *value == '\"') + { + value++; + if (value_end[-1] == '\'' || value_end[-1] == '\"') + value_end--; + } + if (value_end < value) /* Empty string */ + value_end=value; + for ( ; value != value_end; value++) + { + if (*value == '\\' && value != value_end-1) + { + switch(*++value) { + case 'n': + *ptr++='\n'; + break; + case 't': + *ptr++= '\t'; + break; + case 'r': + *ptr++ = '\r'; + break; + case 'b': + *ptr++ = '\b'; + break; + case 's': + *ptr++= ' '; /* space */ + break; + case '\"': + *ptr++= '\"'; + break; + case '\'': + *ptr++= '\''; + break; + case '\\': + *ptr++= '\\'; + break; + default: /* Unknown; Keep '\' */ + *ptr++= '\\'; + *ptr++= *value; + break; + } + } + else + *ptr++= *value; + } + *ptr=0; + set_option(mysql, key, optval); + key= optval= 0; + } + } + rc= 0; + +err: + free(filename); + if (file) + ma_close(file); + return rc; +} + + diff --git a/libmariadb/errmsg.c b/libmariadb/ma_errmsg.c similarity index 95% rename from libmariadb/errmsg.c rename to libmariadb/ma_errmsg.c index 936db98e..d79da00e 100644 --- a/libmariadb/errmsg.c +++ b/libmariadb/ma_errmsg.c @@ -18,9 +18,9 @@ /* Error messages for MySQL clients */ /* error messages for the demon is in share/language/errmsg.sys */ -#include -#include -#include "errmsg.h" +#include +#include +#include "ma_errmsg.h" #include #ifdef GERMAN @@ -106,7 +106,7 @@ const char *client_errors[]= /* 2023 */ "", /* 2024 */ "", /* 2025 */ "", -/* 2026 */ "SSL connection error: %100s", +/* 2026 */ "SSL connection error: %-.100s", /* 2027 */ "received malformed packet", /* 2028 */ "", /* 2029 */ "", @@ -151,10 +151,16 @@ const char *mariadb_client_errors[] = /* 5001 */ "Bind to local interface '-.%64s' failed (Errorcode: %d)", /* 5002 */ "Connection type doesn't support asynchronous IO operations", /* 5003 */ "Server doesn't support function '%s'", + /* 5004 */ "File '%s' not found (Errcode: %d)", + /* 5005 */ "Error reading file '%s' (Errcode: %d)", "" }; +const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; +char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; + void init_client_errs(void) { my_errmsg[CLIENT_ERRMAP] = &client_errors[0]; } + diff --git a/libmariadb/hash.c b/libmariadb/ma_hash.c similarity index 86% rename from libmariadb/hash.c rename to libmariadb/ma_hash.c index 8436ef91..8b00d077 100644 --- a/libmariadb/hash.c +++ b/libmariadb/ma_hash.c @@ -1,6 +1,6 @@ /************************************************************************************ Copyright (C) 2000, 2012 MySQL AB & MySQL Finland AB & TCX DataKonsult AB, - Monty Program AB + Monty Program AB, 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -25,10 +25,11 @@ /* One of key_length or key_length_offset must be given */ /* Key length of 0 isn't allowed */ -#include "mysys_priv.h" -#include -#include -#include "hash.h" +#include +#include +#include +#include +#include "ma_hash.h" #define NO_RECORD ((uint) -1) #define LOWFIND 1 @@ -47,14 +48,11 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, hash_get_key get_key, void (*free_element)(void*),uint flags CALLER_INFO_PROTO) { - DBUG_ENTER("hash_init"); - DBUG_PRINT("enter",("hash: %lx size: %d",hash,size)); - hash->records=0; - if (my_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) + if (ma_init_dynamic_array_ci(&hash->array,sizeof(HASH_LINK),size,0)) { hash->free=0; /* Allow call to hash_free */ - DBUG_RETURN(TRUE); + return(TRUE); } hash->key_offset=key_offset; hash->key_length=key_length; @@ -67,13 +65,12 @@ my_bool _hash_init(HASH *hash,uint size,uint key_offset,uint key_length, hash->calc_hashnr=calc_hashnr_caseup; else hash->calc_hashnr=calc_hashnr; - DBUG_RETURN(0); + return(0); } void hash_free(HASH *hash) { - DBUG_ENTER("hash_free"); if (hash->free) { uint i,records; @@ -82,9 +79,9 @@ void hash_free(HASH *hash) (*hash->free)(data[i].data); hash->free=0; } - delete_dynamic(&hash->array); + ma_delete_dynamic(&hash->array); hash->records=0; - DBUG_VOID_RETURN; + return; } /* some helper functions */ @@ -209,7 +206,6 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) { HASH_LINK *pos; uint flag,idx; - DBUG_ENTER("hash_search"); flag=1; if (hash->records) @@ -222,9 +218,8 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) pos= dynamic_element(&hash->array,idx,HASH_LINK*); if (!hashcmp(hash,pos,key,length)) { - DBUG_PRINT("exit",("found key at %d",idx)); hash->current_record= idx; - DBUG_RETURN (pos->data); + return (pos->data); } if (flag) { @@ -236,7 +231,7 @@ gptr hash_search(HASH *hash,const uchar *key,uint length) while ((idx=pos->next) != NO_RECORD); } hash->current_record= NO_RECORD; - DBUG_RETURN(0); + return(0); } /* Get next record with identical key */ @@ -303,7 +298,7 @@ my_bool hash_insert(HASH *info,const uchar *record) LINT_INIT(ptr_to_rec); LINT_INIT(ptr_to_rec2); flag=0; - if (!(empty=(HASH_LINK*) alloc_dynamic(&info->array))) + if (!(empty=(HASH_LINK*) ma_alloc_dynamic(&info->array))) return(TRUE); /* No more memory */ info->current_record= NO_RECORD; @@ -430,9 +425,8 @@ my_bool hash_delete(HASH *hash,uchar *record) { uint blength,pos2,pos_hashnr,lastpos_hashnr,idx,empty_index; HASH_LINK *data,*lastpos,*gpos,*pos,*pos3,*empty; - DBUG_ENTER("hash_delete"); if (!hash->records) - DBUG_RETURN(1); + return(1); blength=hash->blength; data=dynamic_element(&hash->array,0,HASH_LINK*); @@ -444,7 +438,7 @@ my_bool hash_delete(HASH *hash,uchar *record) { gpos=pos; if (pos->next == NO_RECORD) - DBUG_RETURN(1); /* Key not found */ + return(1); /* Key not found */ pos=data+pos->next; } @@ -503,10 +497,10 @@ my_bool hash_delete(HASH *hash,uchar *record) pos->next=empty_index; exit: - VOID(pop_dynamic(&hash->array)); + VOID(ma_pop_dynamic(&hash->array)); if (hash->free) (*hash->free)((uchar*) record); - DBUG_RETURN(0); + return(0); } /* @@ -518,7 +512,6 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) { uint idx,new_index,new_pos_index,blength,records,empty; HASH_LINK org_link,*data,*previous,*pos; - DBUG_ENTER("hash_update"); data=dynamic_element(&hash->array,0,HASH_LINK*); blength=hash->blength; records=hash->records; @@ -531,7 +524,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) blength,records); new_index=hash_mask(rec_hashnr(hash,record),blength,records); if (idx == new_index) - DBUG_RETURN(0); /* Nothing to do (No record check) */ + return(0); /* Nothing to do (No record check) */ previous=0; for (;;) { @@ -540,7 +533,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) break; previous=pos; if ((idx=pos->next) == NO_RECORD) - DBUG_RETURN(1); /* Not found in links */ + return(1); /* Not found in links */ } hash->current_record= NO_RECORD; org_link= *pos; @@ -575,7 +568,7 @@ my_bool hash_update(HASH *hash,uchar *record,uchar *old_key,uint old_key_length) data[empty]=org_link; data[new_index].next=empty; } - DBUG_RETURN(0); + return(0); } @@ -587,58 +580,4 @@ uchar *hash_element(HASH *hash,uint idx) } -#ifndef DBUG_OFF -my_bool hash_check(HASH *hash) -{ - int error; - uint i,rec_link,found,max_links,seek,links,idx; - uint records,blength; - HASH_LINK *data,*hash_info; - - records=hash->records; blength=hash->blength; - data=dynamic_element(&hash->array,0,HASH_LINK*); - error=0; - - for (i=found=max_links=seek=0 ; i < records ; i++) - { - if (hash_rec_mask(hash,data+i,blength,records) == i) - { - found++; seek++; links=1; - for (idx=data[i].next ; - idx != NO_RECORD && found < records + 1; - idx=hash_info->next) - { - if (idx >= records) - { - DBUG_PRINT("error", - ("Found pointer outside array to %d from link starting at %d", - idx,i)); - error=1; - } - hash_info=data+idx; - seek+= ++links; - if ((rec_link=hash_rec_mask(hash,hash_info,blength,records)) != i) - { - DBUG_PRINT("error", - ("Record in wrong link at %d: Start %d Record: %lx Record-link %d", idx,i,hash_info->data,rec_link)); - error=1; - } - else - found++; - } - if (links > max_links) max_links=links; - } - } - if (found != records) - { - DBUG_PRINT("error",("Found %ld of %ld records")); - error=1; - } - if (records) - DBUG_PRINT("info", - ("records: %ld seeks: %d max links: %d hitrate: %.2f", - records,seek,max_links,(float) seek / (float) records)); - return error; -} -#endif diff --git a/libmariadb/ma_init.c b/libmariadb/ma_init.c new file mode 100644 index 00000000..1e254b20 --- /dev/null +++ b/libmariadb/ma_init.c @@ -0,0 +1,115 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include +#include "mariadb_ctype.h" +#include +#include +#ifdef HAVE_GETRUSAGE +#include +/* extern int getrusage(int, struct rusage *); */ +#endif +#include +#ifdef _WIN32 +#ifdef _MSC_VER +#include +#include +#endif +static my_bool my_win_init(void); +#else +#define my_win_init() +#endif + +my_bool ma_init_done=0; + + + +/* Init ma_sys functions and ma_sys variabels */ + +void ma_init(void) +{ + if (ma_init_done) + return; + ma_init_done=1; + { +#ifdef _WIN32 + my_win_init(); +#endif + return; + } +} /* ma_init */ + + + +void ma_end(int infoflag) +{ +#ifdef _WIN32 + WSACleanup( ); +#endif /* _WIN32 */ + ma_init_done=0; +} /* ma_end */ + +#ifdef _WIN32 + +/* + This code is specially for running MySQL, but it should work in + other cases too. + + Inizializzazione delle variabili d'ambiente per Win a 32 bit. + + Vengono inserite nelle variabili d'ambiente (utilizzando cosi' + le funzioni getenv e putenv) i valori presenti nelle chiavi + del file di registro: + + HKEY_LOCAL_MACHINE\software\MySQL + + Se la kiave non esiste nonn inserisce nessun valore +*/ + +/* Crea la stringa d'ambiente */ + +void setEnvString(char *ret, const char *name, const char *value) +{ + sprintf(ret, "%s=%s", name, value); + return ; +} + +static my_bool my_win_init() +{ + WORD VersionRequested; + int err; + WSADATA WsaData; + const unsigned int MajorVersion=2, + MinorVersion=2; + VersionRequested= MAKEWORD(MajorVersion, MinorVersion); + /* Load WinSock library */ + if ((err= WSAStartup(VersionRequested, &WsaData))) + { + return 0; + } + /* make sure 2.2 or higher is supported */ + if ((LOBYTE(WsaData.wVersion) * 10 + HIBYTE(WsaData.wVersion)) < 22) + { + WSACleanup(); + return 1; + } + return 0; +} +#endif + diff --git a/libmariadb/ma_io.c b/libmariadb/ma_io.c index c66d00a0..c9e1509a 100644 --- a/libmariadb/ma_io.c +++ b/libmariadb/ma_io.c @@ -17,10 +17,9 @@ MA 02111-1307, USA */ -#include -#include -#include -#include +#include +#include +#include #include #include #include @@ -53,11 +52,6 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) { if (!(fp= fopen(location, mode))) { -#ifdef _WIN32 - my_errno= GetLastError(); -#else - my_errno= errno; -#endif return NULL; } } @@ -74,7 +68,7 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) len= MultiByteToWideChar(CodePage, 0, location, (int)strlen(location), NULL, 0); if (!len) return NULL; - if (!(w_filename= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + if (!(w_filename= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t)))) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; @@ -84,14 +78,14 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - my_free(w_filename); + free(w_filename); return NULL; } len= (int)strlen(mode); - if (!(w_mode= (wchar_t *)my_malloc((len + 1) * sizeof(wchar_t), MYF(MY_ZEROFILL)))) + if (!(w_mode= (wchar_t *)calloc(1, (len + 1) * sizeof(wchar_t)))) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - my_free(w_filename); + free(w_filename); return NULL; } Length= len; @@ -99,20 +93,19 @@ MA_FILE *ma_open(const char *location, const char *mode, MYSQL *mysql) if (!len) { /* todo: error handling */ - my_free(w_filename); - my_free(w_mode); + free(w_filename); + free(w_mode); return NULL; } fp= _wfopen(w_filename, w_mode); - my_errno= GetLastError(); - my_free(w_filename); - my_free(w_mode); + free(w_filename); + free(w_mode); } #endif if (fp) { - ma_file= (MA_FILE *)my_malloc(sizeof(MA_FILE), MYF(0)); + ma_file= (MA_FILE *)malloc(sizeof(MA_FILE)); if (!ma_file) { my_set_error(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); @@ -147,7 +140,7 @@ int ma_close(MA_FILE *file) switch (file->type) { case MA_FILE_LOCAL: rc= fclose((FILE *)file->ptr); - my_free(file); + free(file); break; #ifdef HAVE_REMOTEIO case MA_FILE_REMOTE: diff --git a/libmariadb/list.c b/libmariadb/ma_list.c similarity index 88% rename from libmariadb/list.c rename to libmariadb/ma_list.c index 204acd33..4e14c945 100644 --- a/libmariadb/list.c +++ b/libmariadb/ma_list.c @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -19,17 +20,14 @@ Code for handling dubble-linked lists in C */ -#include "mysys_priv.h" -#include - - +#include +#include +#include /* Add a element to start of list */ LIST *list_add(LIST *root, LIST *element) { - DBUG_ENTER("list_add"); - DBUG_PRINT("enter",("root: %lx element: %lx", root, element)); if (root) { if (root->prev) /* If add in mid of list */ @@ -40,7 +38,7 @@ LIST *list_add(LIST *root, LIST *element) else element->prev=0; element->next=root; - DBUG_RETURN(element); /* New root */ + return(element); /* New root */ } @@ -63,8 +61,8 @@ void list_free(LIST *root, unsigned int free_data) { next=root->next; if (free_data) - my_free(root->data); - my_free(root); + free(root->data); + free(root); root=next; } } @@ -72,7 +70,7 @@ void list_free(LIST *root, unsigned int free_data) LIST *list_cons(void *data, LIST *list) { - LIST *new_charset=(LIST*) my_malloc(sizeof(LIST),MYF(MY_FAE)); + LIST *new_charset=(LIST*) malloc(sizeof(LIST)); if (!new_charset) return 0; new_charset->data=data; diff --git a/libmariadb/ma_ll2str.c b/libmariadb/ma_ll2str.c new file mode 100644 index 00000000..36987767 --- /dev/null +++ b/libmariadb/ma_ll2str.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include "ma_string.h" +#include + +char NEAR _dig_vec[] = + "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"; + +#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ + X >= 'A' && X <= 'Z' ? X-'A'+10 :\ + X >= 'a' && X <= 'z' ? X-'a'+10 :\ + '\177') + +char *ma_ll2str(long long val,char *dst,int radix) +{ + char buffer[65]; + register char *p; + long long_val; + + if (radix < 0) + { + if (radix < -36 || radix > -2) return (char*) 0; + if (val < 0) { + *dst++ = '-'; + val = -val; + } + radix = -radix; + } + else + { + if (radix > 36 || radix < 2) return (char*) 0; + } + if (val == 0) + { + *dst++='0'; + *dst='\0'; + return dst; + } + p = &buffer[sizeof(buffer)-1]; + *p = '\0'; + + while ((ulonglong) val > (ulonglong) LONG_MAX) + { + ulonglong quo=(ulonglong) val/(uint) radix; + uint rem= (uint) (val- quo* (uint) radix); + *--p = _dig_vec[rem]; + val= quo; + } + long_val= (long) val; + while (long_val != 0) + { + long quo= long_val/radix; + *--p = _dig_vec[(uchar) (long_val - quo*radix)]; + long_val= quo; + } + while ((*dst++ = *p++) != 0) ; + return dst-1; +} diff --git a/libmariadb/my_loaddata.c b/libmariadb/ma_loaddata.c similarity index 87% rename from libmariadb/my_loaddata.c rename to libmariadb/ma_loaddata.c index e36c086a..2bc51eca 100644 --- a/libmariadb/my_loaddata.c +++ b/libmariadb/ma_loaddata.c @@ -40,11 +40,10 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include -#include "errmsg.h" +#include "ma_global.h" +#include +#include +#include "ma_errmsg.h" #include "mysql.h" #include #include @@ -66,11 +65,10 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) { MYSQL_INFILE_INFO *info; MYSQL *mysql= (MYSQL *)userdata; - DBUG_ENTER("mysql_local_infile_init"); - info = (MYSQL_INFILE_INFO *)my_malloc(sizeof(MYSQL_INFILE_INFO), MYF(MY_ZEROFILL)); + info = (MYSQL_INFILE_INFO *)calloc(1, sizeof(MYSQL_INFILE_INFO)); if (!info) { - DBUG_RETURN(1); + return(1); } *ptr = info; @@ -89,14 +87,14 @@ int mysql_local_infile_init(void **ptr, const char *filename, void *userdata) } else { - info->error_no = my_errno; - my_snprintf((char *)info->error_msg, sizeof(info->error_msg), - EE(EE_FILENOTFOUND), filename, info->error_no); + info->error_no = errno; + snprintf((char *)info->error_msg, sizeof(info->error_msg), + CER(CR_FILE_NOT_FOUND), filename, info->error_no); } - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } /* }}} */ @@ -108,16 +106,15 @@ int mysql_local_infile_read(void *ptr, char * buf, unsigned int buf_len) MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; size_t count; - DBUG_ENTER("mysql_local_infile_read"); - count= ma_read((void *)buf, 1, (size_t)buf_len, info->fp); if (count < 0) { - strcpy(info->error_msg, "Error reading file"); - info->error_no = EE_READ; + info->error_no = errno; + snprintf((char *)info->error_msg, sizeof(info->error_msg), + CER(CR_FILE_READ), info->filename, info->error_no); } - DBUG_RETURN((int)count); + return((int)count); } /* }}} */ @@ -128,15 +125,13 @@ int mysql_local_infile_error(void *ptr, char *error_buf, unsigned int error_buf_ { MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; - DBUG_ENTER("mysql_local_infile_error"); - if (info) { strncpy(error_buf, info->error_msg, error_buf_len); - DBUG_RETURN(info->error_no); + return(info->error_no); } strncpy(error_buf, "Unknown error", error_buf_len); - DBUG_RETURN(CR_UNKNOWN_ERROR); + return(CR_UNKNOWN_ERROR); } /* }}} */ @@ -147,15 +142,13 @@ void mysql_local_infile_end(void *ptr) { MYSQL_INFILE_INFO *info = (MYSQL_INFILE_INFO *)ptr; - DBUG_ENTER("mysql_local_infile_end"); - if (info) { if (info->fp) ma_close(info->fp); - my_free(ptr); + free(ptr); } - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -163,12 +156,11 @@ void mysql_local_infile_end(void *ptr) /* {{{ mysql_local_infile_default */ void mysql_set_local_infile_default(MYSQL *conn) { - DBUG_ENTER("mysql_local_infile_default"); conn->options.local_infile_init = mysql_local_infile_init; conn->options.local_infile_read = mysql_local_infile_read; conn->options.local_infile_error = mysql_local_infile_error; conn->options.local_infile_end = mysql_local_infile_end; - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -180,13 +172,12 @@ void STDCALL mysql_set_local_infile_handler(MYSQL *conn, int (*local_infile_error)(void *, char *, uint), void *userdata) { - DBUG_ENTER("mysql_set_local_infile_handler"); conn->options.local_infile_init= local_infile_init; conn->options.local_infile_read= local_infile_read; conn->options.local_infile_end= local_infile_end; conn->options.local_infile_error= local_infile_error; conn->options.local_infile_userdata = userdata; - DBUG_VOID_RETURN; + return; } /* }}} */ @@ -199,8 +190,6 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) void *info= NULL; my_bool result= 1; - DBUG_ENTER("mysql_handle_local_infile"); - /* check if all callback functions exist */ if (!conn->options.local_infile_init || !conn->options.local_infile_end || !conn->options.local_infile_read || !conn->options.local_infile_error) @@ -218,7 +207,7 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) } /* allocate buffer for reading data */ - buf = (uchar *)my_malloc(buflen, MYF(0)); + buf = (uchar *)malloc(buflen); /* init handler: allocate read buffer and open file */ if (conn->options.local_infile_init(&info, filename, @@ -264,8 +253,8 @@ my_bool mysql_handle_local_infile(MYSQL *conn, const char *filename) infile_error: conn->options.local_infile_end(info); - my_free(buf); - DBUG_RETURN(result); + free(buf); + return(result); } /* }}} */ diff --git a/libmariadb/net.c b/libmariadb/ma_net.c similarity index 84% rename from libmariadb/net.c rename to libmariadb/ma_net.c index 5a850ad7..7be79a23 100644 --- a/libmariadb/net.c +++ b/libmariadb/ma_net.c @@ -1,5 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - + 2012-2016 SkySQL AB, MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either @@ -23,13 +23,13 @@ */ -#include +#include #include #include -#include -#include +#include +#include #include "mysql.h" -#include "mysqld_error.h" +#include "ma_server_error.h" #include #include #include @@ -64,19 +64,6 @@ ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */ #include #endif #endif -#include "mysqld_error.h" -#ifdef MYSQL_SERVER -#include "my_pthread.h" -#include "thr_alarm.h" -void sql_print_error(const char *format,...); -#define RETRY_COUNT mysqld_net_retry_count -extern ulong mysqld_net_retry_count; -#else - -#ifdef OS2 /* avoid name conflict */ -#define thr_alarm_t thr_alarm_t_net -#define ALARM ALARM_net -#endif typedef my_bool thr_alarm_t; typedef my_bool ALARM; @@ -91,7 +78,6 @@ static inline int local_thr_alarm(my_bool *A,int B __attribute__((unused)),ALARM } #define thr_got_alarm(A) 0 #define RETRY_COUNT 1 -#endif #ifdef MYSQL_SERVER extern ulong bytes_sent, bytes_received; @@ -107,7 +93,6 @@ extern pthread_mutex_t LOCK_bytes_sent , LOCK_bytes_received; ** can't normally do this the client should have a bigger max-buffer. */ -#define TEST_BLOCKING 8 static int net_write_buff(NET *net,const char *packet, size_t len); @@ -115,8 +100,12 @@ static int net_write_buff(NET *net,const char *packet, size_t len); int my_net_init(NET *net, MARIADB_PVIO* pvio) { - if (!(net->buff=(uchar*) my_malloc(net_buffer_length,MYF(MY_WME | MY_ZEROFILL)))) + if (!(net->buff=(uchar*) calloc(1, net_buffer_length))) return 1; + + /* We don't allocate memory for multi buffer, since we don't know in advance if the server + * supports COM_MULTI comand. It will be allocated on demand in net_add_multi_command */ + max_allowed_packet= net->max_packet_size= MAX(net_buffer_length, max_allowed_packet); net->buff_end=net->buff+(net->max_packet=net_buffer_length); net->pvio = pvio; @@ -141,61 +130,64 @@ int my_net_init(NET *net, MARIADB_PVIO* pvio) void net_end(NET *net) { - my_free((gptr) net->buff); + free(net->buff); + free(net->mbuff); net->buff=0; + net->mbuff= 0; } /* Realloc the packet buffer */ -static my_bool net_realloc(NET *net, size_t length) +static my_bool net_realloc(NET *net, my_bool is_multi, size_t length) { uchar *buff; size_t pkt_length; - DBUG_ENTER("net_realloc"); - DBUG_PRINT("info", ("length: %lu max_allowed_packet: %lu", - (ulong)length, max_allowed_packet)); - if (length >= net->max_packet_size) { - DBUG_PRINT("error",("Packet too large (%lu)", length)); net->error=1; net->last_errno=ER_NET_PACKET_TOO_LARGE; - DBUG_RETURN(1); + return(1); } pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1); /* reallocate buffer: size= pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE */ - if (!(buff=(uchar*) my_realloc((char*) net->buff, - pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE, - MYF(MY_WME)))) + if (!(buff=(uchar*) realloc(is_multi ? net->mbuff : net->buff, + pkt_length + NET_HEADER_SIZE + COMP_HEADER_SIZE))) { - DBUG_PRINT("info", ("Out of memory")); net->error=1; - DBUG_RETURN(1); + return(1); } - net->buff=net->write_pos=buff; - net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length); - DBUG_RETURN(0); + if (!is_multi) + { + net->buff=net->write_pos=buff; + net->buff_end=buff+(net->max_packet=(unsigned long)pkt_length); + } + else + { + net->mbuff=net->mbuff_pos=buff; + net->mbuff_end=buff+(net->max_packet=(unsigned long)pkt_length); + } + return(0); } /* Remove unwanted characters from connection */ void net_clear(NET *net) { // size_t len; - DBUG_ENTER("net_clear"); /* if (net->pvio) ma_pvio_has_data(net->pvio, &len); */ net->compress_pkt_nr= net->pkt_nr=0; /* Ready for new command */ net->write_pos=net->buff; - DBUG_VOID_RETURN; + if (net->mbuff) + net->mbuff_pos= net->mbuff; + return; } /* Flush write_buffer if not empty. */ int net_flush(NET *net) { int error=0; - DBUG_ENTER("net_flush"); if (net->buff != net->write_pos) { @@ -205,7 +197,7 @@ int net_flush(NET *net) } if (net->compress) net->pkt_nr= net->compress_pkt_nr; - DBUG_RETURN(error); + return(error); } /***************************************************************************** @@ -220,7 +212,7 @@ int net_flush(NET *net) */ int -my_net_write(NET *net, const char *packet, size_t len) +my_net_write(NET *net, const uchar *packet, size_t len) { uchar buff[NET_HEADER_SIZE]; while (len >= MAX_PACKET_LENGTH) @@ -326,6 +318,55 @@ net_write_buff(NET *net,const char *packet, size_t len) return 0; } +int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length) +{ + size_t left_length; + size_t required_length, current_length; + required_length= length + 1 + NET_HEADER_SIZE; + + /* We didn't allocate memory in my_net_init since it was to early to + * detect if the server supports COM_MULTI command */ + if (!net->mbuff) + { + size_t alloc_size= (required_length + IO_SIZE - 1) & ~(IO_SIZE - 1); + if (!(net->mbuff= (char *)malloc(alloc_size))) + { + net->last_errno=ER_OUT_OF_RESOURCES; + net->error=2; + net->reading_or_writing=0; + return(1); + } + net->mbuff_pos= net->mbuff; + net->mbuff_end= net->mbuff + alloc_size; + } + + left_length= net->mbuff_end - net->mbuff_pos; + + /* check if our buffer is large enough */ + if (left_length < required_length) + { + current_length= net->mbuff_pos - net->mbuff; + if (net_realloc(net, 1, current_length + required_length)) + goto error; + } + int3store(net->mbuff_pos, length + 1); + net->mbuff_pos+= 3; + *net->mbuff_pos= command; + net->mbuff_pos++; + memcpy(net->mbuff_pos, packet, length); + net->mbuff_pos+= length; + return 0; + +error: + if (net->mbuff) + { + free(net->mbuff); + net->mbuff= net->mbuff_pos= net->mbuff_end= 0; + } + return 1; +} + /* Read and write using timeouts */ int @@ -333,10 +374,9 @@ net_real_write(NET *net,const char *packet,size_t len) { size_t length; char *pos,*end; - DBUG_ENTER("net_real_write"); if (net->error == 2) - DBUG_RETURN(-1); /* socket can't be used */ + return(-1); /* socket can't be used */ net->reading_or_writing=2; #ifdef HAVE_COMPRESS @@ -345,20 +385,17 @@ net_real_write(NET *net,const char *packet,size_t len) size_t complen; uchar *b; uint header_length=NET_HEADER_SIZE+COMP_HEADER_SIZE; - if (!(b=(uchar*) my_malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1, - MYF(MY_WME)))) + if (!(b=(uchar*) malloc(len + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1))) { net->last_errno=ER_OUT_OF_RESOURCES; net->error=2; net->reading_or_writing=0; - DBUG_RETURN(1); + return(1); } memcpy(b+header_length,packet,len); - if (my_compress((unsigned char*) b+header_length,&len,&complen)) + if (_mariadb_compress((unsigned char*) b+header_length,&len,&complen)) { - DBUG_PRINT("warning", - ("Compression error; Continuing without compression")); complen=0; } int3store(&b[NET_HEADER_SIZE],complen); @@ -377,20 +414,19 @@ net_real_write(NET *net,const char *packet,size_t len) net->error=2; /* Close socket */ net->last_errno= ER_NET_ERROR_ON_WRITE; net->reading_or_writing=0; - DBUG_RETURN(1); + return(1); } pos+=length; statistic_add(bytes_sent,length,&LOCK_bytes_sent); } #ifdef HAVE_COMPRESS if (net->compress) - my_free((char*) packet); + free((char*) packet); #endif net->reading_or_writing=0; - DBUG_RETURN(((int) (pos != end))); + return(((int) (pos != end))); } - /***************************************************************************** ** Read something from server/clinet *****************************************************************************/ @@ -430,10 +466,6 @@ my_real_read(NET *net, size_t *complen) { if (net->buff[net->where_b] != (uchar) 255) { - DBUG_PRINT("error", - ("Packets out of order (Found: %d, expected %d)", - (int) net->buff[net->where_b + 3], - (uint) (uchar) net->pkt_nr)); #ifdef EXTRA_DEBUG fprintf(stderr,"Packets out of order (Found: %d, expected %d)\n", (int) net->buff[net->where_b + 3], @@ -459,7 +491,7 @@ my_real_read(NET *net, size_t *complen) /* The necessary size of net->buff */ if (helping >= net->max_packet) { - if (net_realloc(net,helping)) + if (net_realloc(net, 0, helping)) { len= packet_error; /* Return error */ goto end; @@ -606,7 +638,7 @@ ulong my_net_read(NET *net) if ((packet_length = my_real_read(net,(size_t *)&complen)) == packet_error) return packet_error; - if (my_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) + if (_mariadb_uncompress((unsigned char*) net->buff + net->where_b, &packet_length, &complen)) { len= packet_error; net->error=2; /* caller will close socket */ diff --git a/libmariadb/password.c b/libmariadb/ma_password.c similarity index 90% rename from libmariadb/password.c rename to libmariadb/ma_password.c index ce0a6af7..6a494fad 100644 --- a/libmariadb/password.c +++ b/libmariadb/ma_password.c @@ -1,4 +1,5 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -35,17 +36,17 @@ This saves a hashed number as a string in the password field. *****************************************************************************/ -#include -#include -#include -#include +#include +#include +#include +#include #include "mysql.h" void randominit(struct rand_struct *rand_st,ulong seed1, ulong seed2) { /* For mysql 3.21.# */ #ifdef HAVE_purify - bzero((char*) rand_st,sizeof(*rand_st)); /* Avoid UMC varnings */ + memset((char*) rand_st, 0m sizeof(*rand_st)); /* Avoid UMC varnings */ #endif rand_st->max_value= 0x3FFFFFFFL; rand_st->max_value_dbl=(double) rand_st->max_value; @@ -114,26 +115,26 @@ void my_crypt(unsigned char *buffer, const unsigned char *s1, const unsigned cha void my_scramble_41(const unsigned char *buffer, const char *scramble, const char *password) { - MYSQL_SHA1_CTX context; + _MA_SHA1_CTX context; unsigned char sha1[SHA1_MAX_LENGTH]; unsigned char sha2[SHA1_MAX_LENGTH]; /* Phase 1: hash password */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); - MYSQL_SHA1Final(sha1, &context); + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char *)password, strlen((char *)password)); + ma_SHA1Final(sha1, &context); /* Phase 2: hash sha1 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); - MYSQL_SHA1Final(sha2, &context); + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char*)sha1, SHA1_MAX_LENGTH); + ma_SHA1Final(sha2, &context); /* Phase 3: hash scramble + sha2 */ - MYSQL_SHA1Init(&context); - MYSQL_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); - MYSQL_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); - MYSQL_SHA1Final((unsigned char *)buffer, &context); + ma_SHA1Init(&context); + ma_SHA1Update(&context, (unsigned char *)scramble, SCRAMBLE_LENGTH); + ma_SHA1Update(&context, (unsigned char*)sha2, SHA1_MAX_LENGTH); + ma_SHA1Final((unsigned char *)buffer, &context); /* let's crypt buffer now */ my_crypt((uchar *)buffer, (const unsigned char *)buffer, (const unsigned char *)sha1, SHA1_MAX_LENGTH); diff --git a/libmariadb/ma_pvio.c b/libmariadb/ma_pvio.c index c4bc98ca..370223a4 100644 --- a/libmariadb/ma_pvio.c +++ b/libmariadb/ma_pvio.c @@ -43,18 +43,18 @@ register callback functions for read and write */ -#include -#include +#include +#include #include -#include +#include #include #include #include #include -#include -#include - -extern pthread_mutex_t THR_LOCK_lock; +#ifdef HAVE_NONBLOCK +#include +#include +#endif /* callback functions for read/write */ LIST *pvio_callback= NULL; @@ -104,8 +104,7 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) } - if (!(pvio= (MARIADB_PVIO *)my_malloc(sizeof(MARIADB_PVIO), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(pvio= (MARIADB_PVIO *)calloc(1, sizeof(MARIADB_PVIO)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); return NULL; @@ -124,9 +123,10 @@ MARIADB_PVIO *ma_pvio_init(MA_PVIO_CINFO *cinfo) pvio->methods->set_timeout(pvio, PVIO_WRITE_TIMEOUT, cinfo->mysql->options.write_timeout); } - if (!(pvio->cache= my_malloc(PVIO_READ_AHEAD_CACHE_SIZE, MYF(MY_ZEROFILL)))) + if (!(pvio->cache= calloc(1, PVIO_READ_AHEAD_CACHE_SIZE))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0); + free(pvio); return NULL; } pvio->cache_size= 0; @@ -177,6 +177,7 @@ my_bool ma_pvio_set_timeout(MARIADB_PVIO *pvio, } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ size_t ma_pvio_read_async */ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t length) { @@ -212,6 +213,7 @@ static size_t ma_pvio_read_async(MARIADB_PVIO *pvio, uchar *buffer, size_t lengt } } /* }}} */ +#endif /* {{{ size_t ma_pvio_read */ size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) @@ -219,13 +221,14 @@ size_t ma_pvio_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) size_t r= -1; if (!pvio) return -1; - +#ifdef HAVE_NONBLOCK if (IS_PVIO_ASYNC_ACTIVE(pvio)) { r= ma_pvio_read_async(pvio, buffer, length); goto end; } else +#endif { if (IS_PVIO_ASYNC(pvio)) { @@ -303,6 +306,7 @@ size_t ma_pvio_cache_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ size_t ma_pvio_write_async */ static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) { @@ -332,6 +336,7 @@ static size_t ma_pvio_write_async(MARIADB_PVIO *pvio, const uchar *buffer, size_ } } /* }}} */ +#endif /* {{{ size_t ma_pvio_write */ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) @@ -350,13 +355,14 @@ size_t ma_pvio_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length) } else #endif -// printf("No ssl (write): %x\n", pvio->cssl); +#ifdef HAVE_NONBLOCK if (IS_PVIO_ASYNC_ACTIVE(pvio)) { r= ma_pvio_write_async(pvio, buffer, length); goto end; } else +#endif { if (IS_PVIO_ASYNC(pvio)) { @@ -386,19 +392,16 @@ void ma_pvio_close(MARIADB_PVIO *pvio) if (pvio && pvio->cssl) { ma_pvio_ssl_close(pvio->cssl); - my_free((gptr)pvio->cssl); + free(pvio->cssl); } #endif if (pvio && pvio->methods->close) pvio->methods->close(pvio); if (pvio->cache) - my_free((gptr)pvio->cache); + free(pvio->cache); - if (pvio->fp) - my_fclose(pvio->fp, MYF(0)); - - my_free((gptr)pvio); + free(pvio); } /* }}} */ @@ -411,6 +414,7 @@ my_bool ma_pvio_get_handle(MARIADB_PVIO *pvio, void *handle) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ ma_pvio_wait_async */ static my_bool ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event, @@ -442,15 +446,17 @@ ma_pvio_wait_async(struct mysql_async_context *b, enum enum_pvio_io_event event, return (b->events_occured & MYSQL_WAIT_TIMEOUT) ? 0 : 1; } /* }}} */ +#endif /* {{{ ma_pvio_wait_io_or_timeout */ int ma_pvio_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout) { +#ifdef HAVE_NONBLOCK if (IS_PVIO_ASYNC_ACTIVE(pvio)) return ma_pvio_wait_async(pvio->mysql->options.extension->async_context, (is_read) ? VIO_IO_EVENT_READ : VIO_IO_EVENT_WRITE, timeout); - +#endif if (pvio && pvio->methods->wait_io_or_timeout) return pvio->methods->wait_io_or_timeout(pvio, is_read, timeout); @@ -511,7 +517,7 @@ my_bool ma_pvio_start_ssl(MARIADB_PVIO *pvio) } if (ma_pvio_ssl_connect(pvio->cssl)) { - my_free(pvio->cssl); + free(pvio->cssl); pvio->cssl= NULL; return 1; } diff --git a/libmariadb/ma_sha1.c b/libmariadb/ma_sha1.c new file mode 100644 index 00000000..04c5760e --- /dev/null +++ b/libmariadb/ma_sha1.c @@ -0,0 +1,326 @@ +/**************************************************************************** + Copyright (C) 2012 Monty Program AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not see + or write to the Free Software Foundation, Inc., + 51 Franklin St., Fifth Floor, Boston, MA 02110, USA + *****************************************************************************/ + +/* This code came from the PHP project, initially written by + Stefan Esser */ + + +#include "ma_global.h" +#include "string.h" + +/* This code is heavily based on the PHP md5 implementation */ + +#include "ma_sha1.h" + + +static void ma_SHA1Transform(uint32[5], const unsigned char[64]); +static void ma_SHA1Encode(unsigned char *, uint32 *, unsigned int); +static void ma_SHA1Decode(uint32 *, const unsigned char *, unsigned int); + +static unsigned char PADDING[64] = +{ + 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; + +/* F, G, H and I are basic SHA1 functions. +*/ +#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) +#define G(x, y, z) ((x) ^ (y) ^ (z)) +#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) +#define I(x, y, z) ((x) ^ (y) ^ (z)) + +/* ROTATE_LEFT rotates x left n bits. +*/ +#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) + +/* W[i] +*/ +#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ + (x[i&15]=ROTATE_LEFT(tmp, 1)) ) + +/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. +*/ +#define FF(a, b, c, d, e, w) { \ + (e) += F ((b), (c), (d)) + (w) + (uint32)(0x5A827999); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define GG(a, b, c, d, e, w) { \ + (e) += G ((b), (c), (d)) + (w) + (uint32)(0x6ED9EBA1); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define HH(a, b, c, d, e, w) { \ + (e) += H ((b), (c), (d)) + (w) + (uint32)(0x8F1BBCDC); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} +#define II(a, b, c, d, e, w) { \ + (e) += I ((b), (c), (d)) + (w) + (uint32)(0xCA62C1D6); \ + (e) += ROTATE_LEFT ((a), 5); \ + (b) = ROTATE_LEFT((b), 30); \ +} + + +/* {{{ ma_SHA1Init + * SHA1 initialization. Begins an SHA1 operation, writing a new context. + */ +void ma_SHA1Init(_MA_SHA1_CTX * context) +{ + context->count[0] = context->count[1] = 0; + /* Load magic initialization constants. + */ + context->state[0] = 0x67452301; + context->state[1] = 0xefcdab89; + context->state[2] = 0x98badcfe; + context->state[3] = 0x10325476; + context->state[4] = 0xc3d2e1f0; +} +/* }}} */ + +/* {{{ ma_SHA1Update + SHA1 block update operation. Continues an SHA1 message-digest + operation, processing another message block, and updating the + context. + */ +void ma_SHA1Update(_MA_SHA1_CTX * context, const unsigned char *input, + size_t inputLen) +{ + unsigned int i, index, partLen; + + /* Compute number of bytes mod 64 */ + index = (unsigned int) ((context->count[0] >> 3) & 0x3F); + + /* Update number of bits */ + if ((context->count[0] += ((uint32) inputLen << 3)) + < ((uint32) inputLen << 3)) + context->count[1]++; + context->count[1] += ((uint32) inputLen >> 29); + + partLen = 64 - index; + + /* Transform as many times as possible. + */ + if (inputLen >= partLen) { + memcpy + ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); + ma_SHA1Transform(context->state, context->buffer); + + for (i = partLen; i + 63 < inputLen; i += 64) + ma_SHA1Transform(context->state, &input[i]); + + index = 0; + } else + i = 0; + + /* Buffer remaining input */ + memcpy + ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], + inputLen - i); +} +/* }}} */ + +/* {{{ ma_SHA1Final + SHA1 finalization. Ends an SHA1 message-digest operation, writing the + the message digest and zeroizing the context. + */ +void ma_SHA1Final(unsigned char digest[20], _MA_SHA1_CTX * context) +{ + unsigned char bits[8]; + unsigned int index, padLen; + + /* Save number of bits */ + bits[7] = context->count[0] & 0xFF; + bits[6] = (context->count[0] >> 8) & 0xFF; + bits[5] = (context->count[0] >> 16) & 0xFF; + bits[4] = (context->count[0] >> 24) & 0xFF; + bits[3] = context->count[1] & 0xFF; + bits[2] = (context->count[1] >> 8) & 0xFF; + bits[1] = (context->count[1] >> 16) & 0xFF; + bits[0] = (context->count[1] >> 24) & 0xFF; + + /* Pad out to 56 mod 64. + */ + index = (unsigned int) ((context->count[0] >> 3) & 0x3f); + padLen = (index < 56) ? (56 - index) : (120 - index); + ma_SHA1Update(context, PADDING, padLen); + + /* Append length (before padding) */ + ma_SHA1Update(context, bits, 8); + + /* Store state in digest */ + ma_SHA1Encode(digest, context->state, 20); + + /* Zeroize sensitive information. + */ + memset((unsigned char*) context, 0, sizeof(*context)); +} +/* }}} */ + +/* {{{ ma_SHA1Transform + * SHA1 basic transformation. Transforms state based on block. + */ +static void ma_SHA1Transform(uint32 state[5], const unsigned char block[64]) +{ + uint32 a = state[0], b = state[1], c = state[2]; + uint32 d = state[3], e = state[4], x[16], tmp; + + ma_SHA1Decode(x, block, 64); + + /* Round 1 */ + FF(a, b, c, d, e, x[0]); /* 1 */ + FF(e, a, b, c, d, x[1]); /* 2 */ + FF(d, e, a, b, c, x[2]); /* 3 */ + FF(c, d, e, a, b, x[3]); /* 4 */ + FF(b, c, d, e, a, x[4]); /* 5 */ + FF(a, b, c, d, e, x[5]); /* 6 */ + FF(e, a, b, c, d, x[6]); /* 7 */ + FF(d, e, a, b, c, x[7]); /* 8 */ + FF(c, d, e, a, b, x[8]); /* 9 */ + FF(b, c, d, e, a, x[9]); /* 10 */ + FF(a, b, c, d, e, x[10]); /* 11 */ + FF(e, a, b, c, d, x[11]); /* 12 */ + FF(d, e, a, b, c, x[12]); /* 13 */ + FF(c, d, e, a, b, x[13]); /* 14 */ + FF(b, c, d, e, a, x[14]); /* 15 */ + FF(a, b, c, d, e, x[15]); /* 16 */ + FF(e, a, b, c, d, W(16)); /* 17 */ + FF(d, e, a, b, c, W(17)); /* 18 */ + FF(c, d, e, a, b, W(18)); /* 19 */ + FF(b, c, d, e, a, W(19)); /* 20 */ + + /* Round 2 */ + GG(a, b, c, d, e, W(20)); /* 21 */ + GG(e, a, b, c, d, W(21)); /* 22 */ + GG(d, e, a, b, c, W(22)); /* 23 */ + GG(c, d, e, a, b, W(23)); /* 24 */ + GG(b, c, d, e, a, W(24)); /* 25 */ + GG(a, b, c, d, e, W(25)); /* 26 */ + GG(e, a, b, c, d, W(26)); /* 27 */ + GG(d, e, a, b, c, W(27)); /* 28 */ + GG(c, d, e, a, b, W(28)); /* 29 */ + GG(b, c, d, e, a, W(29)); /* 30 */ + GG(a, b, c, d, e, W(30)); /* 31 */ + GG(e, a, b, c, d, W(31)); /* 32 */ + GG(d, e, a, b, c, W(32)); /* 33 */ + GG(c, d, e, a, b, W(33)); /* 34 */ + GG(b, c, d, e, a, W(34)); /* 35 */ + GG(a, b, c, d, e, W(35)); /* 36 */ + GG(e, a, b, c, d, W(36)); /* 37 */ + GG(d, e, a, b, c, W(37)); /* 38 */ + GG(c, d, e, a, b, W(38)); /* 39 */ + GG(b, c, d, e, a, W(39)); /* 40 */ + + /* Round 3 */ + HH(a, b, c, d, e, W(40)); /* 41 */ + HH(e, a, b, c, d, W(41)); /* 42 */ + HH(d, e, a, b, c, W(42)); /* 43 */ + HH(c, d, e, a, b, W(43)); /* 44 */ + HH(b, c, d, e, a, W(44)); /* 45 */ + HH(a, b, c, d, e, W(45)); /* 46 */ + HH(e, a, b, c, d, W(46)); /* 47 */ + HH(d, e, a, b, c, W(47)); /* 48 */ + HH(c, d, e, a, b, W(48)); /* 49 */ + HH(b, c, d, e, a, W(49)); /* 50 */ + HH(a, b, c, d, e, W(50)); /* 51 */ + HH(e, a, b, c, d, W(51)); /* 52 */ + HH(d, e, a, b, c, W(52)); /* 53 */ + HH(c, d, e, a, b, W(53)); /* 54 */ + HH(b, c, d, e, a, W(54)); /* 55 */ + HH(a, b, c, d, e, W(55)); /* 56 */ + HH(e, a, b, c, d, W(56)); /* 57 */ + HH(d, e, a, b, c, W(57)); /* 58 */ + HH(c, d, e, a, b, W(58)); /* 59 */ + HH(b, c, d, e, a, W(59)); /* 60 */ + + /* Round 4 */ + II(a, b, c, d, e, W(60)); /* 61 */ + II(e, a, b, c, d, W(61)); /* 62 */ + II(d, e, a, b, c, W(62)); /* 63 */ + II(c, d, e, a, b, W(63)); /* 64 */ + II(b, c, d, e, a, W(64)); /* 65 */ + II(a, b, c, d, e, W(65)); /* 66 */ + II(e, a, b, c, d, W(66)); /* 67 */ + II(d, e, a, b, c, W(67)); /* 68 */ + II(c, d, e, a, b, W(68)); /* 69 */ + II(b, c, d, e, a, W(69)); /* 70 */ + II(a, b, c, d, e, W(70)); /* 71 */ + II(e, a, b, c, d, W(71)); /* 72 */ + II(d, e, a, b, c, W(72)); /* 73 */ + II(c, d, e, a, b, W(73)); /* 74 */ + II(b, c, d, e, a, W(74)); /* 75 */ + II(a, b, c, d, e, W(75)); /* 76 */ + II(e, a, b, c, d, W(76)); /* 77 */ + II(d, e, a, b, c, W(77)); /* 78 */ + II(c, d, e, a, b, W(78)); /* 79 */ + II(b, c, d, e, a, W(79)); /* 80 */ + + state[0] += a; + state[1] += b; + state[2] += c; + state[3] += d; + state[4] += e; + + /* Zeroize sensitive information. */ + memset((unsigned char*) x, 0, sizeof(x)); +} +/* }}} */ + +/* {{{ ma_SHA1Encode + Encodes input (uint32) into output (unsigned char). Assumes len is + a multiple of 4. + */ +static void ma_SHA1Encode(unsigned char *output, uint32 *input, unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) { + output[j] = (unsigned char) ((input[i] >> 24) & 0xff); + output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); + output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); + output[j + 3] = (unsigned char) (input[i] & 0xff); + } +} +/* }}} */ + +/* {{{ ma_SHA1Decode + Decodes input (unsigned char) into output (uint32). Assumes len is + a multiple of 4. + */ +static void ma_SHA1Decode(uint32 *output, const unsigned char * input, unsigned int len) +{ + unsigned int i, j; + + for (i = 0, j = 0; j < len; i++, j += 4) + output[i] = ((uint32) input[j + 3]) | (((uint32) input[j + 2]) << 8) | + (((uint32) input[j + 1]) << 16) | (((uint32) input[j]) << 24); +} +/* }}} */ + +/* + * Local variables: + * tab-width: 4 + * c-basic-offset: 4 + * End: + * vim600: sw=4 ts=4 fdm=marker + * vim<600: sw=4 ts=4 + */ diff --git a/libmariadb/ma_ssl.c b/libmariadb/ma_ssl.c index 772c90b7..ff9f5bc6 100644 --- a/libmariadb/ma_ssl.c +++ b/libmariadb/ma_ssl.c @@ -32,20 +32,19 @@ #ifdef HAVE_SSL -#include -#include +#include +#include #include #include -//#include -#include +#include #include #include #include -/* -#include -#include -*/ +#ifdef HAVE_NONBLOCK +#include +#include +#endif /* Errors should be handled via pvio callback function */ my_bool ma_ssl_initialized= FALSE; @@ -60,8 +59,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) if (!ma_ssl_initialized) ma_ssl_start(mysql->net.last_error, MYSQL_ERRMSG_SIZE); - if (!(cssl= (MARIADB_SSL *)my_malloc(sizeof(MARIADB_SSL), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(cssl= (MARIADB_SSL *)calloc(1, sizeof(MARIADB_SSL)))) { return NULL; } @@ -70,7 +68,7 @@ MARIADB_SSL *ma_pvio_ssl_init(MYSQL *mysql) cssl->pvio= mysql->net.pvio; if (!(cssl->ssl= ma_ssl_init(mysql))) { - my_free(cssl); + free(cssl); cssl= NULL; } return cssl; diff --git a/libmariadb/my_stmt_codec.c b/libmariadb/ma_stmt_codec.c similarity index 97% rename from libmariadb/my_stmt_codec.c rename to libmariadb/ma_stmt_codec.c index 34c4c0ff..f47487bc 100644 --- a/libmariadb/my_stmt_codec.c +++ b/libmariadb/ma_stmt_codec.c @@ -43,11 +43,10 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include -#include +#include "ma_global.h" +#include +#include +#include #include "mysql.h" #define MYSQL_SILENT @@ -222,7 +221,7 @@ my_bool str_to_TIME(const char *str, size_t length, MYSQL_TIME *tm) } -static void convert_from_string(MYSQL_BIND *r_param, char *buffer, size_t len) +static void convert_froma_string(MYSQL_BIND *r_param, char *buffer, size_t len) { int error= 0; switch (r_param->buffer_type) @@ -363,12 +362,12 @@ static void convert_from_long(MYSQL_BIND *r_param, const MYSQL_FIELD *field, lon char *endptr; uint len; - endptr= longlong10_to_str(val, buffer, is_unsigned ? 10 : -10); + endptr= ma_ll2str(val, buffer, is_unsigned ? 10 : -10); len= (uint)(endptr - buffer); /* check if field flag is zerofill */ - convert_from_string(r_param, buffer, len); + convert_froma_string(r_param, buffer, len); } break; } @@ -493,6 +492,11 @@ void ps_fetch_int64(MYSQL_BIND *r_param, const MYSQL_FIELD * const field, } /* }}} */ +void ma_bmove_upp(register char *dst, register const char *src, register size_t len) +{ + while (len-- != 0) *--dst = *--src; +} + static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, double val, int size) { double check_trunc_val= (val > 0) ? floor(val) : -floor(-val); @@ -569,8 +573,8 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do { #define MAX_DOUBLE_STRING_REP_LENGTH 300 char buff[MAX_DOUBLE_STRING_REP_LENGTH]; - char *end; size_t length; + char *end; length= MIN(MAX_DOUBLE_STRING_REP_LENGTH - 1, r_param->buffer_length); @@ -585,9 +589,10 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do length= strlen(buff); } - /* remove possible trailing blanks */ - if ((end= strcend(buff, ' '))) - *end= 0; + /* remove trailing blanks */ + end= strchr(buff, '\0') - 1; + while (end > buff && *end == ' ') + *end--= '\0'; /* check if ZEROFILL flag is active */ if (field->flags & ZEROFILL_FLAG) @@ -595,10 +600,10 @@ static void convert_from_float(MYSQL_BIND *r_param, const MYSQL_FIELD *field, do /* enough space available ? */ if (field->length < length || field->length > MAX_DOUBLE_STRING_REP_LENGTH - 1) break; - bmove_upp(buff + field->length, buff + length, length); - bfill((char*) buff, field->length - length, '0'); + ma_bmove_upp(buff + field->length, buff + length, length); + memset((char*) buff, 0, field->length - length); } - convert_from_string(r_param, buff, strlen(buff)); + convert_froma_string(r_param, buff, strlen(buff)); } break; } @@ -781,7 +786,7 @@ void ps_fetch_datetime(MYSQL_BIND *r_param, const MYSQL_FIELD * field, length= 0; break; } - convert_from_string(r_param, dtbuffer, length); + convert_froma_string(r_param, dtbuffer, length); break; } } @@ -800,7 +805,7 @@ void ps_fetch_string(MYSQL_BIND *r_param, const MYSQL_FIELD *field, */ ulong field_length= net_field_length(row); - convert_from_string(r_param, (char *)*row, field_length); + convert_froma_string(r_param, (char *)*row, field_length); (*row) += field_length; } /* }}} */ diff --git a/libmariadb/string.c b/libmariadb/ma_string.c similarity index 69% rename from libmariadb/string.c rename to libmariadb/ma_string.c index aba0ba83..18c9bef7 100644 --- a/libmariadb/string.c +++ b/libmariadb/ma_string.c @@ -1,5 +1,6 @@ /* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - + 2016 MariaDB Corporation AB + This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either @@ -21,14 +22,15 @@ By monty. */ -#include "mysys_priv.h" -#include +#include +#include +#include + +my_bool ma_init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, -my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, size_t init_alloc, size_t alloc_increment) { uint length; - DBUG_ENTER("init_dynamic_string"); if (!alloc_increment) alloc_increment=128; @@ -38,21 +40,19 @@ my_bool init_dynamic_string(DYNAMIC_STRING *str, const char *init_str, if (!init_alloc) init_alloc=alloc_increment; - if (!(str->str=(char*) my_malloc(init_alloc,MYF(MY_WME)))) - DBUG_RETURN(TRUE); + if (!(str->str=(char*) malloc(init_alloc))) + return(TRUE); str->length=length-1; if (init_str) memcpy(str->str,init_str,length); str->max_length=init_alloc; str->alloc_increment=alloc_increment; - DBUG_RETURN(FALSE); + return(FALSE); } - -my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) +my_bool ma_dynstr_set(DYNAMIC_STRING *str, const char *init_str) { uint length; - DBUG_ENTER("dynstr_set"); if (init_str && (length= (uint) strlen(init_str)+1) > str->max_length) { @@ -60,8 +60,8 @@ my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) str->alloc_increment; if (!str->max_length) str->max_length=str->alloc_increment; - if (!(str->str=(char*) my_realloc(str->str,str->max_length,MYF(MY_WME)))) - DBUG_RETURN(TRUE); + if (!(str->str=(char*) realloc(str->str,str->max_length))) + return(TRUE); } if (init_str) { @@ -70,33 +70,31 @@ my_bool dynstr_set(DYNAMIC_STRING *str, const char *init_str) } else str->length=0; - DBUG_RETURN(FALSE); + return(FALSE); } -my_bool dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) +my_bool ma_dynstr_realloc(DYNAMIC_STRING *str, size_t additional_size) { - DBUG_ENTER("dynstr_realloc"); - - if (!additional_size) DBUG_RETURN(FALSE); + if (!additional_size) return(FALSE); if (str->length + additional_size > str->max_length) { str->max_length=((str->length + additional_size+str->alloc_increment-1)/ str->alloc_increment)*str->alloc_increment; - if (!(str->str=(char*) my_realloc(str->str,str->max_length,MYF(MY_WME)))) - DBUG_RETURN(TRUE); + if (!(str->str=(char*) realloc(str->str,str->max_length))) + return(TRUE); } - DBUG_RETURN(FALSE); + return(FALSE); } -my_bool dynstr_append(DYNAMIC_STRING *str, const char *append) +my_bool ma_dynstr_append(DYNAMIC_STRING *str, const char *append) { - return dynstr_append_mem(str,append,strlen(append)); + return ma_dynstr_append_mem(str,append,strlen(append)); } -my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, +my_bool ma_dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t length) { char *new_ptr; @@ -105,7 +103,7 @@ my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, size_t new_length=(str->length+length+str->alloc_increment)/ str->alloc_increment; new_length*=str->alloc_increment; - if (!(new_ptr=(char*) my_realloc(str->str,new_length,MYF(MY_WME)))) + if (!(new_ptr=(char*) realloc(str->str,new_length))) return TRUE; str->str=new_ptr; str->max_length=new_length; @@ -117,11 +115,13 @@ my_bool dynstr_append_mem(DYNAMIC_STRING *str, const char *append, } -void dynstr_free(DYNAMIC_STRING *str) +void ma_dynstr_free(DYNAMIC_STRING *str) { if (str->str) { - my_free(str->str); + free(str->str); str->str=0; } } + + diff --git a/libmariadb/ma_time.c b/libmariadb/ma_time.c index 0b755064..5b4087b0 100644 --- a/libmariadb/ma_time.c +++ b/libmariadb/ma_time.c @@ -1,5 +1,6 @@ /**************************************************************************** Copyright (C) 2013 Monty Program AB + 2016 MariaDB Corporation AB This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public @@ -19,8 +20,7 @@ Part of this code includes code from the PHP project which is freely available from http://www.php.net *****************************************************************************/ -#include "mysys_priv.h" -#include +#include #include #include diff --git a/libmariadb/mysql_async.c b/libmariadb/mariadb_async.c similarity index 97% rename from libmariadb/mysql_async.c rename to libmariadb/mariadb_async.c index f7dfc998..922658ea 100644 --- a/libmariadb/mysql_async.c +++ b/libmariadb/mariadb_async.c @@ -19,19 +19,18 @@ MySQL non-blocking client library functions. */ -#include "my_global.h" -#include "my_sys.h" +#include "ma_global.h" +#include "ma_sys.h" #include "mysql.h" -#include "errmsg.h" +#include "ma_errmsg.h" #ifndef LIBMARIADB #include "sql_common.h" #else -#include "mysql_com.h" #include "ma_common.h" #endif -#include "my_context.h" +#include "ma_context.h" #include "ma_pvio.h" -#include "mysql_async.h" +#include "mariadb_async.h" #include @@ -186,29 +185,8 @@ my_ssl_write_async(struct mysql_async_context *b, SSL *ssl, } #endif /* HAVE_OPENSSL */ -/* - Legacy support of the MariaDB 5.5 version, where timeouts where only in - seconds resolution. Applications that use this will be asked to set a timeout - at the nearest higher whole-seconds value. -*/ -unsigned int STDCALL -mysql_get_timeout_value(const MYSQL *mysql) -{ - unsigned int timeout= mysql->options.extension->async_context->timeout_value; - /* Avoid overflow. */ - if (timeout > UINT_MAX - 999) - return (timeout - 1)/1000 + 1; - else - return (timeout+999)/1000; -} -unsigned int STDCALL -mysql_get_timeout_value_ms(const MYSQL *mysql) -{ - return mysql->options.extension->async_context->timeout_value; -} - /* Now create non-blocking definitions for all the calls that may block. @@ -250,7 +228,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) } \ if (res < 0) \ { \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ *ret= err_val; \ } \ else \ @@ -263,7 +241,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) (mysql_val)->options.extension->async_context; \ if (!b->suspended) \ { \ - set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ *ret= err_val; \ return 0; \ } \ @@ -277,7 +255,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) b->suspended= 0; \ if (res < 0) \ { \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ *ret= err_val; \ } \ else \ @@ -311,7 +289,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) return b->events_to_wait_for; \ } \ if (res < 0) \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ return 0; #define MK_ASYNC_CONT_BODY_VOID_RETURN(mysql_val) \ @@ -320,7 +298,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) (mysql_val)->options.extension->async_context; \ if (!b->suspended) \ { \ - set_mysql_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_COMMANDS_OUT_OF_SYNC, unknown_sqlstate); \ return 0; \ } \ \ @@ -332,7 +310,7 @@ mysql_get_timeout_value_ms(const MYSQL *mysql) return b->events_to_wait_for; /* (Still) suspended */ \ b->suspended= 0; \ if (res < 0) \ - set_mysql_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ + set_mariadb_error((mysql_val), CR_OUT_OF_MEMORY, unknown_sqlstate); \ return 0; @@ -432,7 +410,7 @@ mysql_real_query_start(int *ret, MYSQL *mysql, const char *stmt_str, size_t leng } if (res < 0) { - set_mysql_error((mysql), CR_OUT_OF_MEMORY, unknown_sqlstate); + set_mariadb_error((mysql), CR_OUT_OF_MEMORY, unknown_sqlstate); *ret= 1; } else diff --git a/libmariadb/mariadb_charset.c b/libmariadb/mariadb_charset.c new file mode 100644 index 00000000..e78f6777 --- /dev/null +++ b/libmariadb/mariadb_charset.c @@ -0,0 +1,74 @@ +/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB + 2016 MariaDB Corporation AB + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public + License along with this library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + MA 02111-1307, USA */ + +#include +#include +// #include "mysys_err.h" +#include +#include + +MARIADB_CHARSET_INFO *ma_default_charset_info = (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5]; +MARIADB_CHARSET_INFO *ma_charset_bin= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[32]; +MARIADB_CHARSET_INFO *ma_charset_latin1= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[5]; +MARIADB_CHARSET_INFO *ma_charset_utf8_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[21]; +MARIADB_CHARSET_INFO *ma_charset_utf16le_general_ci= (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[68]; + +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_nr(uint cs_number) +{ + int i= 0; + + while (mariadb_compiled_charsets[i].nr && cs_number != mariadb_compiled_charsets[i].nr) + i++; + + return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL; +} + +my_bool set_default_charset(uint cs, myf flags) +{ + MARIADB_CHARSET_INFO *new_charset; + new_charset = mysql_get_charset_by_nr(cs); + if (!new_charset) + { + return(TRUE); /* error */ + } + ma_default_charset_info = new_charset; + return(FALSE); +} + +MARIADB_CHARSET_INFO * STDCALL mysql_get_charset_by_name(const char *cs_name) +{ + int i= 0; + + while (mariadb_compiled_charsets[i].nr && strcmp(cs_name, mariadb_compiled_charsets[i].csname) != 0) + i++; + + return (mariadb_compiled_charsets[i].nr) ? (MARIADB_CHARSET_INFO *)&mariadb_compiled_charsets[i] : NULL; +} + +my_bool set_default_charset_by_name(const char *cs_name, myf flags) +{ + MARIADB_CHARSET_INFO *new_charset; + new_charset = mysql_get_charset_by_name(cs_name); + if (!new_charset) + { + return(TRUE); /* error */ + } + + ma_default_charset_info = new_charset; + return(FALSE); +} diff --git a/libmariadb/ma_dyncol.c b/libmariadb/mariadb_dyncol.c similarity index 95% rename from libmariadb/ma_dyncol.c rename to libmariadb/mariadb_dyncol.c index aa8391b6..9f06d29a 100644 --- a/libmariadb/ma_dyncol.c +++ b/libmariadb/mariadb_dyncol.c @@ -61,25 +61,25 @@ */ #include -#include "mysys_priv.h" -#include -#include -#include -#include +#include +#include +#include +#include +#include #include #ifndef LIBMARIADB -uint32 copy_and_convert(char *to, uint32 to_length, CHARSET_INFO *to_cs, +uint32 copy_and_convert(char *to, uint32 to_length, MARIADB_CHARSET_INFO *to_cs, const char *from, uint32 from_length, - CHARSET_INFO *from_cs, uint *errors); + MARIADB_CHARSET_INFO *from_cs, uint *errors); #else size_t mariadb_time_to_string(const MYSQL_TIME *tm, char *time_str, size_t len, unsigned int digits); -size_t STDCALL mariadb_convert_string(const char *from, size_t *from_len, CHARSET_INFO *from_cs, - char *to, size_t *to_len, CHARSET_INFO *to_cs, int *errorcode); +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); #endif /* Flag byte bits @@ -705,7 +705,7 @@ static my_bool dynamic_column_init_named(DYNAMIC_COLUMN *str, size_t size) - First \0 is flags - other 2 \0 is number of fields */ - if (init_dynamic_string(str, NULL, size, DYNCOL_SYZERESERVE)) + if (ma_init_dynamic_string(str, NULL, size, DYNCOL_SYZERESERVE)) return TRUE; return FALSE; } @@ -749,7 +749,7 @@ static size_t dynamic_column_var_uint_bytes(ulonglong val) static enum enum_dyncol_func_result dynamic_column_var_uint_store(DYNAMIC_COLUMN *str, ulonglong val) { - if (dynstr_realloc(str, 10)) /* max what we can use */ + if (ma_dynstr_realloc(str, 10)) /* max what we can use */ return ER_DYNCOL_RESOURCE; do @@ -829,7 +829,7 @@ static size_t dynamic_column_uint_bytes(ulonglong val) static enum enum_dyncol_func_result dynamic_column_uint_store(DYNAMIC_COLUMN *str, ulonglong val) { - if (dynstr_realloc(str, 8)) /* max what we can use */ + if (ma_dynstr_realloc(str, 8)) /* max what we can use */ return ER_DYNCOL_RESOURCE; for (; val; val>>= 8) @@ -1022,7 +1022,7 @@ dynamic_column_value_len(DYNAMIC_COLUMN_VALUE *value, static enum enum_dyncol_func_result dynamic_column_double_store(DYNAMIC_COLUMN *str, double val) { - if (dynstr_realloc(str, 8)) + if (ma_dynstr_realloc(str, 8)) return ER_DYNCOL_RESOURCE; float8store(str->str + str->length, val); str->length+= 8; @@ -1062,7 +1062,7 @@ dynamic_column_double_read(DYNAMIC_COLUMN_VALUE *store_it_here, static enum enum_dyncol_func_result dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, - CHARSET_INFO *charset) + MARIADB_CHARSET_INFO *charset) { enum enum_dyncol_func_result rc; #ifdef LIBMARIADB @@ -1071,7 +1071,7 @@ dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, if ((rc= dynamic_column_var_uint_store(str, charset->number))) #endif return rc; - if (dynstr_append_mem(str, string->str, string->length)) + if (ma_dynstr_append_mem(str, string->str, string->length)) return ER_DYNCOL_RESOURCE; return ER_DYNCOL_OK; } @@ -1088,7 +1088,7 @@ dynamic_column_string_store(DYNAMIC_COLUMN *str, LEX_STRING *string, static enum enum_dyncol_func_result dynamic_column_dyncol_store(DYNAMIC_COLUMN *str, LEX_STRING *string) { - if (dynstr_append_mem(str, string->str, string->length)) + if (ma_dynstr_append_mem(str, string->str, string->length)) return ER_DYNCOL_RESOURCE; return ER_DYNCOL_OK; } @@ -1139,7 +1139,7 @@ static enum enum_dyncol_func_result dynamic_column_dyncol_read(DYNAMIC_COLUMN_VALUE *store_it_here, uchar *data, size_t length) { - store_it_here->x.string.charset= my_charset_bin; + store_it_here->x.string.charset= ma_charset_bin; store_it_here->x.string.value.length= length; store_it_here->x.string.value.str= (char*) data; return ER_DYNCOL_OK; @@ -1166,7 +1166,7 @@ dynamic_column_decimal_store(DYNAMIC_COLUMN *str, return ER_DYNCOL_OK; bin_size= decimal_bin_size(precision, value->frac); - if (dynstr_realloc(str, bin_size + 20)) + if (ma_dynstr_realloc(str, bin_size + 20)) return ER_DYNCOL_RESOURCE; /* The following can't fail as memory is already allocated */ @@ -1321,7 +1321,7 @@ dynamic_column_time_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value, enum enum_dyncol_format format) { uchar *buf; - if (dynstr_realloc(str, 6)) + if (ma_dynstr_realloc(str, 6)) return ER_DYNCOL_RESOURCE; buf= ((uchar *)str->str) + str->length; @@ -1464,7 +1464,7 @@ static enum enum_dyncol_func_result dynamic_column_date_store(DYNAMIC_COLUMN *str, MYSQL_TIME *value) { uchar *buf; - if (dynstr_realloc(str, 3)) + if (ma_dynstr_realloc(str, 3)) return ER_DYNCOL_RESOURCE; buf= ((uchar *)str->str) + str->length; @@ -1668,7 +1668,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str, else { str->length= 0; - if (dynstr_realloc(str, + if (ma_dynstr_realloc(str, fmt->fixed_hdr + hdr->header_size + hdr->nmpool_size + @@ -1679,7 +1679,7 @@ dynamic_new_column_store(DYNAMIC_COLUMN *str, if (!column_count) return ER_DYNCOL_OK; - bzero(str->str, fmt->fixed_hdr); + memset(str->str, 0, fmt->fixed_hdr); str->length= fmt->fixed_hdr; /* sort columns for the header */ @@ -1813,13 +1813,13 @@ dynamic_column_create_many_internal_fmt(DYNAMIC_COLUMN *str, { DYN_HEADER header; enum enum_dyncol_func_result rc; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); header.format= (string_keys ? 1 : 0); if (new_str) { /* to make dynstr_free() working in case of errors */ - bzero(str, sizeof(DYNAMIC_COLUMN)); + memset(str, 0, sizeof(DYNAMIC_COLUMN)); } if ((rc= calc_var_sizes(&header, column_count, column_keys, values)) < 0) @@ -1849,8 +1849,7 @@ dynamic_column_create_many(DYNAMIC_COLUMN *str, uint *column_numbers, DYNAMIC_COLUMN_VALUE *values) { - DBUG_ENTER("dynamic_column_create_many"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_numbers, values, TRUE, FALSE)); } @@ -1874,8 +1873,7 @@ mariadb_dyncol_create_many_num(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *values, my_bool new_string) { - DBUG_ENTER("mariadb_dyncol_create_many"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_numbers, values, new_string, FALSE)); } @@ -1899,8 +1897,7 @@ mariadb_dyncol_create_many_named(DYNAMIC_COLUMN *str, DYNAMIC_COLUMN_VALUE *values, my_bool new_string) { - DBUG_ENTER("mariadb_dyncol_create_many_named"); - DBUG_RETURN(dynamic_column_create_many_internal_fmt(str, column_count, + return(dynamic_column_create_many_internal_fmt(str, column_count, column_keys, values, new_string, TRUE)); } @@ -1919,8 +1916,7 @@ enum enum_dyncol_func_result dynamic_column_create(DYNAMIC_COLUMN *str, uint column_nr, DYNAMIC_COLUMN_VALUE *value) { - DBUG_ENTER("dynamic_column_create"); - DBUG_RETURN(dynamic_column_create_many(str, 1, &column_nr, value)); + return(dynamic_column_create_many(str, 1, &column_nr, value)); } @@ -2319,7 +2315,7 @@ dynamic_column_get_internal(DYNAMIC_COLUMN *str, { DYN_HEADER header; enum enum_dyncol_func_result rc= ER_DYNCOL_FORMAT; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); if (str->length == 0) goto null; @@ -2392,7 +2388,7 @@ dynamic_column_exists_internal(DYNAMIC_COLUMN *str, uint num_key, { DYN_HEADER header; enum enum_dyncol_func_result rc; - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); if (str->length == 0) return ER_DYNCOL_NO; /* no columns */ @@ -2426,7 +2422,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) uint i; enum enum_dyncol_func_result rc; - bzero(array_of_uint, sizeof(*array_of_uint)); /* In case of errors */ + memset(array_of_uint, 0, sizeof(*array_of_uint)); /* In case of errors */ if (str->length == 0) return ER_DYNCOL_OK; /* no columns */ @@ -2440,7 +2436,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) str->length) return ER_DYNCOL_FORMAT; - if (my_init_dynamic_array(array_of_uint, sizeof(uint), header.column_count, 0)) + if (ma_init_dynamic_array(array_of_uint, sizeof(uint), header.column_count, 0)) return ER_DYNCOL_RESOURCE; for (i= 0, read= header.header; @@ -2449,7 +2445,7 @@ dynamic_column_list(DYNAMIC_COLUMN *str, DYNAMIC_ARRAY *array_of_uint) { uint nm= uint2korr(read); /* Insert can't never fail as it's pre-allocated above */ - (void) insert_dynamic(array_of_uint, (uchar *)&nm); + (void) ma_insert_dynamic(array_of_uint, (uchar *)&nm); } return ER_DYNCOL_OK; } @@ -2484,7 +2480,7 @@ mariadb_dyncol_list_num(DYNAMIC_COLUMN *str, uint *count, uint **nums) str->length) return ER_DYNCOL_FORMAT; - if (!((*nums)= (uint *)my_malloc(sizeof(uint) * header.column_count, MYF(0)))) + if (!((*nums)= (uint *)malloc(sizeof(uint) * header.column_count))) return ER_DYNCOL_RESOURCE; for (i= 0, read= header.header; @@ -2532,11 +2528,11 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) return ER_DYNCOL_FORMAT; if (header.format == dyncol_fmt_num) - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + - DYNCOL_NUM_CHAR * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); else - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + - header.nmpool_size + header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + header.nmpool_size + header.column_count); if (!(*names)) return ER_DYNCOL_RESOURCE; pool= ((char *)(*names)) + sizeof(LEX_STRING) * header.column_count; @@ -2551,7 +2547,7 @@ mariadb_dyncol_list_named(DYNAMIC_COLUMN *str, uint *count, LEX_STRING **names) (*names)[i].str= pool; pool+= DYNCOL_NUM_CHAR; (*names)[i].length= - longlong2str(nm, (*names)[i].str, 10) - (*names)[i].str; + ma_ll2str(nm, (*names)[i].str, 10) - (*names)[i].str; } else { @@ -2738,7 +2734,7 @@ dynamic_column_update_copy(DYNAMIC_COLUMN *str, PLAN *plan, { return ER_DYNCOL_RESOURCE; } - bzero(tmp.str, new_fmt->fixed_hdr); + memset(tmp.str, 0, new_fmt->fixed_hdr); (*new_fmt->set_fixed_hdr)(&tmp, new_hdr); /* Adjust tmp to contain whole the future header */ tmp.length= new_fmt->fixed_hdr + new_hdr->header_size + new_hdr->nmpool_size; @@ -3337,8 +3333,8 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, if (add_column_count == 0) return ER_DYNCOL_OK; - bzero(&header, sizeof(header)); - bzero(&new_header, sizeof(new_header)); + memset(&header, 0, sizeof(header)); + memset(&new_header, 0, sizeof(new_header)); new_header.format= (string_keys ? dyncol_fmt_str : dyncol_fmt_num); new_fmt= fmt_data + new_header.format; @@ -3349,7 +3345,7 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, if (IN_PLACE_PLAN > add_column_count) plan= in_place_plan; else if (!(alloc_plan= plan= - (PLAN *)my_malloc(sizeof(PLAN) * (add_column_count + 1), MYF(0)))) + (PLAN *)malloc(sizeof(PLAN) * (add_column_count + 1)))) return ER_DYNCOL_RESOURCE; not_null= add_column_count; @@ -3606,13 +3602,13 @@ dynamic_column_update_many_fmt(DYNAMIC_COLUMN *str, &header, &new_header, convert); end: - my_free(alloc_plan); + free(alloc_plan); return rc; create_new_string: /* There is no columns from before, so let's just add the new ones */ rc= ER_DYNCOL_OK; - my_free(alloc_plan); + free(alloc_plan); if (not_null != 0) rc= dynamic_column_create_many_internal_fmt(str, add_column_count, (uint*)column_keys, values, @@ -3654,20 +3650,16 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) void *key, *prev_key; enum enum_dynamic_column_type type= DYN_COL_NULL, prev_type= DYN_COL_NULL; - DBUG_ENTER("dynamic_column_check"); - if (str->length == 0) { - DBUG_PRINT("info", ("empty string is OK")); - DBUG_RETURN(ER_DYNCOL_OK); + return(ER_DYNCOL_OK); } - bzero(&header, sizeof(header)); + memset(&header, 0, sizeof(header)); /* Check that header is OK */ if (read_fixed_header(&header, str)) { - DBUG_PRINT("info", ("Reading fixed string header failed")); goto end; } fmt= fmt_data + header.format; @@ -3677,12 +3669,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) /* headers are out of string length (no space for data and part of headers) */ if (fmt->fixed_hdr + header.header_size + header.nmpool_size > str->length) { - DBUG_PRINT("info", ("Fixed header: %u Header size: %u " - "Name pool size: %u but Strig length: %u", - (uint)fmt->fixed_hdr, - (uint)header.header_size, - (uint)header.nmpool_size, - (uint)str->length)); goto end; } header.header= (uchar*)str->str + fmt->fixed_hdr; @@ -3716,12 +3702,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) DBUG_ASSERT(header.format == dyncol_fmt_str); if (read_name(&header, header.entry, &name)) { - DBUG_PRINT("info", ("Reading name failed: Field order: %u" - " Name offset: %u" - " Name pool size: %u", - (uint) i, - uint2korr(header.entry), - (uint)header.nmpool_size)); goto end; } name_offset= name.str - (char *)header.nmpool; @@ -3734,11 +3714,6 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) DBUG_ASSERT(type != DYN_COL_NULL); if (data_offset > header.data_size) { - DBUG_PRINT("info", ("Field order: %u Data offset: %u" - " > Data pool size: %u", - (uint)i, - (uint)data_offset, - (uint)header.data_size)); goto end; } if (prev_type != DYN_COL_NULL) @@ -3746,26 +3721,14 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) /* It is not first entry */ if (prev_data_offset >= data_offset) { - DBUG_PRINT("info", ("Field order: %u Previous data offset: %u" - " >= Current data offset: %u", - (uint)i, - (uint)prev_data_offset, - (uint)data_offset)); goto end; } if (prev_name_offset > name_offset) { - DBUG_PRINT("info", ("Field order: %u Previous name offset: %u" - " > Current name offset: %u", - (uint)i, - (uint)prev_data_offset, - (uint)data_offset)); goto end; } if ((*fmt->column_sort)(&prev_key, &key) >= 0) { - DBUG_PRINT("info", ("Field order: %u Previous key >= Current key", - (uint)i)); goto end; } } @@ -3828,41 +3791,39 @@ mariadb_dyncol_check(DYNAMIC_COLUMN *str) if (rc != ER_DYNCOL_OK) { DBUG_ASSERT(rc < 0); - DBUG_PRINT("info", ("Field order: %u Can't read data: %i", - (uint)i, (int) rc)); goto end; } } rc= ER_DYNCOL_OK; end: - DBUG_RETURN(rc); + return(rc); } enum enum_dyncol_func_result mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, - CHARSET_INFO *cs, char quote) + MARIADB_CHARSET_INFO *cs, char quote) { char buff[40]; size_t len; switch (val->type) { case DYN_COL_INT: len= snprintf(buff, sizeof(buff), "%lld", val->x.long_value); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; case DYN_COL_UINT: len= snprintf(buff, sizeof(buff), "%llu", val->x.ulong_value); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; case DYN_COL_DOUBLE: len= snprintf(buff, sizeof(buff), "%g", val->x.double_value); - if (dynstr_realloc(str, len + (quote ? 2 : 0))) + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) return ER_DYNCOL_RESOURCE; if (quote) str->str[str->length++]= quote; - dynstr_append_mem(str, buff, len); + ma_dynstr_append_mem(str, buff, len); if (quote) str->str[str->length++]= quote; break; @@ -3877,16 +3838,16 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, my_bool rc; len= val->x.string.value.length; bufflen= (ulong)(len * (conv ? cs->char_maxlen : 1)); - if (dynstr_realloc(str, bufflen)) + if (ma_dynstr_realloc(str, bufflen)) return ER_DYNCOL_RESOURCE; // guaranty UTF-8 string for value if (!conv) { #ifndef LIBMARIADB - uint dummy_errors; + uint dumma_errors; #else - int dummy_errors; + int dumma_errors; #endif if (!quote) { @@ -3897,24 +3858,24 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, cs, from, (uint32)len, val->x.string.charset, - &dummy_errors); + &dumma_errors); #else mariadb_convert_string(from, &len, val->x.string.charset, - str->str, (size_t *)&bufflen, cs, &dummy_errors); + str->str, (size_t *)&bufflen, cs, &dumma_errors); #endif return ER_DYNCOL_OK; } - if ((alloc= (char *)my_malloc(bufflen, MYF(0)))) + if ((alloc= (char *)malloc(bufflen))) { len= #ifndef LIBMARIADB copy_and_convert_extended(alloc, bufflen, cs, from, (uint32)len, val->x.string.charset, - &dummy_errors); + &dumma_errors); #else mariadb_convert_string(from, &len, val->x.string.charset, - alloc, (size_t *)&bufflen, cs, &dummy_errors); + alloc, (size_t *)&bufflen, cs, &dumma_errors); #endif from= alloc; } @@ -3922,12 +3883,12 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, return ER_DYNCOL_RESOURCE; } if (quote) - rc= dynstr_append_mem(str, "e, 1); - rc= dynstr_append_mem(str, from, len); + rc= ma_dynstr_append_mem(str, "e, 1); + rc= ma_dynstr_append_mem(str, from, len); if (quote) - rc= dynstr_append_mem(str, "e, 1); + rc= ma_dynstr_append_mem(str, "e, 1); if (alloc) - my_free(alloc); + free(alloc); if (rc) return ER_DYNCOL_RESOURCE; break; @@ -3939,7 +3900,7 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, decimal2string(&val->x.decimal.value, buff, &len, 0, val->x.decimal.value.frac, '0'); - if (dynstr_append_mem(str, buff, len)) + if (ma_dynstr_append_mem(str, buff, len)) return ER_DYNCOL_RESOURCE; break; } @@ -3952,16 +3913,16 @@ mariadb_dyncol_val_str(DYNAMIC_STRING *str, DYNAMIC_COLUMN_VALUE *val, #else len= mariadb_time_to_string(&val->x.time_value, buff, 39, AUTO_SEC_PART_DIGITS); #endif - if (dynstr_realloc(str, len + (quote ? 2 : 0))) + if (ma_dynstr_realloc(str, len + (quote ? 2 : 0))) return ER_DYNCOL_RESOURCE; if (quote) str->str[str->length++]= '"'; - dynstr_append_mem(str, buff, len); + ma_dynstr_append_mem(str, buff, len); if (quote) str->str[str->length++]= '"'; break; case DYN_COL_NULL: - if (dynstr_append_mem(str, "null", 4)) + if (ma_dynstr_append_mem(str, "null", 4)) return ER_DYNCOL_RESOURCE; break; default: @@ -4165,14 +4126,14 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, rc= ER_DYNCOL_RESOURCE; - if (dynstr_append_mem(json, "{", 1)) + if (ma_dynstr_append_mem(json, "{", 1)) goto err; for (i= 0, header.entry= header.header; i < header.column_count; i++, header.entry+= header.entry_size) { DYNAMIC_COLUMN_VALUE val; - if (i != 0 && dynstr_append_mem(json, ",", 1)) + if (i != 0 && ma_dynstr_append_mem(json, ",", 1)) goto err; header.length= hdr_interval_length(&header, header.entry + header.entry_size); @@ -4192,11 +4153,11 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, if (header.format == dyncol_fmt_num) { uint nm= uint2korr(header.entry); - if (dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) + if (ma_dynstr_realloc(json, DYNCOL_NUM_CHAR + 3)) goto err; json->str[json->length++]= '"'; - json->length+= (my_snprintf(json->str + json->length, - DYNCOL_NUM_CHAR, "%u", nm)); + json->length+= snprintf(json->str + json->length, + DYNCOL_NUM_CHAR, "%u", nm); } else { @@ -4206,7 +4167,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, rc= ER_DYNCOL_FORMAT; goto err; } - if (dynstr_realloc(json, name.length + 3)) + if (ma_dynstr_realloc(json, name.length + 3)) goto err; json->str[json->length++]= '"'; memcpy(json->str + json->length, name.str, name.length); @@ -4218,7 +4179,7 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, { /* here we use it only for read so can cheat a bit */ DYNAMIC_COLUMN dc; - bzero(&dc, sizeof(dc)); + memset(&dc, 0, sizeof(dc)); dc.str= val.x.string.value.str; dc.length= val.x.string.value.length; if (mariadb_dyncol_json_internal(&dc, json, lvl + 1) < 0) @@ -4231,11 +4192,11 @@ mariadb_dyncol_json_internal(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json, else { if ((rc= mariadb_dyncol_val_str(json, &val, - my_charset_utf8_general_ci, '"')) < 0) + ma_charset_utf8_general_ci, '"')) < 0) goto err; } } - if (dynstr_append_mem(json, "}", 1)) + if (ma_dynstr_append_mem(json, "}", 1)) { rc= ER_DYNCOL_RESOURCE; goto err; @@ -4251,7 +4212,7 @@ enum enum_dyncol_func_result mariadb_dyncol_json(DYNAMIC_COLUMN *str, DYNAMIC_STRING *json) { - if (init_dynamic_string(json, NULL, str->length * 2, 100)) + if (ma_init_dynamic_string(json, NULL, str->length * 2, 100)) return ER_DYNCOL_RESOURCE; return mariadb_dyncol_json_internal(str, json, 1); @@ -4291,16 +4252,16 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, str->length) return ER_DYNCOL_FORMAT; - *vals= (DYNAMIC_COLUMN_VALUE *)my_malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count, MYF(0)); + *vals= (DYNAMIC_COLUMN_VALUE *)malloc(sizeof(DYNAMIC_COLUMN_VALUE)* header.column_count); if (header.format == dyncol_fmt_num) { - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count + - DYNCOL_NUM_CHAR * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count + + DYNCOL_NUM_CHAR * header.column_count); nm= (char *)(names + sizeof(LEX_STRING) * header.column_count); } else { - *names= (LEX_STRING *)my_malloc(sizeof(LEX_STRING) * header.column_count, MYF(0)); + *names= (LEX_STRING *)malloc(sizeof(LEX_STRING) * header.column_count); nm= 0; } if (!(*vals) || !(*names)) @@ -4352,12 +4313,12 @@ mariadb_dyncol_unpack(DYNAMIC_COLUMN *str, err: if (*vals) { - my_free(*vals); + free(*vals); *vals= 0; } if (*names) { - my_free(*names); + free(*names); *names= 0; } return rc; @@ -4397,5 +4358,5 @@ mariadb_dyncol_column_count(DYNAMIC_COLUMN *str, uint *column_count) */ void mariadb_dyncol_free(DYNAMIC_COLUMN *str) { - dynstr_free(str); + ma_dynstr_free(str); } diff --git a/libmariadb/libmariadb.c b/libmariadb/mariadb_lib.c similarity index 75% rename from libmariadb/libmariadb.c rename to libmariadb/mariadb_lib.c index 5d6811ff..b2a56f3e 100644 --- a/libmariadb/libmariadb.c +++ b/libmariadb/mariadb_lib.c @@ -21,19 +21,20 @@ is freely available from http://www.php.net *************************************************************************************/ -#include +#include -#include -#include -#include -#include +#include +#include +#include #include -#include "my_context.h" +#ifdef HAVE_NONBLOCK +#include "ma_context.h" +#endif #include "mysql.h" -#include "mysql_version.h" -#include "mysqld_error.h" +#include "mariadb_version.h" +#include "ma_server_error.h" #include -#include "errmsg.h" +#include "ma_errmsg.h" #include #include #include @@ -56,13 +57,10 @@ #ifdef HAVE_SYS_UN_H # include #endif -#if defined(THREAD) && !defined(_WIN32) -#include /* because of signal() */ -#endif #ifndef INADDR_NONE #define INADDR_NONE -1 #endif -#include +#include #ifndef _WIN32 #include #endif @@ -70,10 +68,10 @@ #ifdef HAVE_SSL #include #endif -#include #include #define ASYNC_CONTEXT_DEFAULT_STACK_SIZE (4096*15) +#define MA_RPL_VERSION_HACK "5.5.5-" #undef max_allowed_packet #undef net_buffer_length @@ -82,13 +80,15 @@ extern ulong net_buffer_length; /* net.c */ static my_bool mysql_client_init=0; static void mysql_close_options(MYSQL *mysql); -extern my_bool my_init_done; +extern my_bool ma_init_done; extern my_bool mysql_ps_subsystem_initialized; extern my_bool mysql_handle_local_infile(MYSQL *mysql, const char *filename); -extern const CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); -extern const CHARSET_INFO * mysql_find_charset_name(const char * const name); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_nr(uint charsetnr); +extern const MARIADB_CHARSET_INFO * mysql_find_charset_name(const char * const name); extern int run_plugin_auth(MYSQL *mysql, char *data, uint data_len, const char *data_plugin, const char *db); +extern int net_add_multi_command(NET *net, uchar command, const uchar *packet, + size_t length); extern LIST *pvio_callback; @@ -101,11 +101,16 @@ extern int mthd_stmt_fetch_row(MYSQL_STMT *stmt, unsigned char **row); extern int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row); extern int mthd_stmt_read_all_rows(MYSQL_STMT *stmt); extern void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt); +extern my_bool _mariadb_read_options(MYSQL *mysql, const char *config_file, + char *group); extern unsigned char *mysql_net_store_length(unsigned char *packet, size_t length); + +#ifdef HAVE_NONBLOCK extern void my_context_install_suspend_resume_hook(struct mysql_async_context *b, void (*hook)(my_bool, void *), void *user_data); +#endif uint mysql_port=0; my_string mysql_unix_port=0; @@ -116,10 +121,10 @@ my_string mysql_unix_port=0; #define CONNECT_TIMEOUT 0 #endif -struct st_mysql_methods MARIADB_DEFAULT_METHODS; +struct st_mariadb_methods MARIADB_DEFAULT_METHODS; #if defined(MSDOS) || defined(_WIN32) -// socket_errno is defined in my_global.h for all platforms +// socket_errno is defined in ma_global.h for all platforms #define perror(A) #else #include @@ -136,7 +141,6 @@ struct st_mysql_methods MARIADB_DEFAULT_METHODS; static void end_server(MYSQL *mysql); static void mysql_close_memory(MYSQL *mysql); void read_user_name(char *name); -static void append_wild(char *to,char *end,const char *wild); my_bool STDCALL mysql_reconnect(MYSQL *mysql); static int cli_report_progress(MYSQL *mysql, uchar *packet, uint length); @@ -222,15 +226,15 @@ restart: net->last_errno= last_errno; if (pos[0]== '#') { - strmake(net->sqlstate, pos+1, SQLSTATE_LENGTH); + strncpy(net->sqlstate, pos+1, SQLSTATE_LENGTH); pos+= SQLSTATE_LENGTH + 1; } else { - strmov(net->sqlstate, SQLSTATE_UNKNOWN); + strcpy(net->sqlstate, SQLSTATE_UNKNOWN); } - (void) strmake(net->last_error,(char*) pos, - min(len,sizeof(net->last_error)-1)); + strncpy(net->last_error,(char*) pos, + min(len,sizeof(net->last_error)-1)); } else { @@ -239,8 +243,6 @@ restart: mysql->server_status&= ~SERVER_MORE_RESULTS_EXIST; - DBUG_PRINT("error",("Got error: %d (%s)", net->last_errno, - net->last_error)); return(packet_error); } return len; @@ -347,8 +349,8 @@ void free_rows(MYSQL_DATA *cur) { if (cur) { - free_root(&cur->alloc,MYF(0)); - my_free(cur); + ma_free_root(&cur->alloc,MYF(0)); + free(cur); } } @@ -358,17 +360,22 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { NET *net= &mysql->net; int result= -1; + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; - DBUG_ENTER("mthd_my_send_command"); + if (OPT_HAS_EXT_VAL(mysql, multi_command)) + multi= mysql->options.extension->multi_command; - DBUG_PRINT("info", ("server_command: %d packet_size: %u", command, length)); + if (multi == MARIADB_COM_MULTI_BEGIN) + { + /* todo: error handling */ + return(net_add_multi_command(&mysql->net, command, arg, length)); + } if (mysql->net.pvio == 0) { /* Do reconnect if possible */ if (mysql_reconnect(mysql)) { - DBUG_PRINT("info", ("reconnect failed")); - DBUG_RETURN(1); + return(1); } } if (mysql->status != MYSQL_STATUS_READY || @@ -382,7 +389,7 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, { result= mysql->net.conn_hdlr->plugin->set_connection(mysql, command, arg, length, skipp_check, opt_arg); if (result== -1) - DBUG_RETURN(result); + return(result); } CLEAR_CLIENT_ERROR(mysql); @@ -396,7 +403,6 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (net_write_command(net,(uchar) command,arg, length ? length : (ulong) strlen(arg))) { - DBUG_PRINT("error",("Can't send command to server. Error: %d",socket_errno)); if (net->last_errno == ER_NET_PACKET_TOO_LARGE) { my_set_error(mysql, CR_NET_PACKET_TOO_LARGE, SQLSTATE_UNKNOWN, 0); @@ -416,14 +422,13 @@ mthd_my_send_cmd(MYSQL *mysql,enum enum_server_command command, const char *arg, if (!skipp_check) { result= ((mysql->packet_length=net_safe_read(mysql)) == packet_error ? 1 : 0); - DBUG_PRINT("info", ("packet_length=%llu", mysql->packet_length)); } end: - DBUG_RETURN(result); + return(result); } int -simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, +ma_simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, size_t length, my_bool skipp_check, void *opt_arg) { return mysql->methods->db_command(mysql, command, arg, length, skipp_check, opt_arg); @@ -431,13 +436,12 @@ simple_command(MYSQL *mysql,enum enum_server_command command, const char *arg, static void free_old_query(MYSQL *mysql) { - DBUG_ENTER("free_old_query"); if (mysql->fields) - free_root(&mysql->field_alloc,MYF(0)); - init_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ + ma_free_root(&mysql->field_alloc,MYF(0)); + ma_init_ma_alloc_root(&mysql->field_alloc,8192,0); /* Assume rowlength < 8192 */ mysql->fields=0; mysql->field_count=0; /* For API */ - DBUG_VOID_RETURN; + return; } #if defined(HAVE_GETPWUID) && defined(NO_GETPWUID_DECL) @@ -448,9 +452,8 @@ char* getlogin(void); #if !defined(MSDOS) && ! defined(VMS) && !defined(_WIN32) && !defined(OS2) void read_user_name(char *name) { - DBUG_ENTER("read_user_name"); if (geteuid() == 0) - (void) strmov(name,"root"); /* allow use of surun */ + strcpy(name,"root"); /* allow use of surun */ else { #ifdef HAVE_GETPWUID @@ -464,14 +467,14 @@ void read_user_name(char *name) !(str=getenv("LOGIN"))) str="UNKNOWN_USER"; } - (void) strmake(name,str,USERNAME_LENGTH); + strncpy(name,str,USERNAME_LENGTH); #elif HAVE_CUSERID (void) cuserid(name); #else - strmov(name,"UNKNOWN_USER"); + strncpy(name,"UNKNOWN_USER", USERNAME_LENGTH); #endif } - DBUG_VOID_RETURN; + return; } #else /* If MSDOS || VMS */ @@ -479,7 +482,7 @@ void read_user_name(char *name) void read_user_name(char *name) { char *str=getenv("USERNAME"); /* ODBC will send user variable */ - strmake(name,str ? str : "ODBC", USERNAME_LENGTH); + strncpy(name,str ? str : "ODBC", USERNAME_LENGTH); } #endif @@ -492,74 +495,6 @@ static my_bool is_NT(void) } #endif -/* -** Expand wildcard to a sql string -*/ - -static void -append_wild(char *to, char *end, const char *wild) -{ - end-=5; /* Some extra */ - if (wild && wild[0]) - { - to=strmov(to," like '"); - while (*wild && to < end) - { - if (*wild == '\\' || *wild == '\'') - *to++='\\'; - *to++= *wild++; - } - if (*wild) /* Too small buffer */ - *to++='%'; /* Nicer this way */ - to[0]='\''; - to[1]=0; - } -} - - - -/************************************************************************** -** Init debugging if MYSQL_DEBUG environment variable is found -**************************************************************************/ -void STDCALL mysql_debug_end(void) -{ -#ifndef DBUG_OFF - DEBUGGER_OFF; - DBUG_POP(); -#endif -} - -void STDCALL -mysql_debug(const char *debug __attribute__((unused))) -{ -#ifndef DBUG_OFF - char *env; - if (debug) - { - DEBUGGER_ON; - DBUG_PUSH(debug); - } - else if ((env = getenv("MYSQL_DEBUG"))) - { - DEBUGGER_ON; - DBUG_PUSH(env); -#if !defined(_WINVER) && !defined(WINVER) - puts("\n-------------------------------------------------------"); - puts("MYSQL_DEBUG found. libmariadb started with the following:"); - puts(env); - puts("-------------------------------------------------------\n"); -#else - { - char buff[80]; - strmov(strmov(buff,"libmariadb: "),env); - MessageBox((HWND) 0,"Debugging variable MYSQL_DEBUG used",buff,MB_OK); - } -#endif - } -#endif -} - - /************************************************************************** ** Shut down connection **************************************************************************/ @@ -567,8 +502,6 @@ mysql_debug(const char *debug __attribute__((unused))) static void end_server(MYSQL *mysql) { - DBUG_ENTER("end_server"); - /* if net->error 2 and reconnect is activated, we need to inforn connection handler */ if (mysql->net.pvio != 0) @@ -578,27 +511,24 @@ end_server(MYSQL *mysql) } net_end(&mysql->net); free_old_query(mysql); - DBUG_VOID_RETURN; + return; } void mthd_my_skip_result(MYSQL *mysql) { ulong pkt_len; - DBUG_ENTER("madb_skip_result"); do { pkt_len= net_safe_read(mysql); if (pkt_len == packet_error) break; } while (pkt_len > 8 || mysql->net.read_pos[0] != 254); - DBUG_VOID_RETURN; + return; } void STDCALL mysql_free_result(MYSQL_RES *result) { - DBUG_ENTER("mysql_free_result"); - DBUG_PRINT("enter",("mysql_res: %lx",result)); if (result) { if (result->handle && result->handle->status == MYSQL_STATUS_USE_RESULT) @@ -608,298 +538,166 @@ mysql_free_result(MYSQL_RES *result) } free_rows(result->data); if (result->fields) - free_root(&result->field_alloc,MYF(0)); + ma_free_root(&result->field_alloc,MYF(0)); if (result->row) - my_free(result->row); - my_free(result); + free(result->row); + free(result); } - DBUG_VOID_RETURN; + return; } /**************************************************************************** ** Get options from my.cnf ****************************************************************************/ - -static const char *default_options[]= -{ - "port","socket","compress","password","pipe", "timeout", "user", - "init-command", "host", "database", "debug", "return-found-rows", - "ssl-key" ,"ssl-cert" ,"ssl-ca" ,"ssl-capath", - "character-sets-dir", "default-character-set", "interactive-timeout", - "connect-timeout", "local-infile", "disable-local-infile", - "ssl-cipher", "max-allowed-packet", "protocol", "shared-memory-base-name", - "multi-results", "multi-statements", "multi-queries", "secure-auth", - "report-data-truncation", "plugin-dir", "default-auth", "database-type", - "ssl-fp", "ssl-fp-list", "ssl_password", "bind-address", - NULL +enum enum_option_type { + MARIADB_OPTION_NONE, + MARIADB_OPTION_BOOL, + MARIADB_OPTION_INT, + MARIADB_OPTION_SIZET, + MARIADB_OPTION_STR, }; -enum option_val +struct st_default_options { + enum mysql_option option; + enum enum_option_type type; + char *conf_key; +}; + +struct st_default_options mariadb_defaults[] = { - OPT_port=1, OPT_socket, OPT_compress, OPT_password, OPT_pipe, - OPT_timeout, OPT_user, OPT_init_command, OPT_host, OPT_database, - OPT_debug, OPT_return_found_rows, OPT_ssl_key, OPT_ssl_cert, - OPT_ssl_ca, OPT_ssl_capath, OPT_charset_dir, - OPT_charset_name, OPT_interactive_timeout, - OPT_connect_timeout, OPT_local_infile, OPT_disable_local_infile, - OPT_ssl_cipher, OPT_max_allowed_packet, OPT_protocol, OPT_shared_memory_base_name, - OPT_multi_results, OPT_multi_statements, OPT_multi_queries, OPT_secure_auth, - OPT_report_data_truncation, OPT_plugin_dir, OPT_default_auth, OPT_db_type, - OPT_ssl_fp, OPT_ssl_fp_list, OPT_ssl_pw, OPT_bind_address + {MARIADB_OPT_PORT, MARIADB_OPTION_INT,"port"}, + {MARIADB_OPT_UNIXSOCKET, MARIADB_OPTION_STR, "socket"}, + {MYSQL_OPT_COMPRESS, MARIADB_OPTION_BOOL, "compress"}, + {MARIADB_OPT_PASSWORD, MARIADB_OPTION_STR, "password"}, + {MYSQL_OPT_NAMED_PIPE, MARIADB_OPTION_BOOL, "pipe"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "timeout"}, + {MARIADB_OPT_USER, MARIADB_OPTION_STR, "user"}, + {MYSQL_INIT_COMMAND, MARIADB_OPTION_STR, "init-command"}, + {MARIADB_OPT_HOST, MARIADB_OPTION_STR, "host"}, + {MARIADB_OPT_SCHEMA, MARIADB_OPTION_STR, "database"}, + {MARIADB_OPT_DEBUG, MARIADB_OPTION_STR, "debug"}, + {MARIADB_OPT_FOUND_ROWS, MARIADB_OPTION_NONE, "return-found-rows"}, + {MYSQL_OPT_SSL_KEY, MARIADB_OPTION_STR, "ssl-key"}, + {MYSQL_OPT_SSL_CERT, MARIADB_OPTION_STR,"ssl-cert"}, + {MYSQL_OPT_SSL_CA, MARIADB_OPTION_STR,"ssl-ca"}, + {MYSQL_OPT_SSL_CAPATH, MARIADB_OPTION_STR,"ssl-capath"}, + {MYSQL_SET_CHARSET_DIR, MARIADB_OPTION_STR, "character-sets-dir"}, + {MYSQL_SET_CHARSET_NAME, MARIADB_OPTION_STR, "default-character-set"}, + {MARIADB_OPT_INTERACTIVE, MARIADB_OPTION_NONE, "interactive-timeout"}, + {MYSQL_OPT_CONNECT_TIMEOUT, MARIADB_OPTION_INT, "connect-timeout"}, + {MYSQL_OPT_LOCAL_INFILE, MARIADB_OPTION_BOOL, "local-infile"}, + {0, 0 ,"disable-local-infile",}, + {MYSQL_OPT_SSL_CIPHER, MARIADB_OPTION_STR, "ssl-cipher"}, + {MYSQL_OPT_MAX_ALLOWED_PACKET, MARIADB_OPTION_SIZET, "max-allowed-packet"}, + {MYSQL_OPT_NET_BUFFER_LENGTH, MARIADB_OPTION_SIZET, "net-buffer-length"}, + {MYSQL_OPT_PROTOCOL, MARIADB_OPTION_INT, "protocol"}, + {MYSQL_SHARED_MEMORY_BASE_NAME, MARIADB_OPTION_STR,"shared-memory-base-name"}, + {MARIADB_OPT_MULTI_RESULTS, MARIADB_OPTION_NONE, "multi-results"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-statements"}, + {MARIADB_OPT_MULTI_STATEMENTS, MARIADB_OPTION_STR, "multi-queries"}, + {MYSQL_SECURE_AUTH, MARIADB_OPTION_BOOL, "secure-auth"}, + {MYSQL_REPORT_DATA_TRUNCATION, MARIADB_OPTION_BOOL, "report-data-truncation"}, + {MYSQL_OPT_RECONNECT, MARIADB_OPTION_BOOL, "reconnect"}, + {MYSQL_PLUGIN_DIR, MARIADB_OPTION_STR, "plugin-dir"}, + {MYSQL_DEFAULT_AUTH, MARIADB_OPTION_STR, "default-auth"}, + {MARIADB_OPT_SSL_FP, MARIADB_OPTION_STR, "ssl-fp"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fp-list"}, + {MARIADB_OPT_SSL_FP_LIST, MARIADB_OPTION_STR, "ssl-fplist"}, + {MARIADB_OPT_SSL_PASSPHRASE, MARIADB_OPTION_STR, "ssl_passphrase"}, + {MYSQL_OPT_BIND, MARIADB_OPTION_STR, "bind-address"}, + {0, 0, NULL} }; #define CHECK_OPT_EXTENSION_SET(OPTS)\ if (!(OPTS)->extension) \ (OPTS)->extension= (struct st_mysql_options_extension *) \ - my_malloc(sizeof(struct st_mysql_options_extension), \ - MYF(MY_WME | MY_ZEROFILL)); \ + calloc(1, sizeof(struct st_mysql_options_extension)); -#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ - CHECK_OPT_EXTENSION_SET(OPTS) \ - my_free((gptr)(OPTS)->extension->KEY);\ - (OPTS)->extension->KEY= my_strdup((char *)(VAL), MYF(MY_WME)) +#define OPT_SET_EXTENDED_VALUE_STR(OPTS, KEY, VAL) \ + CHECK_OPT_EXTENSION_SET(OPTS) \ + free((gptr)(OPTS)->extension->KEY); \ + if((VAL)) \ + (OPTS)->extension->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->extension->KEY= NULL #define OPT_SET_EXTENDED_VALUE_INT(OPTS, KEY, VAL) \ CHECK_OPT_EXTENSION_SET(OPTS) \ (OPTS)->extension->KEY= (VAL) +#define OPT_SET_VALUE_STR(OPTS, KEY, VAL) \ + free((OPTS)->KEY); \ + if((VAL)) \ + (OPTS)->KEY= strdup((char *)(VAL)); \ + else \ + (OPTS)->KEY= NULL -static TYPELIB option_types={array_elements(default_options)-1, - "options",default_options}; - -const char *protocol_names[]= {"TCP", "SOCKED", "PIPE", "MEMORY", NULL}; -static TYPELIB protocol_types= {array_elements(protocol_names)-1, - "protocol names", - protocol_names}; +#define OPT_SET_VALUE_INT(OPTS, KEY, VAL) \ + (OPTS)->KEY= (VAL) static void options_add_initcommand(struct st_mysql_options *options, const char *init_cmd) { - char *insert= my_strdup(init_cmd, MYF(MY_WME)); + char *insert= strdup(init_cmd); if (!options->init_command) { - options->init_command= (DYNAMIC_ARRAY*)my_malloc(sizeof(DYNAMIC_ARRAY), - MYF(MY_WME)); - my_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); + options->init_command= (DYNAMIC_ARRAY*)malloc(sizeof(DYNAMIC_ARRAY)); + ma_init_dynamic_array(options->init_command, sizeof(char*), 5, 5); } - if (insert_dynamic(options->init_command, (gptr)&insert)) - my_free(insert); + if (ma_insert_dynamic(options->init_command, (gptr)&insert)) + free(insert); } - - -static void mysql_read_default_options(struct st_mysql_options *options, - const char *filename,const char *group) +my_bool _mariadb_set_conf_option(MYSQL *mysql, const char *config_option, const char *config_value) { - int argc; - char *argv_buff[1],**argv; - const char *groups[3]; - DBUG_ENTER("mysql_read_default_options"); - DBUG_PRINT("enter",("file: %s group: %s",filename,group ? group :"NULL")); - - argc=1; argv=argv_buff; argv_buff[0]= (char*) "client"; - groups[0]= (char*) "client"; groups[1]= (char*) group; groups[2]=0; - - load_defaults(filename, groups, &argc, &argv); - if (argc != 1) /* If some default option */ + if (config_option) { - char **option=argv; - while (*++option) + int i; + + for (i=0; mariadb_defaults[i].conf_key; i++) { - /* DBUG_PRINT("info",("option: %s",option[0])); */ - if (option[0][0] == '-' && option[0][1] == '-') + if (!strcmp(mariadb_defaults[i].conf_key, config_option)) { - char *end=strcend(*option,'='); - char *opt_arg=0; - if (*end) - { - opt_arg=end+1; - *end=0; /* Remove '=' */ - } - /* Change all '_' in variable name to '-' */ - for (end= *option ; *(end= strcend(end,'_')) ; ) - *end= '-'; - switch (find_type(*option+2,&option_types,2)) { - case OPT_port: - if (opt_arg) - options->port=atoi(opt_arg); - break; - case OPT_socket: - if (opt_arg) - { - my_free(options->unix_socket); - options->unix_socket=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case OPT_compress: - options->compress=1; - break; - case OPT_password: - if (opt_arg) - { - my_free(options->password); - options->password=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case OPT_pipe: - options->named_pipe=1; /* Force named pipe */ - break; - case OPT_connect_timeout: - case OPT_timeout: - if (opt_arg) - options->connect_timeout=atoi(opt_arg); - break; - case OPT_user: - if (opt_arg) - { - my_free(options->user); - options->user=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case OPT_init_command: - if (opt_arg) - options_add_initcommand(options, opt_arg); - break; - case OPT_host: - if (opt_arg) - { - my_free(options->host); - options->host=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case OPT_database: - if (opt_arg) - { - my_free(options->db); - options->db=my_strdup(opt_arg,MYF(MY_WME)); - } - break; - case OPT_debug: - mysql_debug(opt_arg ? opt_arg : "d:t:o,/tmp/client.trace"); - break; - case OPT_return_found_rows: - options->client_flag|=CLIENT_FOUND_ROWS; - break; -#ifdef HAVE_SSL - case OPT_ssl_key: - my_free(options->ssl_key); - options->ssl_key = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_ssl_cert: - my_free(options->ssl_cert); - options->ssl_cert = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_ssl_ca: - my_free(options->ssl_ca); - options->ssl_ca = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_ssl_capath: - my_free(options->ssl_capath); - options->ssl_capath = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_ssl_cipher: - break; - case OPT_ssl_fp: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_fp, opt_arg); - break; - case OPT_ssl_fp_list: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_fp_list, opt_arg); - break; - case OPT_ssl_pw: - OPT_SET_EXTENDED_VALUE_STR(options, ssl_pw, opt_arg); - break; -#else - case OPT_ssl_key: - case OPT_ssl_cert: - case OPT_ssl_ca: - case OPT_ssl_capath: - case OPT_ssl_cipher: - case OPT_ssl_fp: - case OPT_ssl_fp_list: - break; -#endif /* HAVE_SSL */ - case OPT_charset_dir: - my_free(options->charset_dir); - options->charset_dir = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_charset_name: - my_free(options->charset_name); - options->charset_name = my_strdup(opt_arg, MYF(MY_WME)); - break; - case OPT_interactive_timeout: - options->client_flag|= CLIENT_INTERACTIVE; - break; - case OPT_local_infile: - if (!opt_arg || atoi(opt_arg) != 0) - options->client_flag|= CLIENT_LOCAL_FILES; - else - options->client_flag&= ~CLIENT_LOCAL_FILES; - break; - case OPT_disable_local_infile: - options->client_flag&= CLIENT_LOCAL_FILES; - break; - case OPT_max_allowed_packet: - if(opt_arg) - options->max_allowed_packet= atoi(opt_arg); - break; - case OPT_protocol: - options->protocol= find_type(opt_arg, &protocol_types, 0); -#ifndef _WIN32 - if (options->protocol < 0 || options->protocol > 1) -#else - if (options->protocol < 0) -#endif + int rc; + void *option_val= NULL; + switch (mariadb_defaults[i].type) { + case MARIADB_OPTION_BOOL: { - fprintf(stderr, "Unknown or unsupported protocol %s", opt_arg); + my_bool val= 0; + if (config_value) + val= atoi(config_value); + option_val= &val; + break; } - break; - case OPT_shared_memory_base_name: - /* todo */ - break; - case OPT_multi_results: - options->client_flag|= CLIENT_MULTI_RESULTS; - break; - case OPT_multi_statements: - case OPT_multi_queries: - options->client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; - break; - case OPT_report_data_truncation: - if (opt_arg) - options->report_data_truncation= atoi(opt_arg); - else - options->report_data_truncation= 1; - break; - case OPT_secure_auth: - options->secure_auth= 1; - break; - case OPT_plugin_dir: + case MARIADB_OPTION_INT: { - char directory[FN_REFLEN]; - if (strlen(opt_arg) >= FN_REFLEN) - opt_arg[FN_REFLEN]= 0; - if (!my_realpath(directory, opt_arg, 0)) - OPT_SET_EXTENDED_VALUE_STR(options, plugin_dir, convert_dirname(directory)); + int val= 0; + if (config_value) + val= atoi(config_value); + option_val= &val; + break; + } + case MARIADB_OPTION_SIZET: + { + size_t val= 0; + if (config_value) + val= strtol(config_value, NULL, 10); + option_val= &val; + break; } - break; - case OPT_default_auth: - OPT_SET_EXTENDED_VALUE_STR(options, default_auth, opt_arg); - break; - case OPT_bind_address: - my_free(options->bind_address); - options->bind_address= my_strdup(opt_arg, MYF(MY_WME)); - break; default: - DBUG_PRINT("warning",("unknown option: %s",option[0])); + option_val= (void *)config_value; } + rc= mysql_optionsv(mysql, mariadb_defaults[i].option, option_val); + return(test(rc)); } } } - free_defaults(argv); - DBUG_VOID_RETURN; + /* unknown key */ + return 1; } - /*************************************************************************** ** Change field rows to field structs ***************************************************************************/ @@ -920,7 +718,7 @@ static size_t rset_field_offsets[]= { }; MYSQL_FIELD * -unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, +unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol) { MYSQL_ROWS *row; @@ -928,10 +726,9 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, char *p; unsigned int i, field_count= sizeof(rset_field_offsets)/sizeof(size_t)/2; - DBUG_ENTER("unpack_fields"); - field=result=(MYSQL_FIELD*) alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); + field=result=(MYSQL_FIELD*) ma_alloc_root(alloc,sizeof(MYSQL_FIELD)*fields); if (!result) - DBUG_RETURN(0); + return(0); for (row=data->data; row ; row = row->next,field++) { @@ -939,12 +736,12 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, { switch(row->data[i][0]) { case 0: - *(char **)(((char *)field) + rset_field_offsets[i*2])= strdup_root(alloc, ""); + *(char **)(((char *)field) + rset_field_offsets[i*2])= ma_strdup_root(alloc, ""); *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= 0; break; default: *(char **)(((char *)field) + rset_field_offsets[i*2])= - strdup_root(alloc, (char *)row->data[i]); + ma_strdup_root(alloc, (char *)row->data[i]); *(unsigned int *)(((char *)field) + rset_field_offsets[i*2+1])= (uint)(row->data[i+1] - row->data[i] - 1); break; @@ -972,14 +769,14 @@ unpack_fields(MYSQL_DATA *data,MEM_ROOT *alloc,uint fields, if (default_value && row->data[7]) { - field->def=strdup_root(alloc,(char*) row->data[7]); + field->def=ma_strdup_root(alloc,(char*) row->data[7]); } else field->def=0; field->max_length= 0; } free_rows(data); /* Free old data */ - DBUG_RETURN(result); + return(result); } @@ -996,17 +793,15 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, MYSQL_DATA *result; MYSQL_ROWS **prev_ptr,*cur; NET *net = &mysql->net; - DBUG_ENTER("madb_read_rows"); if ((pkt_len= net_safe_read(mysql)) == packet_error) - DBUG_RETURN(0); - if (!(result=(MYSQL_DATA*) my_malloc(sizeof(MYSQL_DATA), - MYF(MY_WME | MY_ZEROFILL)))) + return(0); + if (!(result=(MYSQL_DATA*) calloc(1, sizeof(MYSQL_DATA)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } - init_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ + ma_init_ma_alloc_root(&result->alloc,8192,0); /* Assume rowlength < 8192 */ result->alloc.min_malloc=sizeof(MYSQL_ROWS); prev_ptr= &result->data; result->rows=0; @@ -1015,15 +810,15 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, while (*(cp=net->read_pos) != 254 || pkt_len >= 8) { result->rows++; - if (!(cur= (MYSQL_ROWS*) alloc_root(&result->alloc, + if (!(cur= (MYSQL_ROWS*) ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS))) || !(cur->data= ((MYSQL_ROW) - alloc_root(&result->alloc, + ma_alloc_root(&result->alloc, (fields+1)*sizeof(char *)+fields+pkt_len)))) { free_rows(result); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } *prev_ptr=cur; prev_ptr= &cur->next; @@ -1042,7 +837,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, { free_rows(result); SET_CLIENT_ERROR(mysql, CR_UNKNOWN_ERROR, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } memcpy(to,(char*) cp,len); to[len]=0; to+=len+1; @@ -1058,7 +853,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, if ((pkt_len=net_safe_read(mysql)) == packet_error) { free_rows(result); - DBUG_RETURN(0); + return(0); } } *prev_ptr=0; /* last pointer is null */ @@ -1070,8 +865,7 @@ MYSQL_DATA *mthd_my_read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, cp+= 2; mysql->server_status= uint2korr(cp); } - DBUG_PRINT("exit",("Got %d rows",result->rows)); - DBUG_RETURN(result); + return(result); } @@ -1111,7 +905,7 @@ int mthd_my_read_one_row(MYSQL *mysql,uint fields,MYSQL_ROW row, ulong *lengths) if (len > (ulong) (end_pos - pos)) { mysql->net.last_errno=CR_UNKNOWN_ERROR; - strmov(mysql->net.last_error,ER(mysql->net.last_errno)); + strcpy(mysql->net.last_error,ER(mysql->net.last_errno)); return -1; } row[field] = (char*) pos; @@ -1138,17 +932,17 @@ mysql_init(MYSQL *mysql) return NULL; if (!mysql) { - if (!(mysql=(MYSQL*) my_malloc(sizeof(*mysql),MYF(MY_WME | MY_ZEROFILL)))) + if (!(mysql=(MYSQL*) calloc(1, sizeof(MYSQL)))) return 0; mysql->free_me=1; mysql->net.pvio= 0; } else - bzero((char*) (mysql),sizeof(*(mysql))); + memset((char*) (mysql), 0, sizeof(*(mysql))); mysql->options.connect_timeout=CONNECT_TIMEOUT; - mysql->charset= default_charset_info; + mysql->charset= ma_default_charset_info; mysql->methods= &MARIADB_DEFAULT_METHODS; - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); mysql->net.last_error[0]= mysql->net.last_errno= 0; /* @@ -1285,7 +1079,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, if (!connection_handler || !connection_handler[0]) { - bzero(plugin_name, 64); + memset(plugin_name, 0, 64); strncpy(plugin_name, host, MIN(end - host, 63)); end+= 3; } @@ -1295,7 +1089,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, if (!(plugin= (MARIADB_CONNECTION_PLUGIN *)mysql_client_find_plugin(mysql, plugin_name, MARIADB_CLIENT_CONNECTION_PLUGIN))) return NULL; - if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)my_malloc(sizeof(MA_CONNECTION_HANDLER), MYF(MY_ZEROFILL)))) + if (!(mysql->net.conn_hdlr= (MA_CONNECTION_HANDLER *)calloc(1, sizeof(MA_CONNECTION_HANDLER)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); return NULL; @@ -1311,7 +1105,7 @@ mysql_real_connect(MYSQL *mysql, const char *host, const char *user, MYSQL *my= plugin->connect(mysql, end, user, passwd, db, port, unix_socket, client_flag); if (!my) { - my_free(mysql->net.conn_hdlr); + free(mysql->net.conn_hdlr); mysql->net.conn_hdlr= NULL; } return my; @@ -1332,15 +1126,10 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, MA_PVIO_CINFO cinfo= {NULL, NULL, 0, -1, NULL}; MARIADB_PVIO *pvio= NULL; char *scramble_data; + my_bool is_maria= 0; const char *scramble_plugin; uint pkt_length, scramble_len, pkt_scramble_len= 0; NET *net= &mysql->net; - DBUG_ENTER("mysql_real_connect"); - - DBUG_PRINT("enter",("host: %s db: %s user: %s", - host ? host : "(Null)", - db ? db : "(Null)", - user ? user : "(Null)")); if (!mysql->methods) mysql->methods= &MARIADB_DEFAULT_METHODS; @@ -1350,18 +1139,18 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (net->pvio) /* check if we are already connected */ { SET_CLIENT_ERROR(mysql, CR_ALREADY_CONNECTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } /* use default options */ if (mysql->options.my_cnf_file || mysql->options.my_cnf_group) { - mysql_read_default_options(&mysql->options, - (mysql->options.my_cnf_file ? - mysql->options.my_cnf_file : "my"), - mysql->options.my_cnf_group); - my_free(mysql->options.my_cnf_file); - my_free(mysql->options.my_cnf_group); + _mariadb_read_options(mysql, + (mysql->options.my_cnf_file ? + mysql->options.my_cnf_file : NULL), + mysql->options.my_cnf_group); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); mysql->options.my_cnf_file=mysql->options.my_cnf_group=0; } @@ -1413,12 +1202,8 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, #endif #else /* named pipe */ - if ((unix_socket || - (!host && is_NT()) || - (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0) || - mysql->options.named_pipe || - !have_tcpip) && - mysql->options.protocol != MYSQL_PROTOCOL_TCP) + if (mysql->options.protocol == MYSQL_PROTOCOL_PIPE || + (host && strcmp(host,LOCAL_HOST_NAMEDPIPE) == 0)) { cinfo.type= PVIO_TYPE_NAMEDPIPE; sprintf(host_info=buff,ER(CR_NAMEDPIPE_CONNECTION),cinfo.host); @@ -1451,7 +1236,7 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, goto error; ma_pvio_keepalive(net->pvio); - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); /* Get version info */ mysql->protocol_version= PROTOCOL_VERSION; /* Assume this */ @@ -1494,9 +1279,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, goto error; } - DBUG_DUMP("packet",net->read_pos,10); - DBUG_PRINT("info",("mysql protocol version %d, server=%d", - PROTOCOL_VERSION, mysql->protocol_version)); if (mysql->protocol_version < PROTOCOL_VERSION) { net->last_errno= CR_VERSION_ERROR; @@ -1508,39 +1290,31 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, if (!user) user=""; if (!passwd) passwd=""; - if (!my_multi_malloc(MYF(0), - &mysql->host_info, (uint) strlen(host_info)+1, - &mysql->host, (uint) strlen(cinfo.host)+1, - &mysql->unix_socket, cinfo.unix_socket ? - (uint) strlen(cinfo.unix_socket)+1 : (uint) 1, - &mysql->server_version, (uint) (end - (char*) net->read_pos), - NullS) || - !(mysql->user=my_strdup(user,MYF(0))) || - !(mysql->passwd=my_strdup(passwd,MYF(0)))) + if (!(mysql->host_info= strdup(host_info ? host_info : "")) || + !(mysql->host= strdup(cinfo.host ? cinfo.host : "")) || + !(mysql->user=strdup(user)) || + !(mysql->passwd=strdup(passwd))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; } - strmov(mysql->host_info,host_info); - strmov(mysql->host, cinfo.host); + strcpy(mysql->host_info,host_info); + strcpy(mysql->host, cinfo.host); if (cinfo.unix_socket) - strmov(mysql->unix_socket, cinfo.unix_socket); + mysql->unix_socket= strdup(cinfo.unix_socket); else mysql->unix_socket=0; mysql->port=port; client_flag|=mysql->options.client_flag; - if (strncmp(end, "5.5.5-", 6) == 0) + if (strncmp(end, MA_RPL_VERSION_HACK, sizeof(MA_RPL_VERSION_HACK) - 1) == 0) { - if (!(mysql->server_version= my_strdup(end + 6, 0))) - { - SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - goto error; - } + mysql->server_version= strdup(end + sizeof(MA_RPL_VERSION_HACK) - 1); + is_maria= 1; } else { - if (!(mysql->server_version= my_strdup(end, MYF(0)))) + if (!(mysql->server_version= strdup(end))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto error; @@ -1571,9 +1345,16 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, { mysql->server_language= uint1korr(end + 2); mysql->server_status= uint2korr(end + 3); - mysql->server_capabilities|= uint2korr(end + 5) << 16; + mysql->server_capabilities|= (unsigned int)(uint2korr(end + 5) << 16); pkt_scramble_len= uint1korr(end + 7); + + /* check if MariaD2B specific capabilities are available */ + if (is_maria && !(mysql->server_capabilities & CLIENT_MYSQL)) + { + mysql->server_capabilities|= (ulonglong) uint4korr(end + 14) << 32; + } } + /* pad 2 */ end+= 18; @@ -1603,14 +1384,25 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } } - /* Set character set */ if (mysql->options.charset_name) - mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + { + if (!strcmp(mysql->options.charset_name, MADB_AUTODETECT_CHARSET_NAME)) + { + char *csname= madb_get_os_character_set(); + if (csname) + { + if (mysql->charset= mysql_find_charset_name(csname)) + mysql_options(mysql, MYSQL_SET_CHARSET_NAME, csname); + } + } + else + mysql->charset= mysql_find_charset_name(mysql->options.charset_name); + } else if (mysql->server_language) mysql->charset= mysql_find_charset_nr(mysql->server_language); else - mysql->charset=default_charset_info; + mysql->charset=ma_default_charset_info; if (!mysql->charset) { @@ -1643,10 +1435,6 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, } } - DBUG_PRINT("info",("Server version = '%s' capabilities: %ld status: %d client_flag: %d", - mysql->server_version,mysql->server_capabilities, - mysql->server_status, client_flag)); - if (mysql->options.init_command) { char **begin= (char **)mysql->options.init_command->buffer; @@ -1671,22 +1459,18 @@ MYSQL *mthd_my_real_connect(MYSQL *mysql, const char *host, const char *user, mysql->options.reconnect= save_reconnect; } - strmov(mysql->net.sqlstate, "00000"); + strcpy(mysql->net.sqlstate, "00000"); - DBUG_PRINT("exit",("Mysql handler: %lx",mysql)); - DBUG_RETURN(mysql); + return(mysql); error: - DBUG_PRINT("error",("message: %u (%s)",net->last_errno,net->last_error)); - { - /* Free alloced memory */ - end_server(mysql); - /* only free the allocated memory, user needs to call mysql_close */ - mysql_close_memory(mysql); - if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) - mysql_close_options(mysql); - } - DBUG_RETURN(0); + /* Free alloced memory */ + end_server(mysql); + /* only free the allocated memory, user needs to call mysql_close */ + mysql_close_memory(mysql); + if (!(((ulong) client_flag) & CLIENT_REMEMBER_OPTIONS)) + mysql_close_options(mysql); + return(0); } struct my_hook_data { @@ -1699,6 +1483,7 @@ struct my_hook_data { Callback hook to make the new VIO accessible via the old MYSQL to calling application when suspending a non-blocking call during automatic reconnect. */ +#ifdef HAVE_NONBLOCK static void my_suspend_hook(my_bool suspend, void *data) { @@ -1711,22 +1496,22 @@ my_suspend_hook(my_bool suspend, void *data) else hook_data->orig_mysql->net.pvio= hook_data->orig_pvio; } - +#endif my_bool STDCALL mysql_reconnect(MYSQL *mysql) { MYSQL tmp_mysql; +#ifdef HAVE_NONBLOCK struct my_hook_data hook_data; struct mysql_async_context *ctxt= NULL; +#endif LIST *li_stmt= mysql->stmts; - DBUG_ENTER("mysql_reconnect"); - /* check if connection handler is active */ if (IS_CONNHDLR_ACTIVE(mysql)) { if (mysql->net.conn_hdlr->plugin && mysql->net.conn_hdlr->plugin->reconnect) - DBUG_RETURN(mysql->net.conn_hdlr->plugin->reconnect(mysql)); + return(mysql->net.conn_hdlr->plugin->reconnect(mysql)); } if (!mysql->options.reconnect || @@ -1735,15 +1520,22 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) /* Allow reconnect next time */ mysql->server_status&= ~SERVER_STATUS_IN_TRANS; my_set_error(mysql, CR_SERVER_GONE_ERROR, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } mysql_init(&tmp_mysql); tmp_mysql.options=mysql->options; + if (mysql->net.conn_hdlr) + { + tmp_mysql.net.conn_hdlr= mysql->net.conn_hdlr; + mysql->net.conn_hdlr= 0; + } + + /* don't reread options from configuration files */ tmp_mysql.options.my_cnf_group= tmp_mysql.options.my_cnf_file= NULL; - +#ifdef HAVE_NONBLOCK if (IS_MYSQL_ASYNC_ACTIVE(mysql)) { hook_data.orig_mysql= mysql; @@ -1751,21 +1543,24 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) hook_data.orig_pvio= mysql->net.pvio; my_context_install_suspend_resume_hook(ctxt, my_suspend_hook, &hook_data); } +#endif if (!mysql_real_connect(&tmp_mysql,mysql->host,mysql->user,mysql->passwd, mysql->db, mysql->port, mysql->unix_socket, mysql->client_flag | CLIENT_REMEMBER_OPTIONS) || mysql_set_character_set(&tmp_mysql, mysql->charset->csname)) { +#ifdef HAVE_NONBLOCK if (ctxt) my_context_install_suspend_resume_hook(ctxt, NULL, NULL); +#endif /* don't free options (CONC-118) */ memset(&tmp_mysql.options, 0, sizeof(struct st_mysql_options)); my_set_error(mysql, tmp_mysql.net.last_errno, tmp_mysql.net.sqlstate, tmp_mysql.net.last_error); mysql_close(&tmp_mysql); - DBUG_RETURN(1); + return(1); } for (;li_stmt;li_stmt= li_stmt->next) @@ -1791,7 +1586,7 @@ my_bool STDCALL mysql_reconnect(MYSQL *mysql) mysql->net.pvio->mysql= mysql; net_clear(&mysql->net); mysql->affected_rows= ~(my_ulonglong) 0; - DBUG_RETURN(0); + return(0); } void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) @@ -1810,6 +1605,37 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) } } +/* + Legacy support of the MariaDB 5.5 version, where timeouts where only in + seconds resolution. Applications that use this will be asked to set a timeout + at the nearest higher whole-seconds value. +*/ +unsigned int STDCALL +mysql_get_timeout_value(const MYSQL *mysql) +{ +#ifdef HAVE_NONBLOCK + unsigned int timeout= mysql->options.extension->async_context->timeout_value; + /* Avoid overflow. */ + if (timeout > UINT_MAX - 999) + return (timeout - 1)/1000 + 1; + else + return (timeout+999)/1000; +#else + return 0; +#endif +} + + +unsigned int STDCALL +mysql_get_timeout_value_ms(const MYSQL *mysql) +{ +#ifdef HAVE_NONBLOCK + return mysql->options.extension->async_context->timeout_value; +#else + return 0; +#endif +} + /************************************************************************** ** Change user and database **************************************************************************/ @@ -1817,14 +1643,12 @@ void ma_invalidate_stmts(MYSQL *mysql, const char *function_name) my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, const char *passwd, const char *db) { - const CHARSET_INFO *s_cs= mysql->charset; + const MARIADB_CHARSET_INFO *s_cs= mysql->charset; char *s_user= mysql->user, *s_passwd= mysql->passwd, *s_db= mysql->db; int rc; - DBUG_ENTER("mysql_change_user"); - if (!user) user=""; if (!passwd) @@ -1837,10 +1661,10 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, else if (mysql->server_language) mysql->charset=mysql_find_charset_nr(mysql->server_language); else - mysql->charset=default_charset_info; + mysql->charset=ma_default_charset_info; - mysql->user= my_strdup(user ? user : "", MYF(MY_WME)); - mysql->passwd= my_strdup(passwd ? passwd : "", MYF(MY_WME)); + mysql->user= strdup(user ? user : ""); + mysql->passwd= strdup(passwd ? passwd : ""); /* db will be set in run_plugin_auth */ mysql->db= 0; @@ -1851,27 +1675,27 @@ my_bool STDCALL mysql_change_user(MYSQL *mysql, const char *user, if (rc==0) { - my_free(s_user); - my_free(s_passwd); - my_free(s_db); + free(s_user); + free(s_passwd); + free(s_db); - if (db && !(mysql->db= my_strdup(db,MYF(MY_WME)))) + if (db && !(mysql->db= strdup(db))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); rc= 1; } } else { - my_free(mysql->user); - my_free(mysql->passwd); - my_free(mysql->db); + free(mysql->user); + free(mysql->passwd); + free(mysql->db); mysql->user= s_user; mysql->passwd= s_passwd; mysql->db= s_db; mysql->charset= s_cs; } - DBUG_RETURN(rc); + return(rc); } @@ -1883,14 +1707,12 @@ int STDCALL mysql_select_db(MYSQL *mysql, const char *db) { int error; - DBUG_ENTER("mysql_select_db"); - DBUG_PRINT("enter",("db: '%s'",db)); - if ((error=simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) - DBUG_RETURN(error); - my_free(mysql->db); - mysql->db=my_strdup(db,MYF(MY_WME)); - DBUG_RETURN(0); + if ((error=ma_simple_command(mysql, COM_INIT_DB,db,(uint) strlen(db),0,0))) + return(error); + free(mysql->db); + mysql->db=strdup(db); + return(0); } @@ -1907,62 +1729,64 @@ static void mysql_close_options(MYSQL *mysql) char **end= begin + mysql->options.init_command->elements; for (;begin < end; begin++) - my_free(*begin); - delete_dynamic(mysql->options.init_command); - my_free(mysql->options.init_command); + free(*begin); + ma_delete_dynamic(mysql->options.init_command); + free(mysql->options.init_command); } - my_free(mysql->options.user); - my_free(mysql->options.host); - my_free(mysql->options.password); - my_free(mysql->options.unix_socket); - my_free(mysql->options.db); - my_free(mysql->options.my_cnf_file); - my_free(mysql->options.my_cnf_group); - my_free(mysql->options.charset_dir); - my_free(mysql->options.charset_name); - my_free(mysql->options.bind_address); - my_free(mysql->options.ssl_key); - my_free(mysql->options.ssl_cert); - my_free(mysql->options.ssl_ca); - my_free(mysql->options.ssl_capath); - my_free(mysql->options.ssl_cipher); + free(mysql->options.user); + free(mysql->options.host); + free(mysql->options.password); + free(mysql->options.unix_socket); + free(mysql->options.db); + free(mysql->options.my_cnf_file); + free(mysql->options.my_cnf_group); + free(mysql->options.charset_dir); + free(mysql->options.charset_name); + free(mysql->options.bind_address); + free(mysql->options.ssl_key); + free(mysql->options.ssl_cert); + free(mysql->options.ssl_ca); + free(mysql->options.ssl_capath); + free(mysql->options.ssl_cipher); if (mysql->options.extension) { +#ifdef HAVE_NONBLOCK struct mysql_async_context *ctxt; - my_free(mysql->options.extension->plugin_dir); - my_free(mysql->options.extension->default_auth); - my_free(mysql->options.extension->db_driver); - my_free(mysql->options.extension->ssl_crl); - my_free(mysql->options.extension->ssl_crlpath); - my_free(mysql->options.extension->ssl_fp); - my_free(mysql->options.extension->ssl_fp_list); - my_free(mysql->options.extension->ssl_pw); - my_free(mysql->options.extension->url); - my_free(mysql->options.extension->connection_handler); + if ((ctxt = mysql->options.extension->async_context) != 0) + { + my_context_destroy(&ctxt->async_context); + free(ctxt); + } +#endif + free(mysql->options.extension->plugin_dir); + free(mysql->options.extension->default_auth); + free(mysql->options.extension->db_driver); + free(mysql->options.extension->ssl_crl); + free(mysql->options.extension->ssl_crlpath); + free(mysql->options.extension->ssl_fp); + free(mysql->options.extension->ssl_fp_list); + free(mysql->options.extension->ssl_pw); + free(mysql->options.extension->url); + free(mysql->options.extension->connection_handler); if(hash_inited(&mysql->options.extension->connect_attrs)) hash_free(&mysql->options.extension->connect_attrs); if (hash_inited(&mysql->options.extension->userdata)) hash_free(&mysql->options.extension->userdata); - if ((ctxt = mysql->options.extension->async_context) != 0) - { - my_context_destroy(&ctxt->async_context); - my_free(ctxt); - } } - my_free(mysql->options.extension); + free(mysql->options.extension); /* clear all pointer */ memset(&mysql->options, 0, sizeof(mysql->options)); } static void mysql_close_memory(MYSQL *mysql) { - my_free(mysql->host_info); - my_free(mysql->user); - my_free(mysql->passwd); - my_free(mysql->db); - my_free(mysql->server_version); + free(mysql->host_info); + free(mysql->user); + free(mysql->passwd); + free(mysql->db); + free(mysql->server_version); mysql->host_info= mysql->server_version=mysql->user=mysql->passwd=mysql->db=0; } @@ -1974,16 +1798,13 @@ void my_set_error(MYSQL *mysql, { va_list ap; - DBUG_ENTER("my_set_error"); - mysql->net.last_errno= error_nr; strncpy(mysql->net.sqlstate, sqlstate, SQLSTATE_LENGTH); va_start(ap, format); - my_vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, - format ? format : ER(error_nr), ap); - DBUG_PRINT("info", ("error(%d) %s", error_nr, mysql->net.last_error)); + vsnprintf(mysql->net.last_error, MYSQL_ERRMSG_SIZE, + format ? format : ER(error_nr), ap); va_end(ap); - DBUG_VOID_RETURN; + return; } void mysql_close_slow_part(MYSQL *mysql) @@ -1994,7 +1815,7 @@ void mysql_close_slow_part(MYSQL *mysql) mysql->status=MYSQL_STATUS_READY; /* Force command */ mysql->options.reconnect=0; if (mysql->net.pvio && mysql->net.buff) - simple_command(mysql, COM_QUIT,NullS,0,1,0); + ma_simple_command(mysql, COM_QUIT,NullS,0,1,0); end_server(mysql); } } @@ -2002,14 +1823,13 @@ void mysql_close_slow_part(MYSQL *mysql) void STDCALL mysql_close(MYSQL *mysql) { - DBUG_ENTER("mysql_close"); if (mysql) /* Some simple safety */ { if (mysql->net.conn_hdlr) { MA_CONNECTION_HANDLER *p= mysql->net.conn_hdlr; p->plugin->close(mysql); - my_free(p); + free(p); } if (mysql->methods) @@ -2023,16 +1843,16 @@ mysql_close(MYSQL *mysql) mysql->host_info=mysql->user=mysql->passwd=mysql->db=0; /* Clear pointers for better safety */ - bzero((char*) &mysql->options,sizeof(mysql->options)); + memset((char*) &mysql->options, 0, sizeof(mysql->options)); if (mysql->extension) - my_free(mysql->extension); + free(mysql->extension); mysql->net.pvio= 0; if (mysql->free_me) - my_free(mysql); + free(mysql); } - DBUG_VOID_RETURN; + return; } @@ -2056,7 +1876,7 @@ mysql_query(MYSQL *mysql, const char *query) int STDCALL mysql_send_query(MYSQL* mysql, const char* query, size_t length) { - return simple_command(mysql, COM_QUERY, query, length, 1,0); + return ma_simple_command(mysql, COM_QUERY, query, length, 1,0); } int mthd_my_read_query_result(MYSQL *mysql) @@ -2065,11 +1885,10 @@ int mthd_my_read_query_result(MYSQL *mysql) ulong field_count; MYSQL_DATA *fields; ulong length; - DBUG_ENTER("mthd_my_read_query_result"); if (!mysql || (length = net_safe_read(mysql)) == packet_error) { - DBUG_RETURN(1); + return(1); } free_old_query(mysql); /* Free old result */ get_info: @@ -2084,14 +1903,14 @@ get_info: pos+=2; if (pos < mysql->net.read_pos+length && net_field_length(&pos)) mysql->info=(char*) pos; - DBUG_RETURN(0); + return(0); } if (field_count == NULL_LENGTH) /* LOAD DATA LOCAL INFILE */ { int error=mysql_handle_local_infile(mysql, (char *)pos); if ((length=net_safe_read(mysql)) == packet_error || error) - DBUG_RETURN(-1); + return(-1); goto get_info; /* Get info packet */ } if (!(mysql->server_status & SERVER_STATUS_AUTOCOMMIT)) @@ -2099,15 +1918,15 @@ get_info: mysql->extra_info= net_field_length_ll(&pos); /* Maybe number of rec */ if (!(fields=mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) - DBUG_RETURN(-1); + return(-1); if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc, (uint) field_count,1, (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)))) - DBUG_RETURN(-1); + return(-1); mysql->status=MYSQL_STATUS_GET_RESULT; mysql->field_count=field_count; - DBUG_RETURN(0); + return(0); } my_bool STDCALL @@ -2119,18 +1938,20 @@ mysql_read_query_result(MYSQL *mysql) int STDCALL mysql_real_query(MYSQL *mysql, const char *query, size_t length) { - DBUG_ENTER("mysql_real_query"); - DBUG_PRINT("enter",("handle: %lx",mysql)); - DBUG_PRINT("query",("Query = \"%.255s\" length=%u",query, length)); + my_bool is_multi= 0; + if (OPT_HAS_EXT_VAL(mysql, multi_command)) + is_multi= mysql->options.extension->multi_command; if (length == -1) length= strlen(query); free_old_query(mysql); - if (simple_command(mysql, COM_QUERY,query,length,1,0)) - DBUG_RETURN(-1); - DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); + if (ma_simple_command(mysql, COM_QUERY,query,length,1,0)) + return(-1); + if (!is_multi) + return(mysql->methods->db_read_query_result(mysql)); + return(0); } /************************************************************************** @@ -2142,29 +1963,27 @@ MYSQL_RES * STDCALL mysql_store_result(MYSQL *mysql) { MYSQL_RES *result; - DBUG_ENTER("mysql_store_result"); if (!mysql->fields) - DBUG_RETURN(0); + return(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } mysql->status=MYSQL_STATUS_READY; /* server is ready */ - if (!(result=(MYSQL_RES*) my_malloc(sizeof(MYSQL_RES)+ - sizeof(ulong)*mysql->field_count, - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result=(MYSQL_RES*) calloc(1, sizeof(MYSQL_RES)+ + sizeof(ulong)*mysql->field_count))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } result->eof=1; /* Marker for buffered */ result->lengths=(ulong*) (result+1); if (!(result->data=mysql->methods->db_read_rows(mysql,mysql->fields,mysql->field_count))) { - my_free(result); - DBUG_RETURN(0); + free(result); + return(0); } mysql->affected_rows= result->row_count= result->data->rows; result->data_cursor= result->data->data; @@ -2174,7 +1993,7 @@ mysql_store_result(MYSQL *mysql) result->current_field=0; result->current_row=0; /* Must do a fetch first */ mysql->fields=0; /* fields is now in result */ - DBUG_RETURN(result); /* Data fetched */ + return(result); /* Data fetched */ } @@ -2192,25 +2011,23 @@ MYSQL_RES * STDCALL mysql_use_result(MYSQL *mysql) { MYSQL_RES *result; - DBUG_ENTER("mysql_use_result"); if (!mysql->fields) - DBUG_RETURN(0); + return(0); if (mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(0); + return(0); } - if (!(result=(MYSQL_RES*) my_malloc(sizeof(*result)+ - sizeof(ulong)*mysql->field_count, - MYF(MY_WME | MY_ZEROFILL)))) - DBUG_RETURN(0); + if (!(result=(MYSQL_RES*) calloc(1, sizeof(*result)+ + sizeof(ulong)*mysql->field_count))) + return(0); result->lengths=(ulong*) (result+1); if (!(result->row=(MYSQL_ROW) - my_malloc(sizeof(result->row[0])*(mysql->field_count+1), MYF(MY_WME)))) + malloc(sizeof(result->row[0])*(mysql->field_count+1)))) { /* Ptrs: to one row */ - my_free(result); - DBUG_RETURN(0); + free(result); + return(0); } result->fields= mysql->fields; result->field_alloc= mysql->field_alloc; @@ -2220,7 +2037,7 @@ mysql_use_result(MYSQL *mysql) result->current_row= 0; mysql->fields=0; /* fields is now in result */ mysql->status=MYSQL_STATUS_USE_RESULT; - DBUG_RETURN(result); /* Data is read to be fetched */ + return(result); /* Data is read to be fetched */ } /************************************************************************** @@ -2240,7 +2057,6 @@ mysql_fetch_field(MYSQL_RES *result) MYSQL_ROW STDCALL mysql_fetch_row(MYSQL_RES *res) { - DBUG_ENTER("mysql_fetch_row"); if (!res) return 0; if (!res->data) @@ -2250,26 +2066,24 @@ mysql_fetch_row(MYSQL_RES *res) if (!(res->handle->methods->db_read_one_row(res->handle,res->field_count,res->row, res->lengths))) { res->row_count++; - DBUG_RETURN(res->current_row=res->row); + return(res->current_row=res->row); } - DBUG_PRINT("info",("end of data")); res->eof=1; res->handle->status=MYSQL_STATUS_READY; /* Don't clear handle in mysql_free_results */ res->handle=0; } - DBUG_RETURN((MYSQL_ROW) NULL); + return((MYSQL_ROW) NULL); } { MYSQL_ROW tmp; if (!res->data_cursor) { - DBUG_PRINT("info",("end of data")); - DBUG_RETURN(res->current_row=(MYSQL_ROW) NULL); + return(res->current_row=(MYSQL_ROW) NULL); } tmp = res->data_cursor->data; res->data_cursor = res->data_cursor->next; - DBUG_RETURN(res->current_row=tmp); + return(res->current_row=tmp); } } @@ -2317,7 +2131,6 @@ void STDCALL mysql_data_seek(MYSQL_RES *result, my_ulonglong row) { MYSQL_ROWS *tmp=0; - DBUG_PRINT("info",("mysql_data_seek(%ld)",(long) row)); if (result->data) for (tmp=result->data->data; row-- && tmp ; tmp = tmp->next) ; result->current_row=0; @@ -2356,12 +2169,10 @@ MYSQL_RES * STDCALL mysql_list_dbs(MYSQL *mysql, const char *wild) { char buff[255]; - DBUG_ENTER("mysql_list_dbs"); - - append_wild(strmov(buff,"show databases"),buff+sizeof(buff),wild); + snprintf(buff, 255, "SHOW DATABASES LIKE '%s'", wild ? wild : "%"); if (mysql_query(mysql,buff)) - DBUG_RETURN(0); - DBUG_RETURN (mysql_store_result(mysql)); + return(0); + return (mysql_store_result(mysql)); } @@ -2374,12 +2185,11 @@ MYSQL_RES * STDCALL mysql_list_tables(MYSQL *mysql, const char *wild) { char buff[255]; - DBUG_ENTER("mysql_list_tables"); - append_wild(strmov(buff,"show tables"),buff+sizeof(buff),wild); + snprintf(buff, 255, "SHOW TABLES LIKE '%s'", wild ? wild : "%"); if (mysql_query(mysql,buff)) - DBUG_RETURN(0); - DBUG_RETURN (mysql_store_result(mysql)); + return(0); + return (mysql_store_result(mysql)); } @@ -2395,23 +2205,22 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) { MYSQL_RES *result; MYSQL_DATA *query; - char buff[257],*end; - DBUG_ENTER("mysql_list_fields"); - DBUG_PRINT("enter",("table: '%s' wild: '%s'",table,wild ? wild : "")); + char buff[255]; + int length= 0; LINT_INIT(query); - end=strmake(strmake(buff, table,128)+1,wild ? wild : "",128); - if (simple_command(mysql, COM_FIELD_LIST,buff,(uint) (end-buff),1,0) || + length= snprintf(buff, 128, "%s%c%s", table, '\0', wild ? wild : ""); + + if (ma_simple_command(mysql, COM_FIELD_LIST,buff,length,1,0) || !(query = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,8))) - DBUG_RETURN(NULL); + return(NULL); free_old_query(mysql); - if (!(result = (MYSQL_RES *) my_malloc(sizeof(MYSQL_RES), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(result = (MYSQL_RES *) calloc(1, sizeof(MYSQL_RES)))) { free_rows(query); - DBUG_RETURN(NULL); + return(NULL); } result->field_alloc=mysql->field_alloc; mysql->fields=0; @@ -2421,7 +2230,7 @@ mysql_list_fields(MYSQL *mysql, const char *table, const char *wild) (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)); result->eof=1; - DBUG_RETURN(result); + return(result); } /* List all running processes (threads) in server */ @@ -2432,23 +2241,22 @@ mysql_list_processes(MYSQL *mysql) MYSQL_DATA *fields; uint field_count; uchar *pos; - DBUG_ENTER("mysql_list_processes"); LINT_INIT(fields); - if (simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) - DBUG_RETURN(0); + if (ma_simple_command(mysql, COM_PROCESS_INFO,0,0,0,0)) + return(0); free_old_query(mysql); pos=(uchar*) mysql->net.read_pos; field_count=(uint) net_field_length(&pos); if (!(fields = mysql->methods->db_read_rows(mysql,(MYSQL_FIELD*) 0,5))) - DBUG_RETURN(NULL); + return(NULL); if (!(mysql->fields=unpack_fields(fields,&mysql->field_alloc,field_count,0, (my_bool) test(mysql->server_capabilities & CLIENT_LONG_FLAG)))) - DBUG_RETURN(0); + return(0); mysql->status=MYSQL_STATUS_GET_RESULT; mysql->field_count=field_count; - DBUG_RETURN(mysql_store_result(mysql)); + return(mysql_store_result(mysql)); } /* In 5.0 this version became an additional parameter shutdown_level */ @@ -2456,43 +2264,38 @@ int STDCALL mysql_shutdown(MYSQL *mysql, enum mysql_enum_shutdown_level shutdown_level) { uchar s_level[2]; - DBUG_ENTER("mysql_shutdown"); s_level[0]= (uchar)shutdown_level; - DBUG_RETURN(simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); + return(ma_simple_command(mysql, COM_SHUTDOWN, (char *)s_level, 1, 0, 0)); } int STDCALL mysql_refresh(MYSQL *mysql,uint options) { uchar bits[1]; - DBUG_ENTER("mysql_refresh"); bits[0]= (uchar) options; - DBUG_RETURN(simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); + return(ma_simple_command(mysql, COM_REFRESH,(char*) bits,1,0,0)); } int STDCALL mysql_kill(MYSQL *mysql,ulong pid) { char buff[12]; - DBUG_ENTER("mysql_kill"); int4store(buff,pid); /* if we kill our own thread, reading the response packet will fail */ - DBUG_RETURN(simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); + return(ma_simple_command(mysql, COM_PROCESS_KILL,buff,4,0,0)); } int STDCALL mysql_dump_debug_info(MYSQL *mysql) { - DBUG_ENTER("mysql_dump_debug_info"); - DBUG_RETURN(simple_command(mysql, COM_DEBUG,0,0,0,0)); + return(ma_simple_command(mysql, COM_DEBUG,0,0,0,0)); } char * STDCALL mysql_stat(MYSQL *mysql) { - DBUG_ENTER("mysql_stat"); - if (simple_command(mysql, COM_STATISTICS,0,0,0,0)) + if (ma_simple_command(mysql, COM_STATISTICS,0,0,0,0)) return mysql->net.last_error; mysql->net.read_pos[mysql->packet_length]=0; /* End of stat string */ if (!mysql->net.read_pos[0]) @@ -2500,19 +2303,18 @@ mysql_stat(MYSQL *mysql) SET_CLIENT_ERROR(mysql, CR_WRONG_HOST_INFO , SQLSTATE_UNKNOWN, 0); return mysql->net.last_error; } - DBUG_RETURN((char*) mysql->net.read_pos); + return((char*) mysql->net.read_pos); } int STDCALL mysql_ping(MYSQL *mysql) { int rc; - DBUG_ENTER("mysql_ping"); - rc= simple_command(mysql, COM_PING,0,0,0,0); + rc= ma_simple_command(mysql, COM_PING,0,0,0,0); /* if connection was terminated and reconnect is true, try again */ if (rc!=0 && mysql->options.reconnect) - rc= simple_command(mysql, COM_PING,0,0,0,0); + rc= ma_simple_command(mysql, COM_PING,0,0,0,0); return rc; } @@ -2593,20 +2395,37 @@ uchar *ma_get_hash_keyval(const uchar *hash_entry, void ma_hash_free(void *p) { - my_free(p); + free(p); } +int mariadb_flush_multi_command(MYSQL *mysql) +{ + int rc; + size_t length= mysql->net.mbuff_pos - mysql->net.mbuff; + + rc= ma_simple_command(mysql, COM_MULTI, mysql->net.mbuff, + length, 1, 0); + /* reset multi_buff */ + mysql->net.mbuff_pos= mysql->net.mbuff; + + if (!rc) + if (mysql->net.mbuff && length > 3 && + (mysql->net.mbuff[3] == COM_STMT_PREPARE || mysql->net.mbuff[3] == COM_STMT_EXECUTE)) + return rc; + else + return mysql->methods->db_read_query_result(mysql); + return rc; +} int STDCALL mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) { va_list ap; void *arg1; +#ifdef HAVE_NONBLOCK + size_t stacksize; struct mysql_async_context *ctxt; - size_t stacksize; - - DBUG_ENTER("mysql_option"); - DBUG_PRINT("enter",("option: %d",(int) option)); +#endif va_start(ap, option); @@ -2624,7 +2443,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.named_pipe=1; /* Force named pipe */ break; case MYSQL_OPT_LOCAL_INFILE: /* Allow LOAD DATA LOCAL ?*/ - if (!arg1 || test(*(uint*) arg1)) + if (!arg1 || test(*(my_bool*) arg1)) mysql->options.client_flag|= CLIENT_LOCAL_FILES; else mysql->options.client_flag&= ~CLIENT_LOCAL_FILES; @@ -2633,20 +2452,16 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) options_add_initcommand(&mysql->options, (char *)arg1); break; case MYSQL_READ_DEFAULT_FILE: - my_free(mysql->options.my_cnf_file); - mysql->options.my_cnf_file=my_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, my_cnf_file, (char *)arg1); break; case MYSQL_READ_DEFAULT_GROUP: - my_free(mysql->options.my_cnf_group); - mysql->options.my_cnf_group=my_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, my_cnf_group, (char *)arg1); break; case MYSQL_SET_CHARSET_DIR: - /* not supported in this version. Since all character sets - are internally available, we don't throw an error */ + OPT_SET_VALUE_STR(&mysql->options, charset_dir, arg1); break; case MYSQL_SET_CHARSET_NAME: - my_free(mysql->options.charset_name); - mysql->options.charset_name=my_strdup((char *)arg1,MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, charset_name, (char *)arg1); break; case MYSQL_OPT_RECONNECT: mysql->options.reconnect= *(uint *)arg1; @@ -2664,10 +2479,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.report_data_truncation= *(my_bool *)arg1; break; case MYSQL_PROGRESS_CALLBACK: - if (!mysql->options.extension) - mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)); + CHECK_OPT_EXTENSION_SET(&mysql->options); if (mysql->options.extension) mysql->options.extension->report_progress= (void (*)(const MYSQL *, uint, uint, double, const char *, uint)) arg1; @@ -2678,32 +2490,8 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MYSQL_DEFAULT_AUTH: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, default_auth, (char *)arg1); break; - /* - case MYSQL_DATABASE_DRIVER: - { - MARIADB_DB_PLUGIN *db_plugin; - if (!(db_plugin= (MARIADB_DB_PLUGIN *)mysql_client_find_plugin(mysql, (char *)arg1, - MYSQL_CLIENT_DB_PLUGIN))) - break; - if (!mysql->options.extension) - mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)); - if (!mysql->options.extension->db_driver) - mysql->options.extension->db_driver= (MARIADB_DB_DRIVER *) - my_malloc(sizeof(MARIADB_DB_DRIVER), MYF(MY_WME | MY_ZEROFILL)); - if (mysql->options.extension && - mysql->options.extension->db_driver) - { - mysql->options.extension->db_driver->plugin = db_plugin; - mysql->options.extension->db_driver->buffer= NULL; - mysql->options.extension->db_driver->name= (char *)db_plugin->name; - mysql->methods= db_plugin->methods; - } - } - break; - */ - case MYSQL_OPT_NONBLOCK: + case MYSQL_OPT_NONBLOCK: +#ifdef HAVE_NONBLOCK if (mysql->options.extension && (ctxt = mysql->options.extension->async_context) != 0) { @@ -2714,10 +2502,10 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (ctxt->suspended) goto end; my_context_destroy(&ctxt->async_context); - my_free(ctxt); + free(ctxt); } if (!(ctxt= (struct mysql_async_context *) - my_malloc(sizeof(*ctxt), MYF(MY_ZEROFILL)))) + calloc(1, sizeof(*ctxt)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2729,13 +2517,12 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) stacksize= ASYNC_CONTEXT_DEFAULT_STACK_SIZE; if (my_context_init(&ctxt->async_context, stacksize)) { - my_free(ctxt); + free(ctxt); goto end; } if (!mysql->options.extension) if(!(mysql->options.extension= (struct st_mysql_options_extension *) - my_malloc(sizeof(struct st_mysql_options_extension), - MYF(MY_WME | MY_ZEROFILL)))) + calloc(1, sizeof(struct st_mysql_options_extension)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2743,6 +2530,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.extension->async_context= ctxt; if (mysql->net.pvio) mysql->net.pvio->async_context= ctxt; +#endif break; case MYSQL_OPT_MAX_ALLOWED_PACKET: if (mysql) @@ -2760,24 +2548,19 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.client_flag &= ~CLIENT_SSL_VERIFY_SERVER_CERT; break; case MYSQL_OPT_SSL_KEY: - my_free(mysql->options.ssl_key); - mysql->options.ssl_key=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_key, (char *)arg1); break; case MYSQL_OPT_SSL_CERT: - my_free(mysql->options.ssl_cert); - mysql->options.ssl_cert=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_cert, (char *)arg1); break; case MYSQL_OPT_SSL_CA: - my_free(mysql->options.ssl_ca); - mysql->options.ssl_ca=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_ca, (char *)arg1); break; case MYSQL_OPT_SSL_CAPATH: - my_free(mysql->options.ssl_capath); - mysql->options.ssl_capath=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_capath, (char *)arg1); break; case MYSQL_OPT_SSL_CIPHER: - my_free(mysql->options.ssl_cipher); - mysql->options.ssl_cipher=my_strdup((char *)arg1,MYF(MY_WME | MY_ALLOW_ZERO_PTR)); + OPT_SET_VALUE_STR(&mysql->options, ssl_cipher, (char *)arg1); break; case MYSQL_OPT_SSL_CRL: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_crl, (char *)arg1); @@ -2815,6 +2598,38 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_OPT_CONNECTION_HANDLER: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, connection_handler, (char *)arg1); break; + case MARIADB_OPT_PORT: + OPT_SET_VALUE_INT(&mysql->options, port, *((uint *)arg1)); + break; + case MARIADB_OPT_UNIXSOCKET: + OPT_SET_VALUE_STR(&mysql->options, unix_socket, arg1); + break; + case MARIADB_OPT_USER: + OPT_SET_VALUE_STR(&mysql->options, user, arg1); + break; + case MARIADB_OPT_HOST: + OPT_SET_VALUE_STR(&mysql->options, host, arg1); + break; + case MARIADB_OPT_SCHEMA: + OPT_SET_VALUE_STR(&mysql->options, db, arg1); + break; + case MARIADB_OPT_DEBUG: + break; + case MARIADB_OPT_FOUND_ROWS: + mysql->options.client_flag|= CLIENT_FOUND_ROWS; + break; + case MARIADB_OPT_INTERACTIVE: + mysql->options.client_flag|= CLIENT_INTERACTIVE; + break; + case MARIADB_OPT_MULTI_RESULTS: + mysql->options.client_flag|= CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_MULTI_STATEMENTS: + mysql->options.client_flag|= CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS; + break; + case MARIADB_OPT_PASSWORD: + OPT_SET_VALUE_STR(&mysql->options, password, arg1); + break; case MARIADB_OPT_USERDATA: { void *data= va_arg(ap, void *); @@ -2846,7 +2661,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) break; } - if (!(buffer= (uchar *)my_malloc(strlen(key) + 1 + sizeof(void *), MYF(MY_ZEROFILL)))) + if (!(buffer= (uchar *)malloc(strlen(key) + 1 + sizeof(void *)))) { SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto end; @@ -2859,7 +2674,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->userdata, buffer)) { - my_free(buffer); + free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2897,8 +2712,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) goto end; } } - if ((buffer= (uchar *)my_malloc(key_len + value_len, - MYF(MY_WME | MY_ZEROFILL)))) + if ((buffer= (uchar *)malloc(key_len + value_len))) { uchar *p= buffer; strcpy(p, arg1); @@ -2908,7 +2722,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) if (hash_insert(&mysql->options.extension->connect_attrs, buffer)) { - my_free(buffer); + free(buffer); SET_CLIENT_ERROR(mysql, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); goto end; } @@ -2927,8 +2741,7 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) mysql->options.secure_auth= *(my_bool *)arg1; break; case MYSQL_OPT_BIND: - my_free(mysql->options.bind_address); - mysql->options.bind_address= my_strdup(arg1, MYF(MY_WME)); + OPT_SET_VALUE_STR(&mysql->options, bind_address, arg1); break; case MARIADB_OPT_SSL_CIPHER_STRENGTH: OPT_SET_EXTENDED_VALUE_INT(&mysql->options, ssl_cipher_strength, *((unsigned int *)arg1)); @@ -2942,18 +2755,52 @@ mysql_optionsv(MYSQL *mysql,enum mysql_option option, ...) case MARIADB_OPT_SSL_PASSPHRASE: OPT_SET_EXTENDED_VALUE_STR(&mysql->options, ssl_pw, (char *)arg1); break; + case MARIADB_OPT_COM_MULTI: + if (&mysql->net.pvio && + !(mysql->server_capabilities & CLIENT_MYSQL)) + { + enum mariadb_com_multi type= *(enum mariadb_com_multi *)arg1; + switch (type) + { + case MARIADB_COM_MULTI_BEGIN: + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, type); + break; + case MARIADB_COM_MULTI_CANCEL: + if (!mysql->options.extension || + mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) + return(-1); + /* reset multi_buff */ + mysql->net.mbuff_pos= mysql->net.mbuff; + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); + break; + case MARIADB_COM_MULTI_END: + if (!mysql->options.extension || + mysql->options.extension->multi_command != MARIADB_COM_MULTI_BEGIN) + return(-1); + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, MARIADB_COM_MULTI_END); + if (mariadb_flush_multi_command(mysql)) + return(-1); + break; + default: + return(-1); + } + OPT_SET_EXTENDED_VALUE_INT(&mysql->options, multi_command, *(my_bool *)arg1); + } + else + return(-1); + break; case MARIADB_OPT_CONNECTION_READ_ONLY: OPT_SET_EXTENDED_VALUE_INT(&mysql->options, read_only, *(my_bool *)arg1); break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); end: va_end(ap); - DBUG_RETURN(1); + return(1); } int STDCALL @@ -2961,9 +2808,6 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) { va_list ap; - DBUG_ENTER("mariadb_get_optionv"); - DBUG_PRINT("enter",("option: %d",(int) option)); - va_start(ap, arg); switch(option) { @@ -3031,6 +2875,15 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) case MYSQL_OPT_NONBLOCK: *((my_bool *)arg)= test(mysql->options.extension && mysql->options.extension->async_context); break; + case MARIADB_OPT_COM_MULTI: + if (!(mysql->server_capabilities & CLIENT_MYSQL)) + { + *((enum mariadb_com_multi *)arg)= mysql->options.extension ? + mysql->options.extension->multi_command : 0; + } + else + return(-1); + break; case MYSQL_OPT_SSL_VERIFY_SERVER_CERT: *((my_bool *)arg)= test(mysql->options.client_flag & CLIENT_SSL_VERIFY_SERVER_CERT); break; @@ -3149,13 +3002,13 @@ mysql_get_optionv(MYSQL *mysql, enum mysql_option option, void *arg, ...) break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); error: va_end(ap); - DBUG_RETURN(-1); + return(-1); } int STDCALL mysql_get_option(MYSQL *mysql, enum mysql_option option, void *arg) @@ -3169,6 +3022,11 @@ mysql_options(MYSQL *mysql,enum mysql_option option, const void *arg) return mysql_optionsv(mysql, option, arg); } +int STDCALL +mysql_options4(MYSQL *mysql,enum mysql_option option, const void *arg1, const void *arg2) +{ + return mysql_optionsv(mysql, option, arg1, arg2); +} /**************************************************************************** ** Functions to get information from the MySQL structure ** These are functions to make shared libraries more usable. @@ -3225,21 +3083,18 @@ my_ulonglong STDCALL mysql_affected_rows(MYSQL *mysql) my_bool STDCALL mysql_autocommit(MYSQL *mysql, my_bool mode) { - DBUG_ENTER("mysql_autocommit"); - DBUG_RETURN((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" : + return((my_bool) mysql_real_query(mysql, (mode) ? "SET autocommit=1" : "SET autocommit=0", 16)); } my_bool STDCALL mysql_commit(MYSQL *mysql) { - DBUG_ENTER("mysql_commit"); - DBUG_RETURN((my_bool)mysql_real_query(mysql, "COMMIT", sizeof("COMMIT"))); + return((my_bool)mysql_real_query(mysql, "COMMIT", sizeof("COMMIT"))); } my_bool STDCALL mysql_rollback(MYSQL *mysql) { - DBUG_ENTER("mysql_rollback"); - DBUG_RETURN((my_bool)mysql_real_query(mysql, "ROLLBACK", sizeof("ROLLBACK"))); + return((my_bool)mysql_real_query(mysql, "ROLLBACK", sizeof("ROLLBACK"))); } my_ulonglong STDCALL mysql_insert_id(MYSQL *mysql) @@ -3264,19 +3119,17 @@ char *STDCALL mysql_info(MYSQL *mysql) my_bool STDCALL mysql_more_results(MYSQL *mysql) { - DBUG_ENTER("mysql_more_results"); - DBUG_RETURN(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); + return(test(mysql->server_status & SERVER_MORE_RESULTS_EXIST)); } int STDCALL mysql_next_result(MYSQL *mysql) { - DBUG_ENTER("mysql_next_result"); /* make sure communication is not blocking */ if (mysql->status != MYSQL_STATUS_READY) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* clear error, and mysql status variables */ @@ -3285,10 +3138,10 @@ int STDCALL mysql_next_result(MYSQL *mysql) if (mysql->server_status & SERVER_MORE_RESULTS_EXIST) { - DBUG_RETURN(mysql->methods->db_read_query_result(mysql)); + return(mysql->methods->db_read_query_result(mysql)); } - DBUG_RETURN(-1); + return(-1); } ulong STDCALL mysql_thread_id(MYSQL *mysql) @@ -3324,7 +3177,7 @@ uint STDCALL mysql_thread_safe(void) ulong STDCALL mysql_escape_string(char *to,const char *from, ulong length) { - return (ulong)mysql_cset_escape_slashes(default_charset_info, to, from, length); + return (ulong)mysql_cset_escape_slashes(ma_default_charset_info, to, from, length); } ulong STDCALL @@ -3339,10 +3192,8 @@ mysql_real_escape_string(MYSQL *mysql, char *to,const char *from, static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) { - DBUG_ENTER("mariadb_get_charset_info"); - if (!cs) - DBUG_VOID_RETURN; + return; cs->number= mysql->charset->nr; cs->csname= mysql->charset->csname; @@ -3353,7 +3204,7 @@ static void mariadb_get_charset_info(MYSQL *mysql, MY_CHARSET_INFO *cs) cs->mbminlen= mysql->charset->char_minlen; cs->mbmaxlen= mysql->charset->char_maxlen; - DBUG_VOID_RETURN; + return; } void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) @@ -3363,8 +3214,7 @@ void STDCALL mysql_get_character_set_info(MYSQL *mysql, MY_CHARSET_INFO *cs) int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { - const CHARSET_INFO *cs; - DBUG_ENTER("mysql_set_character_set"); + const MARIADB_CHARSET_INFO *cs; if (!csname) goto error; @@ -3373,18 +3223,18 @@ int STDCALL mysql_set_character_set(MYSQL *mysql, const char *csname) { char buff[64]; - my_snprintf(buff, 63, "SET NAMES %s", cs->csname); + snprintf(buff, 63, "SET NAMES %s", cs->csname); if (!mysql_real_query(mysql, buff, (uint)strlen(buff))) { mysql->charset= cs; - DBUG_RETURN(0); + return(0); } } error: my_set_error(mysql, CR_CANT_READ_CHARSET, SQLSTATE_UNKNOWN, 0, csname, "compiled_in"); - DBUG_RETURN(mysql->net.last_errno); + return(mysql->net.last_errno); } unsigned int STDCALL mysql_warning_count(MYSQL *mysql) @@ -3406,7 +3256,7 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), if (!mysql_client_init) { mysql_client_init=1; - my_init(); /* Will init threads */ + ma_init(); /* Will init threads */ init_client_errs(); if (mysql_client_plugin_init()) return 1; @@ -3432,7 +3282,6 @@ int STDCALL mysql_server_init(int argc __attribute__((unused)), if ((env = getenv("MYSQL_UNIX_PORT"))) mysql_unix_port = env; } - mysql_debug(NullS); } #ifdef THREAD else @@ -3451,37 +3300,30 @@ void STDCALL mysql_server_end(void) mysql_client_plugin_deinit(); list_free(pvio_callback, 0); - if (my_init_done) - my_end(0); + if (ma_init_done) + ma_end(0); #ifdef HAVE_SSL ma_pvio_ssl_end(); #endif mysql_client_init= 0; - my_init_done= 0; + ma_init_done= 0; } my_bool STDCALL mysql_thread_init(void) { -#ifdef THREAD - return my_thread_init(); -#endif return 0; } void STDCALL mysql_thread_end(void) { - #ifdef THREAD - my_thread_end(); - #endif } int STDCALL mysql_set_server_option(MYSQL *mysql, enum enum_mysql_set_option option) { char buffer[2]; - DBUG_ENTER("mysql_set_server_option"); int2store(buffer, (uint)option); - DBUG_RETURN(simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); + return(ma_simple_command(mysql, COM_SET_OPTION, buffer, sizeof(buffer), 0, 0)); } ulong STDCALL mysql_get_client_version(void) @@ -3529,12 +3371,14 @@ static my_socket mariadb_get_socket(MYSQL *mysql) /* if an asynchronous connect is in progress, we need to obtain pvio handle from async_context until the connection was successfully established. - */ + */ +#ifdef HAVE_NONBLOCK else if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->pvio) { ma_pvio_get_handle(mysql->options.extension->async_context->pvio, &sock); } +#endif return sock; } @@ -3544,23 +3388,20 @@ mysql_get_socket(MYSQL *mysql) return mariadb_get_socket(mysql); } -CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_name(const char *csname) { - return (CHARSET_INFO *)mysql_find_charset_name(csname); + return (MARIADB_CHARSET_INFO *)mysql_find_charset_name(csname); } -CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) +MARIADB_CHARSET_INFO * STDCALL mariadb_get_charset_by_nr(unsigned int csnr) { - return (CHARSET_INFO *)mysql_find_charset_nr(csnr); + return (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(csnr); } my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void *arg, ...) { va_list ap; - DBUG_ENTER("mariadb_get_valuev"); - DBUG_PRINT("enter",("value: %d",(int) value)); - va_start(ap, arg); switch(value) { @@ -3652,7 +3493,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * else goto error; break; - case MARIADB_CONNECTION_CHARSET_INFO: + case MARIADB_CONNECTION_MARIADB_CHARSET_INFO: if (mysql) mariadb_get_charset_info(mysql, (MY_CHARSET_INFO *)arg); else @@ -3671,12 +3512,15 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * goto error; break; case MARIADB_CONNECTION_ASYNC_TIMEOUT_MS: +#ifdef HAVE_NONBLOCK if (mysql && mysql->options.extension && mysql->options.extension->async_context) *((unsigned int *)arg)= mysql->options.extension->async_context->timeout_value; else +#endif goto error; break; case MARIADB_CONNECTION_ASYNC_TIMEOUT: +#ifdef HAVE_NONBLOCK if (mysql && mysql->options.extension && mysql->options.extension->async_context) { unsigned int timeout= mysql->options.extension->async_context->timeout_value; @@ -3686,6 +3530,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * *((unsigned int *)arg)= (timeout+999)/1000; } else +#endif goto error; break; case MARIADB_CHARSET_NAME: @@ -3693,7 +3538,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * char *name; name= va_arg(ap, char *); if (name) - *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_name(name); + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_name(name); else goto error; } @@ -3702,7 +3547,7 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * { unsigned int nr; nr= va_arg(ap, unsigned int); - *((CHARSET_INFO **)arg)= (CHARSET_INFO *)mysql_find_charset_nr(nr); + *((MARIADB_CHARSET_INFO **)arg)= (MARIADB_CHARSET_INFO *)mysql_find_charset_nr(nr); } break; case MARIADB_CONNECTION_SSL_CIPHER: @@ -3760,13 +3605,13 @@ my_bool STDCALL mariadb_get_infov(MYSQL *mysql, enum mariadb_value value, void * break; default: va_end(ap); - DBUG_RETURN(-1); + return(-1); } va_end(ap); - DBUG_RETURN(0); + return(0); error: va_end(ap); - DBUG_RETURN(-1); + return(-1); } my_bool STDCALL mariadb_get_info(MYSQL *mysql, enum mariadb_value value, void *arg) @@ -3839,8 +3684,6 @@ struct st_mariadb_api MARIADB_API= mysql_fetch_field, mysql_escape_string, mysql_real_escape_string, - mysql_debug, - mysql_debug_end, mysql_thread_safe, mysql_warning_count, mysql_sqlstate, @@ -3892,7 +3735,8 @@ struct st_mariadb_api MARIADB_API= mysql_stmt_insert_id, mysql_stmt_field_count, mysql_stmt_next_result, - mysql_stmt_more_results + mysql_stmt_more_results, + mariadb_stmt_execute_direct }; /* @@ -3900,7 +3744,7 @@ struct st_mariadb_api MARIADB_API= * stored in mysql->methods and can be overwritten by * a plugin, e.g. for using another database */ -struct st_mysql_methods MARIADB_DEFAULT_METHODS = { +struct st_mariadb_methods MARIADB_DEFAULT_METHODS = { /* open a connection */ mthd_my_real_connect, /* close connection */ diff --git a/libmariadb/my_stmt.c b/libmariadb/mariadb_stmt.c similarity index 79% rename from libmariadb/my_stmt.c rename to libmariadb/mariadb_stmt.c index 4894ceb2..9347b651 100644 --- a/libmariadb/my_stmt.c +++ b/libmariadb/mariadb_stmt.c @@ -43,16 +43,12 @@ +----------------------------------------------------------------------+ */ -#include "my_global.h" -#include -#include -#include -#include +#include "ma_global.h" +#include +#include +#include #include "mysql.h" -#include "mysql_priv.h" -#include "mysql_version.h" -#include "mysqld_error.h" -#include "errmsg.h" +#include "ma_errmsg.h" #include #include #include @@ -71,9 +67,13 @@ typedef struct { - MEM_ROOT fields_alloc_root; + MA_MEM_ROOT fields_ma_alloc_root; } MADB_STMT_EXTENSION; +MYSQL_DATA *read_rows(MYSQL *mysql,MYSQL_FIELD *mysql_fields, uint fields); +void free_rows(MYSQL_DATA *cur); +MYSQL_FIELD * unpack_fields(MYSQL_DATA *data,MA_MEM_ROOT *alloc,uint fields, my_bool default_value, my_bool long_flag_protocol); + static my_bool is_not_null= 0; static my_bool is_null= 1; @@ -113,7 +113,7 @@ my_bool mthd_supported_buffer_type(enum enum_field_types type) } static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags); - +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close); static int stmt_unbuffered_eof(MYSQL_STMT *stmt, uchar **row) { return MYSQL_NO_DATA; @@ -123,27 +123,24 @@ static int stmt_unbuffered_fetch(MYSQL_STMT *stmt, uchar **row) { ulong pkt_len; - DBUG_ENTER("stmt_unbuffered_fetch"); - pkt_len= net_safe_read(stmt->mysql); - DBUG_PRINT("info",("packet_length= %ld",pkt_len)); if (pkt_len == packet_error) { stmt->fetch_row_func= stmt_unbuffered_eof; - DBUG_RETURN(1); + return(1); } if (stmt->mysql->net.read_pos[0] == 254) { *row = NULL; stmt->fetch_row_func= stmt_unbuffered_eof; - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); } else *row = stmt->mysql->net.read_pos; stmt->result.rows++; - DBUG_RETURN(0); + return(0); } static int stmt_buffered_fetch(MYSQL_STMT *stmt, uchar **row) @@ -168,8 +165,6 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) ulong packet_len; unsigned char *p; - DBUG_ENTER("stmt_read_all_rows"); - pprevious= &result->data; while ((packet_len = net_safe_read(stmt->mysql)) != packet_error) @@ -178,10 +173,10 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) if (packet_len > 7 || p[0] != 254) { /* allocate space for rows */ - if (!(current= (MYSQL_ROWS *)alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) + if (!(current= (MYSQL_ROWS *)ma_alloc_root(&result->alloc, sizeof(MYSQL_ROWS) + packet_len))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } current->data= (MYSQL_ROW)(current + 1); *pprevious= current; @@ -249,13 +244,13 @@ int mthd_stmt_read_all_rows(MYSQL_STMT *stmt) p+=2; stmt->mysql->server_status= uint2korr(p); stmt->result_cursor= result->data; - DBUG_RETURN(0); + return(0); } } stmt->result_cursor= 0; SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); - DBUG_RETURN(1); + return(1); } static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) @@ -263,17 +258,15 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) uchar buf[STMT_ID_LENGTH + 4]; MYSQL_DATA *result= &stmt->result; - DBUG_ENTER("stmt_cursor_fetch"); - if (stmt->state < MYSQL_STMT_USE_OR_STORE_CALLED) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* do we have some prefetched rows available ? */ if (stmt->result_cursor) - DBUG_RETURN(stmt_buffered_fetch(stmt, row)); + return(stmt_buffered_fetch(stmt, row)); if (stmt->mysql->server_status & SERVER_STATUS_LAST_ROW_SENT) stmt->mysql->server_status&= ~SERVER_STATUS_LAST_ROW_SENT; else @@ -281,22 +274,22 @@ static int stmt_cursor_fetch(MYSQL_STMT *stmt, uchar **row) int4store(buf, stmt->stmt_id); int4store(buf + STMT_ID_LENGTH, stmt->prefetch_rows); - if (simple_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) - DBUG_RETURN(1); + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, (char *)buf, sizeof(buf), 1, stmt)) + return(1); /* free previously allocated buffer */ - free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&result->alloc, MYF(MY_KEEP_PREALLOC)); result->data= 0; result->rows= 0; if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) - DBUG_RETURN(1); + return(1); - DBUG_RETURN(stmt_buffered_fetch(stmt, row)); + return(stmt_buffered_fetch(stmt, row)); } /* no more cursor data available */ *row= NULL; - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); } void mthd_stmt_flush_unbuffered(MYSQL_STMT *stmt) @@ -313,10 +306,8 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) size_t truncations= 0; unsigned char *null_ptr, bit_offset= 4; - DBUG_ENTER("stmt_fetch_to_bind"); - if (!stmt->bind_result_done) /* nothing to do */ - DBUG_RETURN(0); + return(0); row++; /* skip status byte */ null_ptr= row; @@ -360,22 +351,20 @@ int mthd_stmt_fetch_to_bind(MYSQL_STMT *stmt, unsigned char *row) null_ptr++; } } - DBUG_RETURN((truncations) ? MYSQL_DATA_TRUNCATED : 0); + return((truncations) ? MYSQL_DATA_TRUNCATED : 0); } MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) { MYSQL *mysql= stmt->mysql; - DBUG_ENTER("mysql_stmt_use_result"); - if (!stmt->field_count || (!stmt->cursor_exists && mysql->status != MYSQL_STATUS_GET_RESULT) || (stmt->cursor_exists && mysql->status != MYSQL_STATUS_READY) || (stmt->state != MYSQL_STMT_WAITING_USE_OR_STORE)) { SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } CLEAR_CLIENT_STMT_ERROR(stmt); @@ -386,7 +375,7 @@ MYSQL_RES *_mysql_stmt_use_result(MYSQL_STMT *stmt) else stmt->fetch_row_func= stmt_cursor_fetch; - DBUG_RETURN(NULL); + return(NULL); } unsigned char *mysql_net_store_length(unsigned char *packet, size_t length) @@ -414,8 +403,6 @@ unsigned char *mysql_net_store_length(unsigned char *packet, size_t length) int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) { - DBUG_ENTER("store_param"); - DBUG_PRINT("info", ("column: %d type: %d", column, stmt->params[column].buffer_type)); switch (stmt->params[column].buffer_type) { case MYSQL_TYPE_TINY: int1store(*p, *(uchar *)stmt->params[column].buffer); @@ -530,7 +517,6 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) ulong len= (ulong)*stmt->params[column].length; /* to is after p. The latter hasn't been moved */ uchar *to = mysql_net_store_length(*p, len); - DBUG_PRINT("info", ("len=x%x", len)); if (len) memcpy(to, stmt->params[column].buffer, len); (*p) = to + len; @@ -540,9 +526,9 @@ int store_param(MYSQL_STMT *stmt, int column, unsigned char **p) default: /* unsupported parameter type */ SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } /* {{{ mysqlnd_stmt_execute_generate_request */ @@ -571,10 +557,9 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req uchar *start= NULL, *p; - DBUG_ENTER("mysql_stmt_execute_generate_request"); - /* preallocate length bytes */ - if (!(start= p= (uchar *)my_malloc(length, MYF(MY_WME | MY_ZEROFILL)))) + /* check: gr */ + if (!(start= p= (uchar *)malloc(length))) goto mem_error; int4store(p, stmt->stmt_id); @@ -597,7 +582,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length+= offset + null_count + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -621,7 +606,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + stmt->param_count * 2 + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -676,7 +661,7 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req { size_t offset= p - start; length= offset + data_size + 20; - if (!(start= (uchar *)my_realloc((gptr)start, length, MYF(MY_WME | MY_ZEROFILL)))) + if (!(start= (uchar *)realloc((gptr)start, length))) goto mem_error; p= start + offset; } @@ -689,7 +674,6 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req if (!stmt->params[i].buffer || *stmt->params[i].is_null || stmt->params[i].buffer_type == MYSQL_TYPE_NULL) { (start + null_byte_offset)[i/8] |= (unsigned char) (1 << (i & 7)); } else { - DBUG_PRINT("info", ("storing parameter %d at offset %d", i, p - start)); store_param(stmt, i, &p); } } @@ -697,14 +681,14 @@ unsigned char* mysql_stmt_execute_generate_request(MYSQL_STMT *stmt, size_t *req } stmt->send_types_to_server= 0; *request_len = (size_t)(p - start); - DBUG_RETURN(start); + return(start); mem_error: SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - my_free(start); + free(start); *request_len= 0; - DBUG_RETURN(NULL); + return(NULL); } /* }}} */ @@ -725,8 +709,6 @@ my_ulonglong STDCALL mysql_stmt_affected_rows(MYSQL_STMT *stmt) my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, void *value) { - DBUG_ENTER("mysql_stmt_attr_get"); - switch (attr_type) { case STMT_ATTR_UPDATE_MAX_LENGTH: *(my_bool *)value= stmt->update_max_length; @@ -738,15 +720,13 @@ my_bool STDCALL mysql_stmt_attr_get(MYSQL_STMT *stmt, enum enum_stmt_attr_type a *(unsigned long *)value= stmt->prefetch_rows; break; default: - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type attr_type, const void *value) { - DBUG_ENTER("mysql_stmt_attr_get"); - switch (attr_type) { case STMT_ATTR_UPDATE_MAX_LENGTH: stmt->update_max_length= *(my_bool *)value; @@ -755,7 +735,7 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a if (*(ulong *)value > (unsigned long) CURSOR_TYPE_READ_ONLY) { SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->flags = *(ulong *)value; break; @@ -767,18 +747,48 @@ my_bool STDCALL mysql_stmt_attr_set(MYSQL_STMT *stmt, enum enum_stmt_attr_type a break; default: SET_CLIENT_STMT_ERROR(stmt, CR_NOT_IMPLEMENTED, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) { - DBUG_ENTER("mysql_stmt_bind_param"); + MYSQL *mysql= stmt->mysql; - if (stmt->state < MYSQL_STMT_PREPARED) { + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + /* for mariadb_stmt_execute_direct we need to bind parameters in advance: + client has to pass a bind array, where last parameter needs to be set + to buffer type MAX_NO_FIELD_TYPES */ + if (stmt->state < MYSQL_STMT_PREPARED && + !(mysql->server_capabilities & CLIENT_MYSQL)) + { + if (!stmt->params) + { + int param_count; + for(param_count= 0; + bind[param_count].buffer_type != MAX_NO_FIELD_TYPES; + param_count++); + stmt->param_count= param_count; + if (stmt->param_count) + { + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + return(1); + } + } + memset(stmt->params, '\0', stmt->param_count * sizeof(MYSQL_BIND)); + } + } + else if (stmt->state < MYSQL_STMT_PREPARED) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->param_count && bind) @@ -794,7 +804,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) !stmt->mysql->methods->db_supported_buffer_type(stmt->params[i].buffer_type)) { SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->params[i].is_null) stmt->params[i].is_null= &is_not_null; @@ -845,7 +855,7 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) break; default: SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); break; } } @@ -853,28 +863,27 @@ my_bool STDCALL mysql_stmt_bind_param(MYSQL_STMT *stmt, MYSQL_BIND *bind) stmt->bind_param_done= stmt->send_types_to_server= 1; CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) { uint i; - DBUG_ENTER("mysql_stmt_bind_result"); if (stmt->state < MYSQL_STMT_PREPARED) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->field_count) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_STMT_METADATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!bind) - DBUG_RETURN(1); + return(1); /* In case of a stored procedure we don't allocate memory for bind in mysql_stmt_prepare @@ -882,13 +891,12 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) if (stmt->field_count && !stmt->bind) { - MEM_ROOT *fields_alloc_root= - &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; -// free_root(fields_alloc_root, MYF(0)); - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + MA_MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } } @@ -900,7 +908,7 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) !stmt->mysql->methods->db_supported_buffer_type(bind[i].buffer_type)) { SET_CLIENT_STMT_ERROR(stmt, CR_UNSUPPORTED_PARAM_TYPE, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->bind[i].is_null) @@ -944,18 +952,18 @@ my_bool STDCALL mysql_stmt_bind_result(MYSQL_STMT *stmt, MYSQL_BIND *bind) stmt->bind_result_done= 1; CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } -my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) +static my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) { char stmt_id[STMT_ID_LENGTH]; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; /* clear memory */ - free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ - free_root(&stmt->mem_root,MYF(0)); - free_root(fields_alloc_root, MYF(0)); + ma_free_root(&stmt->result.alloc, MYF(0)); /* allocated in mysql_stmt_store_result */ + ma_free_root(&stmt->mem_root,MYF(0)); + ma_free_root(fields_ma_alloc_root, MYF(0)); if (stmt->mysql) { @@ -974,7 +982,8 @@ my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) if (stmt->state > MYSQL_STMT_INITTED) { int4store(stmt_id, stmt->stmt_id); - if (simple_command(stmt->mysql,COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1, stmt)) + if (stmt->mysql->methods->db_command(stmt->mysql,COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) { SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); return 1; @@ -986,25 +995,21 @@ my_bool net_stmt_close(MYSQL_STMT *stmt, my_bool remove) my_bool STDCALL mysql_stmt_close(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_close"); - if (stmt && stmt->mysql && stmt->mysql->net.pvio) - mysql_stmt_reset(stmt); + mysql_stmt_internal_reset(stmt, 1); + net_stmt_close(stmt, 1); - my_free(stmt->extension); - my_free(stmt); + free(stmt->extension); + free(stmt); - DBUG_RETURN(0); + return(0); } void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) { my_ulonglong i= offset; MYSQL_ROWS *ptr= stmt->result.data; - DBUG_ENTER("mysql_stmt_data_seek"); - - DBUG_PRINT("info", ("total rows: %llu offset: %llu", stmt->result.rows, offset)); while(i-- && ptr) ptr= ptr->next; @@ -1012,7 +1017,7 @@ void STDCALL mysql_stmt_data_seek(MYSQL_STMT *stmt, my_ulonglong offset) stmt->result_cursor= ptr; stmt->state= MYSQL_STMT_USER_FETCHING; - DBUG_VOID_RETURN; + return; } unsigned int STDCALL mysql_stmt_errno(MYSQL_STMT *stmt) @@ -1035,53 +1040,49 @@ int STDCALL mysql_stmt_fetch(MYSQL_STMT *stmt) unsigned char *row; int rc; - DBUG_ENTER("mysql_stmt_fetch"); - if (stmt->state <= MYSQL_STMT_EXECUTED) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state < MYSQL_STMT_WAITING_USE_OR_STORE || !stmt->field_count) { SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } else if (stmt->state== MYSQL_STMT_WAITING_USE_OR_STORE) { stmt->default_rset_handler(stmt); } if (stmt->state == MYSQL_STMT_FETCH_DONE) - DBUG_RETURN(MYSQL_NO_DATA); + return(MYSQL_NO_DATA); if ((rc= stmt->mysql->methods->db_stmt_fetch(stmt, &row))) { stmt->state= MYSQL_STMT_FETCH_DONE; stmt->mysql->status= MYSQL_STATUS_READY; /* to fetch data again, stmt must be executed again */ - DBUG_RETURN(rc); + return(rc); } if ((rc= stmt->mysql->methods->db_stmt_fetch_to_bind(stmt, row))) { - DBUG_RETURN(rc); + return(rc); } stmt->state= MYSQL_STMT_USER_FETCHING; CLEAR_CLIENT_ERROR(stmt->mysql); CLEAR_CLIENT_STMT_ERROR(stmt); - DBUG_RETURN(0); + return(0); } int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned int column, unsigned long offset) { - DBUG_ENTER("mysql_stmt_fetch"); - if (stmt->state < MYSQL_STMT_USER_FETCHING || column >= stmt->field_count || stmt->state == MYSQL_STMT_FETCH_DONE) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_DATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->bind[column].row_ptr) @@ -1109,7 +1110,7 @@ int STDCALL mysql_stmt_fetch_column(MYSQL_STMT *stmt, MYSQL_BIND *bind, unsigned mysql_ps_fetch_functions[stmt->fields[column].type].func(&bind[0], &stmt->fields[column], &stmt->bind[column].row_ptr); stmt->bind[column].row_ptr= save_ptr; } - DBUG_RETURN(0); + return(0); } unsigned int STDCALL mysql_stmt_field_count(MYSQL_STMT *stmt) @@ -1126,22 +1127,21 @@ my_bool STDCALL mysql_stmt_free_result(MYSQL_STMT *stmt) MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) { - MYSQL_STMT *stmt; - DBUG_ENTER("mysql_stmt_init"); + MYSQL_STMT *stmt= NULL; - if (!(stmt= (MYSQL_STMT *)my_malloc(sizeof(MYSQL_STMT), MYF(MY_WME | MY_ZEROFILL))) || - !(stmt->extension= (MADB_STMT_EXTENSION *)my_malloc(sizeof(MADB_STMT_EXTENSION), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(stmt= (MYSQL_STMT *)calloc(1, sizeof(MYSQL_STMT))) || + !(stmt->extension= (MADB_STMT_EXTENSION *)calloc(1, sizeof(MADB_STMT_EXTENSION)))) { - my_free(stmt); + free(stmt); SET_CLIENT_ERROR(mysql, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } /* fill mysql's stmt list */ stmt->list.data= stmt; stmt->mysql= mysql; + stmt->stmt_id= -1; mysql->stmts= list_add(mysql->stmts, &stmt->list); @@ -1153,11 +1153,11 @@ MYSQL_STMT * STDCALL mysql_stmt_init(MYSQL *mysql) /* set default */ stmt->prefetch_rows= 1; - init_alloc_root(&stmt->mem_root, 2048, 0); - init_alloc_root(&stmt->result.alloc, 4096, 0); - init_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root, 2048, 0); + ma_init_ma_alloc_root(&stmt->mem_root, 2048, 0); + ma_init_ma_alloc_root(&stmt->result.alloc, 4096, 0); + ma_init_ma_alloc_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, 2048, 0); - DBUG_RETURN(stmt); + return(stmt); } my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) @@ -1165,18 +1165,14 @@ my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) ulong packet_length; uchar *p; - DBUG_ENTER("read_prepare_response"); - if ((packet_length= net_safe_read(stmt->mysql)) == packet_error) - DBUG_RETURN(1); - - DBUG_PRINT("info",("packet_length= %ld",packet_length)); + return(1); p= (uchar *)stmt->mysql->net.read_pos; if (0xFF == p[0]) /* Error occured */ { - DBUG_RETURN(1); + return(1); } p++; @@ -1190,52 +1186,51 @@ my_bool mthd_stmt_read_prepare_response(MYSQL_STMT *stmt) p++; stmt->upsert_status.warning_count= uint2korr(p); - DBUG_RETURN(0); + return(0); } my_bool mthd_stmt_get_param_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; - DBUG_ENTER("stmt_get_param_metadata"); - if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) - DBUG_RETURN(1); + return(1); free_rows(result); - DBUG_RETURN(0); + return(0); } my_bool mthd_stmt_get_result_metadata(MYSQL_STMT *stmt) { MYSQL_DATA *result; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; - DBUG_ENTER("stmt_read_result_metadata"); + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; if (!(result= stmt->mysql->methods->db_read_rows(stmt->mysql, (MYSQL_FIELD *)0, 7))) - DBUG_RETURN(1); - if (!(stmt->fields= unpack_fields(result,fields_alloc_root, + return(1); + if (!(stmt->fields= unpack_fields(result,fields_ma_alloc_root, stmt->field_count, 0, stmt->mysql->server_capabilities & CLIENT_LONG_FLAG))) - DBUG_RETURN(1); - DBUG_RETURN(0); + return(1); + return(0); } int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t length) { MYSQL *mysql= stmt->mysql; int rc= 1; - DBUG_ENTER("mysql_stmt_prepare"); - - if (length == -1) - length= strlen(query); + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } + if (length == -1) + length= strlen(query); + + mysql_get_optionv(mysql, MARIADB_OPT_COM_MULTI, &multi); + /* clear flags */ CLEAR_CLIENT_STMT_ERROR(stmt); CLEAR_CLIENT_ERROR(stmt->mysql); @@ -1252,21 +1247,25 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt if (mysql_stmt_reset(stmt)) goto fail; - free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); - free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root, MYF(0)); + ma_free_root(&stmt->mem_root, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root, MYF(0)); stmt->param_count= 0; stmt->field_count= 0; int4store(stmt_id, stmt->stmt_id); - if (simple_command(mysql, COM_STMT_CLOSE, stmt_id, sizeof(stmt_id), 1, stmt)) + if (mysql->methods->db_command(mysql, COM_STMT_CLOSE, stmt_id, + sizeof(stmt_id), 1, stmt)) goto fail; } - if (simple_command(mysql, COM_STMT_PREPARE, query, length, 1, stmt)) + if (mysql->methods->db_command(mysql, COM_STMT_PREPARE, query, length, 1, stmt)) goto fail; - if (stmt->mysql->methods->db_read_prepare_response && - stmt->mysql->methods->db_read_prepare_response(stmt)) + if (multi == MARIADB_COM_MULTI_BEGIN) + return 0; + + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) goto fail; /* metadata not supported yet */ @@ -1285,7 +1284,7 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt } if (stmt->param_count) { - if (!(stmt->params= (MYSQL_BIND *)alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) + if (!(stmt->params= (MYSQL_BIND *)ma_alloc_root(&stmt->mem_root, stmt->param_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; @@ -1295,46 +1294,45 @@ int STDCALL mysql_stmt_prepare(MYSQL_STMT *stmt, const char *query, size_t lengt /* allocated bind buffer for result */ if (stmt->field_count) { - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); goto fail; } } stmt->state = MYSQL_STMT_PREPARED; - DBUG_RETURN(0); + return(0); fail: stmt->state= MYSQL_STMT_INITTED; SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); - DBUG_RETURN(rc); + return(rc); } int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) { unsigned int last_server_status; - DBUG_ENTER("mysql_stmt_store_result"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!stmt->field_count) - DBUG_RETURN(0); + return(0); /* test_pure_coverage requires checking of error_no */ if (stmt->last_errno) - DBUG_RETURN(1); + return(1); if (stmt->state < MYSQL_STMT_EXECUTED) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } last_server_status= stmt->mysql->server_status; @@ -1346,25 +1344,26 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) int4store(buff, stmt->stmt_id); int4store(buff + STMT_ID_LENGTH, (int)~0); - if (simple_command(stmt->mysql, COM_STMT_FETCH, buff, sizeof(buff), 1, stmt)) - DBUG_RETURN(1); + if (stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_FETCH, + buff, sizeof(buff), 1, stmt)) + return(1); /* todo: cursor */ } else if (stmt->mysql->status != MYSQL_STATUS_GET_RESULT) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->mysql->methods->db_stmt_read_all_rows(stmt)) { /* error during read - reset stmt->data */ - free_root(&stmt->result.alloc, 0); + ma_free_root(&stmt->result.alloc, 0); stmt->result.data= NULL; stmt->result.rows= 0; stmt->mysql->status= MYSQL_STATUS_READY; - DBUG_RETURN(1); + return(1); } /* workaround for MDEV 6304: @@ -1388,42 +1387,40 @@ int STDCALL mysql_stmt_store_result(MYSQL_STMT *stmt) stmt->upsert_status.affected_rows= stmt->result.rows; stmt->mysql->affected_rows= stmt->result.rows; - DBUG_RETURN(0); + return(0); } static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) { uint i; - MEM_ROOT *fields_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; - - DBUG_ENTER("madb_alloc_stmt_fields"); + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; if (stmt->mysql->field_count) { - free_root(fields_alloc_root, MYF(0)); - if (!(stmt->fields= (MYSQL_FIELD *)alloc_root(fields_alloc_root, + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->fields= (MYSQL_FIELD *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_FIELD) * stmt->mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->field_count= stmt->mysql->field_count; for (i=0; i < stmt->field_count; i++) { if (stmt->mysql->fields[i].db) - stmt->fields[i].db= strdup_root(fields_alloc_root, stmt->mysql->fields[i].db); + stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].db); if (stmt->mysql->fields[i].table) - stmt->fields[i].table= strdup_root(fields_alloc_root, stmt->mysql->fields[i].table); + stmt->fields[i].table= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].table); if (stmt->mysql->fields[i].org_table) - stmt->fields[i].org_table= strdup_root(fields_alloc_root, stmt->mysql->fields[i].org_table); + stmt->fields[i].org_table= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].org_table); if (stmt->mysql->fields[i].name) - stmt->fields[i].name= strdup_root(fields_alloc_root, stmt->mysql->fields[i].name); + stmt->fields[i].name= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].name); if (stmt->mysql->fields[i].org_name) - stmt->fields[i].org_name= strdup_root(fields_alloc_root, stmt->mysql->fields[i].org_name); + stmt->fields[i].org_name= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].org_name); if (stmt->mysql->fields[i].catalog) - stmt->fields[i].catalog= strdup_root(fields_alloc_root, stmt->mysql->fields[i].catalog); - stmt->fields[i].def= stmt->mysql->fields[i].def ? strdup_root(fields_alloc_root, stmt->mysql->fields[i].def) : NULL; + stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].catalog); + stmt->fields[i].def= stmt->mysql->fields[i].def ? ma_strdup_root(fields_ma_alloc_root, stmt->mysql->fields[i].def) : NULL; stmt->fields[i].type= stmt->mysql->fields[i].type; stmt->fields[i].length= stmt->mysql->fields[i].length; stmt->fields[i].flags= stmt->mysql->fields[i].flags; @@ -1431,77 +1428,29 @@ static int madb_alloc_stmt_fields(MYSQL_STMT *stmt) stmt->fields[i].charsetnr= stmt->mysql->fields[i].charsetnr; stmt->fields[i].max_length= stmt->mysql->fields[i].max_length; } - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } - bzero(stmt->bind, stmt->field_count * sizeof(MYSQL_BIND)); + memset(stmt->bind, 0, stmt->field_count * sizeof(MYSQL_BIND)); stmt->bind_result_done= 0; } - DBUG_RETURN(0); + return(0); } - -int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) +int stmt_read_execute_response(MYSQL_STMT *stmt) { MYSQL *mysql= stmt->mysql; - char *request; - int ret; - size_t request_len= 0; + if (!mysql) + return(1); - DBUG_ENTER("mysql_stmt_execute"); - - if (!stmt->mysql) - { - SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); - } - - if (stmt->state < MYSQL_STMT_PREPARED) - { - SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); - } - - if (stmt->param_count && !stmt->bind_param_done) - { - SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); - } - - if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) - { - stmt->default_rset_handler = _mysql_stmt_use_result; - stmt->default_rset_handler(stmt); - } - if (stmt->state > MYSQL_STMT_WAITING_USE_OR_STORE && stmt->state < MYSQL_STMT_FETCH_DONE && !stmt->result.data) - { - mysql->methods->db_stmt_flush_unbuffered(stmt); - stmt->state= MYSQL_STMT_PREPARED; - stmt->mysql->status= MYSQL_STATUS_READY; - } - - /* clear data, in case mysql_stmt_store_result was called */ - if (stmt->result.data) - { - free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); - stmt->result_cursor= stmt->result.data= 0; - stmt->result.rows= 0; - } - request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); - DBUG_PRINT("info",("request_len=%ld", request_len)); - - ret= test(simple_command(mysql, COM_STMT_EXECUTE, request, request_len, 1, stmt) || - (mysql && mysql->methods->db_read_stmt_result && mysql->methods->db_read_stmt_result(mysql))); - if (request) - my_free(request); - + int ret= test((mysql->methods->db_read_stmt_result && + mysql->methods->db_read_stmt_result(mysql))); /* if a reconnect occured, our connection handle is invalid */ if (!stmt->mysql) - DBUG_RETURN(1); + return(1); /* update affected rows, also if an error occured */ stmt->upsert_status.affected_rows= stmt->mysql->affected_rows; @@ -1511,7 +1460,7 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); stmt->state= MYSQL_STMT_PREPARED; - DBUG_RETURN(1); + return(1); } stmt->upsert_status.last_insert_id= mysql->insert_id; stmt->upsert_status.server_status= mysql->server_status; @@ -1530,36 +1479,36 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) if (!stmt->field_count || mysql->server_status & SERVER_MORE_RESULTS_EXIST) /* fix for ps_bug: test_misc */ { - MEM_ROOT *fields_alloc_root= - &((MADB_STMT_EXTENSION *)stmt->extension)->fields_alloc_root; + MA_MEM_ROOT *fields_ma_alloc_root= + &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; uint i; - free_root(fields_alloc_root, MYF(0)); - if (!(stmt->bind= (MYSQL_BIND *)alloc_root(fields_alloc_root, + ma_free_root(fields_ma_alloc_root, MYF(0)); + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_BIND) * mysql->field_count)) || - !(stmt->fields= (MYSQL_FIELD *)alloc_root(fields_alloc_root, + !(stmt->fields= (MYSQL_FIELD *)ma_alloc_root(fields_ma_alloc_root, sizeof(MYSQL_FIELD) * mysql->field_count))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } stmt->field_count= mysql->field_count; for (i=0; i < stmt->field_count; i++) { if (mysql->fields[i].db) - stmt->fields[i].db= strdup_root(fields_alloc_root, mysql->fields[i].db); + stmt->fields[i].db= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].db); if (mysql->fields[i].table) - stmt->fields[i].table= strdup_root(fields_alloc_root, mysql->fields[i].table); + stmt->fields[i].table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].table); if (mysql->fields[i].org_table) - stmt->fields[i].org_table= strdup_root(fields_alloc_root, mysql->fields[i].org_table); + stmt->fields[i].org_table= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_table); if (mysql->fields[i].name) - stmt->fields[i].name= strdup_root(fields_alloc_root, mysql->fields[i].name); + stmt->fields[i].name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].name); if (mysql->fields[i].org_name) - stmt->fields[i].org_name= strdup_root(fields_alloc_root, mysql->fields[i].org_name); + stmt->fields[i].org_name= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].org_name); if (mysql->fields[i].catalog) - stmt->fields[i].catalog= strdup_root(fields_alloc_root, mysql->fields[i].catalog); - stmt->fields[i].def= mysql->fields[i].def ? strdup_root(fields_alloc_root, mysql->fields[i].def) : NULL; + stmt->fields[i].catalog= ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].catalog); + stmt->fields[i].def= mysql->fields[i].def ? ma_strdup_root(fields_ma_alloc_root, mysql->fields[i].def) : NULL; } } @@ -1609,10 +1558,79 @@ int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) { /* table was altered, see test_wl4166_2 */ SET_CLIENT_STMT_ERROR(stmt, CR_NEW_STMT_METADATA, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } } - DBUG_RETURN(0); + return(0); +} + +int STDCALL mysql_stmt_execute(MYSQL_STMT *stmt) +{ + MYSQL *mysql= stmt->mysql; + char *request; + int ret; + size_t request_len= 0; + enum mariadb_com_multi multi= MARIADB_COM_MULTI_END; + + if (!stmt->mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + return(1); + } + + mysql_get_optionv(mysql, MARIADB_OPT_COM_MULTI, &multi); + + if (stmt->state < MYSQL_STMT_PREPARED) + { + SET_CLIENT_ERROR(mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->param_count && !stmt->bind_param_done) + { + SET_CLIENT_STMT_ERROR(stmt, CR_PARAMS_NOT_BOUND, SQLSTATE_UNKNOWN, 0); + return(1); + } + + if (stmt->state == MYSQL_STMT_WAITING_USE_OR_STORE) + { + stmt->default_rset_handler = _mysql_stmt_use_result; + stmt->default_rset_handler(stmt); + } + if (stmt->state > MYSQL_STMT_WAITING_USE_OR_STORE && stmt->state < MYSQL_STMT_FETCH_DONE && !stmt->result.data) + { + mysql->methods->db_stmt_flush_unbuffered(stmt); + stmt->state= MYSQL_STMT_PREPARED; + stmt->mysql->status= MYSQL_STATUS_READY; + } + + /* clear data, in case mysql_stmt_store_result was called */ + if (stmt->result.data) + { + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + stmt->result_cursor= stmt->result.data= 0; + stmt->result.rows= 0; + } + request= (char *)mysql_stmt_execute_generate_request(stmt, &request_len); + + ret= stmt->mysql->methods->db_command(mysql, COM_STMT_EXECUTE, request, + request_len, 1, stmt); + + if (request) + free(request); + + if (ret) + { + SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, + mysql->net.last_error); + return(1); + } + + if (multi == MARIADB_COM_MULTI_BEGIN) + return(0); + + return(stmt_read_execute_response(stmt)); } static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) @@ -1620,11 +1638,10 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) MYSQL *mysql= stmt->mysql; my_bool ret= 0; - DBUG_ENTER("madb_stmt_reset"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } /* clear error */ @@ -1642,7 +1659,7 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) if (flags & MADB_RESET_STORED && stmt->result_cursor) { - free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); + ma_free_root(&stmt->result.alloc, MYF(MY_KEEP_PREALLOC)); stmt->result.data= NULL; stmt->result.rows= 0; stmt->result_cursor= NULL; @@ -1670,15 +1687,17 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) if (flags & MADB_RESET_SERVER) { /* reset statement on server side */ - if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY) + if (stmt->mysql && stmt->mysql->status == MYSQL_STATUS_READY && + stmt->mysql->net.pvio) { unsigned char cmd_buf[STMT_ID_LENGTH]; int4store(cmd_buf, stmt->stmt_id); - if ((ret= simple_command(mysql,COM_STMT_RESET, (char *)cmd_buf, sizeof(cmd_buf), 0, stmt))) + if ((ret= stmt->mysql->methods->db_command(mysql,COM_STMT_RESET, (char *)cmd_buf, + sizeof(cmd_buf), 0, stmt))) { SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, mysql->net.last_error); - DBUG_RETURN(ret); + return(ret); } } } @@ -1695,23 +1714,21 @@ static my_bool madb_reset_stmt(MYSQL_STMT *stmt, unsigned int flags) } } - DBUG_RETURN(ret); + return(ret); } -my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) +static my_bool mysql_stmt_internal_reset(MYSQL_STMT *stmt, my_bool is_close) { MYSQL *mysql= stmt->mysql; my_bool ret= 1; unsigned int flags= MADB_RESET_LONGDATA | MADB_RESET_BUFFER | MADB_RESET_ERROR; - DBUG_ENTER("mysql_stmt_reset"); - if (!mysql) { /* connection could be invalid, e.g. after mysql_stmt_close or failed reconnect attempt (see bug CONC-97) */ SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state >= MYSQL_STMT_USER_FETCHING && @@ -1739,7 +1756,9 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) stmt->mysql->status= MYSQL_STATUS_READY; } } - ret= madb_reset_stmt(stmt, MADB_RESET_SERVER); + if (!stmt->execute_count) + if (!is_close) + ret= madb_reset_stmt(stmt, MADB_RESET_SERVER); } stmt->state= MYSQL_STMT_PREPARED; stmt->upsert_status.affected_rows= mysql->affected_rows; @@ -1748,29 +1767,33 @@ my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) stmt->upsert_status.warning_count= mysql->warning_count; mysql->status= MYSQL_STATUS_READY; - DBUG_RETURN(ret); + return(ret); } MYSQL_RES * STDCALL mysql_stmt_result_metadata(MYSQL_STMT *stmt) { MYSQL_RES *res; - DBUG_ENTER("mysql_stmt_result_metadata"); - if (!stmt->field_count) - DBUG_RETURN(NULL); + return(NULL); /* aloocate result set structutr and copy stmt information */ - if (!(res= (MYSQL_RES *)my_malloc(sizeof(MYSQL_RES), MYF(MY_WME | MY_ZEROFILL)))) + if (!(res= (MYSQL_RES *)calloc(1, sizeof(MYSQL_RES)))) { SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(NULL); + return(NULL); } res->eof= 1; res->fields= stmt->fields; res->field_count= stmt->field_count; - DBUG_RETURN(res);} + return(res); +} + +my_bool STDCALL mysql_stmt_reset(MYSQL_STMT *stmt) +{ + return mysql_stmt_internal_reset(stmt, 0); +} const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) { @@ -1779,8 +1802,7 @@ const char * STDCALL mysql_stmt_sqlstate(MYSQL_STMT *stmt) MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_tell(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_row_tell"); - DBUG_RETURN(stmt->result_cursor); + return(stmt->result_cursor); } unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt) @@ -1791,48 +1813,46 @@ unsigned long STDCALL mysql_stmt_param_count(MYSQL_STMT *stmt) MYSQL_ROW_OFFSET STDCALL mysql_stmt_row_seek(MYSQL_STMT *stmt, MYSQL_ROW_OFFSET new_row) { MYSQL_ROW_OFFSET old_row; /* for returning old position */ - DBUG_ENTER("mysql_stmt_row_seek"); old_row= stmt->result_cursor; stmt->result_cursor= new_row; - DBUG_RETURN(old_row); + return(old_row); } my_bool STDCALL mysql_stmt_send_long_data(MYSQL_STMT *stmt, uint param_number, const char *data, size_t length) { - DBUG_ENTER("mysql_stmt_send_long_data"); - CLEAR_CLIENT_ERROR(stmt->mysql); CLEAR_CLIENT_STMT_ERROR(stmt); if (stmt->state < MYSQL_STMT_PREPARED || !stmt->params) { SET_CLIENT_STMT_ERROR(stmt, CR_NO_PREPARE_STMT, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (param_number >= stmt->param_count) { SET_CLIENT_STMT_ERROR(stmt, CR_INVALID_PARAMETER_NO, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (length || !stmt->params[param_number].long_data_used) { int ret; - size_t packet_len; - uchar *cmd_buff= (uchar *)my_malloc(packet_len= STMT_ID_LENGTH + 2 + length, MYF(MY_WME | MY_ZEROFILL)); + size_t packet_len= STMT_ID_LENGTH + 2 + length; + uchar *cmd_buff= (uchar *)calloc(1, packet_len); int4store(cmd_buff, stmt->stmt_id); int2store(cmd_buff + STMT_ID_LENGTH, param_number); memcpy(cmd_buff + STMT_ID_LENGTH + 2, data, length); stmt->params[param_number].long_data_used= 1; - ret= simple_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, (char *)cmd_buff, packet_len, 1, stmt); - my_free(cmd_buff); - DBUG_RETURN(ret); + ret= stmt->mysql->methods->db_command(stmt->mysql, COM_STMT_SEND_LONG_DATA, + (char *)cmd_buff, packet_len, 1, stmt); + free(cmd_buff); + return(ret); } - DBUG_RETURN(0); + return(0); } my_ulonglong STDCALL mysql_stmt_insert_id(MYSQL_STMT *stmt) @@ -1847,11 +1867,10 @@ my_ulonglong STDCALL mysql_stmt_num_rows(MYSQL_STMT *stmt) MYSQL_RES* STDCALL mysql_stmt_param_metadata(MYSQL_STMT *stmt) { - DBUG_ENTER("mysql_stmt_param_metadata"); /* server doesn't deliver any information yet, so we just return NULL */ - DBUG_RETURN(NULL); + return(NULL); } my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) @@ -1870,23 +1889,22 @@ my_bool STDCALL mysql_stmt_more_results(MYSQL_STMT *stmt) int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) { int rc= 0; - DBUG_ENTER("mysql_stmt_next_result"); if (!stmt->mysql) { SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (stmt->state < MYSQL_STMT_EXECUTED) { SET_CLIENT_ERROR(stmt->mysql, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); SET_CLIENT_STMT_ERROR(stmt, CR_COMMANDS_OUT_OF_SYNC, SQLSTATE_UNKNOWN, 0); - DBUG_RETURN(1); + return(1); } if (!mysql_stmt_more_results(stmt)) - DBUG_RETURN(-1); + return(-1); if (stmt->state > MYSQL_STMT_EXECUTED && stmt->state < MYSQL_STMT_FETCH_DONE) @@ -1898,7 +1916,7 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) stmt->state= MYSQL_STMT_FETCH_DONE; SET_CLIENT_STMT_ERROR(stmt, stmt->mysql->net.last_errno, stmt->mysql->net.sqlstate, stmt->mysql->net.last_error); - DBUG_RETURN(1); + return(1); } if (stmt->mysql->field_count) @@ -1913,5 +1931,77 @@ int STDCALL mysql_stmt_next_result(MYSQL_STMT *stmt) stmt->field_count= stmt->mysql->field_count; - DBUG_RETURN(rc); + return(rc); +} + +int STDCALL mariadb_stmt_execute_direct(MYSQL_STMT *stmt, + const char *stmt_str, + size_t length) +{ + enum mariadb_com_multi multi= MARIADB_COM_MULTI_BEGIN; + MYSQL *mysql= stmt->mysql; + + if (!mysql) + { + SET_CLIENT_STMT_ERROR(stmt, CR_SERVER_LOST, SQLSTATE_UNKNOWN, 0); + goto fail; + } + + if (mysql_optionsv(mysql, MARIADB_OPT_COM_MULTI, &multi)) + goto fail; + + if (length == -1) + length= strlen(stmt_str); + + if (mysql_stmt_prepare(stmt, stmt_str, length)) + goto fail; + + stmt->state= MYSQL_STMT_PREPARED; + + if (mysql_stmt_execute(stmt)) + goto fail; + + multi= MARIADB_COM_MULTI_END; + if (mysql_optionsv(mysql, MARIADB_OPT_COM_MULTI, &multi)) + goto fail; + + /* read prepare response */ + if (mysql->methods->db_read_prepare_response && + mysql->methods->db_read_prepare_response(stmt)) + goto fail; + + /* metadata not supported yet */ + + if (stmt->param_count && + stmt->mysql->methods->db_stmt_get_param_metadata(stmt)) + { + goto fail; + } + + /* allocated bind buffer for parameters */ + if (stmt->field_count && + stmt->mysql->methods->db_stmt_get_result_metadata(stmt)) + { + goto fail; + } + + /* allocated bind buffer for result */ + if (stmt->field_count) + { + MA_MEM_ROOT *fields_ma_alloc_root= &((MADB_STMT_EXTENSION *)stmt->extension)->fields_ma_alloc_root; + if (!(stmt->bind= (MYSQL_BIND *)ma_alloc_root(fields_ma_alloc_root, stmt->field_count * sizeof(MYSQL_BIND)))) + { + SET_CLIENT_STMT_ERROR(stmt, CR_OUT_OF_MEMORY, SQLSTATE_UNKNOWN, 0); + goto fail; + } + } + stmt->state = MYSQL_STMT_PREPARED; + + /* read execute response packet */ + return stmt_read_execute_response(stmt); +fail: + stmt->state= MYSQL_STMT_INITTED; + SET_CLIENT_STMT_ERROR(stmt, mysql->net.last_errno, mysql->net.sqlstate, + mysql->net.last_error); + return 1; } diff --git a/libmariadb/mf_dirname.c b/libmariadb/mf_dirname.c deleted file mode 100644 index f163735c..00000000 --- a/libmariadb/mf_dirname.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* Functions definied in this file */ - -uint dirname_length(const char *name) -{ - register my_string pos,gpos; -#ifdef FN_DEVCHAR - if ((pos=(char*)strrchr(name,FN_DEVCHAR)) == 0) -#endif - pos=(char*) name-1; - - gpos= pos++; - for ( ; *pos ; pos++) /* Find last FN_LIBCHAR */ - if (*pos == FN_LIBCHAR || *pos == '/' -#ifdef FN_C_AFTER_DIR - || *pos == FN_C_AFTER_DIR || *pos == FN_C_AFTER_DIR_2 -#endif - ) - gpos=pos; - return ((uint) (uint) (gpos+1-(char*) name)); -} - - - /* Gives directory part of filename. Directory ends with '/' */ - /* Returns length of directory part */ - -uint dirname_part(my_string to, const char *name) -{ - uint length; - DBUG_ENTER("dirname_part"); - DBUG_PRINT("enter",("'%s'",name)); - - length=dirname_length(name); - (void) strmake(to,(char*) name,min(length,FN_REFLEN-2)); - convert_dirname(to); /* Convert chars */ - DBUG_RETURN(length); -} /* dirname */ - - - /* convert dirname to use under this system */ - /* If MSDOS converts '/' to '\' */ - /* If VMS converts '<' to '[' and '>' to ']' */ - /* Adds a '/' to end if there isn't one and the last isn't a dev_char */ - /* ARGSUSED */ - -#ifndef FN_DEVCHAR -#define FN_DEVCHAR '\0' /* For easier code */ -#endif - -char *convert_dirname(my_string to) -{ - reg1 char *pos; -#if FN_LIBCHAR != '/' - { - pos=to-1; /* Change from '/' */ - while ((pos=strchr(pos+1,'/')) != 0) - *pos=FN_LIBCHAR; - } -#endif -#ifdef FN_C_BEFORE_DIR_2 - { - for (pos=to ; *pos ; pos++) - { - if (*pos == FN_C_BEFORE_DIR_2) - *pos=FN_C_BEFORE_DIR; - if (*pos == FN_C_AFTER_DIR_2) - *pos=FN_C_AFTER_DIR; - } - } -#else - { /* Append FN_LIBCHAR if not there */ - pos=strend(to); - if (pos != to && (pos[-1] != FN_LIBCHAR && pos[-1] != FN_DEVCHAR)) - { - *pos++=FN_LIBCHAR; - *pos=0; - } - } -#endif - return pos; /* Pointer to end of dir */ -} /* convert_dirname */ diff --git a/libmariadb/mf_fn_ext.c b/libmariadb/mf_fn_ext.c deleted file mode 100644 index 6a9b9d18..00000000 --- a/libmariadb/mf_fn_ext.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Returnerar en pekare till filnamnets extension. */ - -#include "mysys_priv.h" -#include - - /* Return a pointerto the extension of the filename - The pointer points at the extension character (normally '.')) - If there isn't any extension, the pointer points at the end - NULL of the filename - */ - -my_string fn_ext(const char *name) -{ - register my_string pos,gpos; - DBUG_ENTER("fn_ext"); - DBUG_PRINT("mfunkt",("name: '%s'",name)); - -#if defined(FN_DEVCHAR) || defined(FN_C_AFTER_DIR) - { - char buff[FN_REFLEN]; - gpos=(my_string) name+dirname_part(buff,(char*) name); - } -#else - if (!(gpos=strrchr(name,FNLIBCHAR))) - gpos=name; -#endif - pos=strrchr(gpos,FN_EXTCHAR); - DBUG_RETURN (pos ? pos : strend(gpos)); -} /* fn_ext */ diff --git a/libmariadb/mf_format.c b/libmariadb/mf_format.c deleted file mode 100644 index 7dac46cf..00000000 --- a/libmariadb/mf_format.c +++ /dev/null @@ -1,156 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include -#ifdef HAVE_REALPATH -#include -#include -#endif - - /* format a filename with replace of library and extension */ - /* params to and name may be identicall */ - /* function doesn't change name if name != to */ - /* Flag may be: 1 replace filenames library with 'dsk' */ - /* 2 replace extension with 'form' */ - /* 4 Unpack filename (replace ~ with home) */ - /* 8 Pack filename as short as possibly */ - /* 16 Resolve symbolic links for filename */ - /* 32 Resolve filename to full path */ - /* 64 Return NULL if too long path */ - -#ifdef SCO -#define BUFF_LEN 4097 -#else -#ifdef MAXPATHLEN -#define BUFF_LEN MAXPATHLEN -#else -#define BUFF_LEN FN_LEN -#endif -#endif - -my_string fn_format(my_string to, const char *name, const char *dsk, - const char *form, int flag) -{ - reg1 uint length; - char dev[FN_REFLEN], buff[BUFF_LEN], *pos, *startpos; - const char *ext; - DBUG_ENTER("fn_format"); - DBUG_PRINT("enter",("name: %s dsk: %s form: %s flag: %d", - name,dsk,form,flag)); - - /* Kopiera & skippa enheten */ - name+=(length=dirname_part(dev,(startpos=(my_string) name))); - if (length == 0 || flag & 1) - { - (void) strmake(dev,dsk, sizeof(dev) - 2); - /* Use given directory */ - convert_dirname(dev); /* Fix to this OS */ - } - if (flag & 8) - pack_dirname(dev,dev); /* Put in ./.. and ~/.. */ - if (flag & 4) - (void) unpack_dirname(dev,dev); /* Replace ~/.. with dir */ - if ((pos=(char*)strchr(name,FN_EXTCHAR)) != NullS) - { - if ((flag & 2) == 0) /* Skall vi byta extension ? */ - { - length=strlength(name); /* Old extension */ - ext = ""; - } - else - { - length=(uint) (pos-(char*) name); /* Change extension */ - ext= form; - } - } - else - { - length=strlength(name); /* Har ingen ext- tag nya */ - ext=form; - } - - if (strlen(dev)+length+strlen(ext) >= FN_REFLEN || length >= FN_LEN ) - { /* To long path, return original */ - uint tmp_length; - if (flag & 64) - return 0; - tmp_length=strlength(startpos); - DBUG_PRINT("error",("dev: '%s' ext: '%s' length: %d",dev,ext,length)); - (void) strmake(to,startpos,min(tmp_length,FN_REFLEN-1)); - } - else - { - if (to == startpos) - { - bmove(buff,(char*) name,length); /* Save name for last copy */ - name=buff; - } - pos=strmake(strmov(to,dev),name,length); -#ifdef FN_UPPER_CASE - caseup_str(to); -#endif -#ifdef FN_LOWER_CASE - casedn_str(to); -#endif - (void) strmov(pos,ext); /* Don't convert extension */ - } - /* Purify gives a lot of UMR errors when using realpath */ -#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) - if (flag & 16) - { - struct stat stat_buff; - if (flag & 32 || (!lstat(to,&stat_buff) && S_ISLNK(stat_buff.st_mode))) - { - if (realpath(to,buff)) - strmake(to,buff,FN_REFLEN-1); - } - } -#endif - DBUG_RETURN (to); -} /* fn_format */ - - - /* - strlength(const string str) - Return length of string with end-space:s not counted. - */ - -size_s strlength(const char *str) -{ - reg1 my_string pos; - reg2 my_string found; - DBUG_ENTER("strlength"); - - pos=found=(char*) str; - - while (*pos) - { - if (*pos != ' ') - { - while (*++pos && *pos != ' ') {}; - if (!*pos) - { - found=pos; /* String ends here */ - break; - } - } - found=pos; - while (*++pos == ' ') {}; - } - DBUG_RETURN((size_s) (found-(char*) str)); -} /* strlength */ diff --git a/libmariadb/mf_loadpath.c b/libmariadb/mf_loadpath.c deleted file mode 100644 index 641528b8..00000000 --- a/libmariadb/mf_loadpath.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* Returns full load-path for a file. to may be = path */ - /* if path is a hard-path return path */ - /* if path starts with home-dir return path */ - /* if path starts with current dir or parent-dir unpack path */ - /* if there is no path, prepend with own_path_prefix if given */ - /* else unpack path according to current dir */ - -my_string my_load_path(my_string to, const char *path, - const char *own_path_prefix) -{ - char buff[FN_REFLEN]; - DBUG_ENTER("my_load_path"); - DBUG_PRINT("enter",("path: %s prefix: %s",path, - own_path_prefix ? own_path_prefix : "")); - - if ((path[0] == FN_HOMELIB && path[1] == FN_LIBCHAR) || - test_if_hard_path(path)) - VOID(strmov(buff,path)); - else if ((path[0] == FN_CURLIB && path[1] == FN_LIBCHAR) || - (is_prefix((gptr) path,FN_PARENTDIR) && - path[strlen(FN_PARENTDIR)] == FN_LIBCHAR) || - ! own_path_prefix) - { - if (! my_getwd(buff,(uint) (FN_REFLEN-strlen(path)),MYF(0))) - VOID(strcat(buff,path)); - else - VOID(strmov(buff,path)); - } - else - VOID(strxmov(buff,own_path_prefix,path,NullS)); - strmov(to,buff); - DBUG_PRINT("exit",("to: %s",to)); - DBUG_RETURN(to); -} /* my_load_path */ diff --git a/libmariadb/mf_pack.c b/libmariadb/mf_pack.c deleted file mode 100644 index 68be4aa2..00000000 --- a/libmariadb/mf_pack.c +++ /dev/null @@ -1,532 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include -#ifdef HAVE_PWD_H -#include -#endif -#ifdef VMS -#include -#include -#include -#endif /* VMS */ - -static my_string NEAR_F expand_tilde(my_string *path); - - /* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */ - /* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */ - /* to may be == from */ - -void pack_dirname(my_string to, const char *from) -{ - int cwd_err; - uint d_length,length,buff_length= 0; - my_string start; - char buff[FN_REFLEN]; - DBUG_ENTER("pack_dirname"); - - (void) intern_filename(to,from); /* Change to intern name */ - -#ifdef FN_DEVCHAR - if ((start=strrchr(to,FN_DEVCHAR)) != 0) /* Skipp device part */ - start++; - else -#endif - start=to; - - LINT_INIT(buff_length); - if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0)))) - { - buff_length= (uint) strlen(buff); - d_length=(uint) (start-to); - if ((start == to || - (buff_length == d_length && !bcmp(buff,start,d_length))) && - *start != FN_LIBCHAR && *start) - { /* Put current dir before */ - bchange(to,d_length,buff,buff_length,(uint) strlen(to)+1); - } - } - - if ((d_length= cleanup_dirname(to,to)) != 0) - { - length=0; - if (home_dir) - { - length= (uint) strlen(home_dir); - if (home_dir[length-1] == FN_LIBCHAR) - length--; /* Don't test last '/' */ - } - if (length > 1 && length < d_length) - { /* test if /xx/yy -> ~/yy */ - if (bcmp(to,home_dir,length) == 0 && to[length] == FN_LIBCHAR) - { - to[0]=FN_HOMELIB; /* Filename begins with ~ */ - (void) strmov_overlapp(to+1,to+length); - } - } - if (! cwd_err) - { /* Test if cwd is ~/... */ - if (length > 1 && length < buff_length) - { - if (bcmp(buff,home_dir,length) == 0 && buff[length] == FN_LIBCHAR) - { - buff[0]=FN_HOMELIB; - (void) strmov_overlapp(buff+1,buff+length); - } - } - if (is_prefix(to,buff)) - { - length= (uint) strlen(buff); - if (to[length]) - (void) strmov_overlapp(to,to+length); /* Remove everything before */ - else - { - to[0]= FN_CURLIB; /* Put ./ instead of cwd */ - to[1]= FN_LIBCHAR; - to[2]= '\0'; - } - } - } - } - DBUG_PRINT("exit",("to: '%s'",to)); - DBUG_VOID_RETURN; -} /* pack_dirname */ - - - /* remove unwanted chars from dirname */ - /* if "/../" removes prev dir; "/~/" removes all before ~ */ - /* "//" is same as "/", except on Win32 at start of a file */ - /* "/./" is removed */ - /* Unpacks home_dir if "~/.." used */ - /* Unpacks current dir if if "./.." used */ - -uint cleanup_dirname(register my_string to, const char *from) - /* to may be == from */ - -{ - reg5 uint length; - reg2 my_string pos; - reg3 my_string from_ptr; - reg4 my_string start; - char parent[5], /* for "FN_PARENTDIR" */ - buff[FN_REFLEN+1],*end_parentdir; - DBUG_ENTER("cleanup_dirname"); - DBUG_PRINT("enter",("from: '%s'",from)); - - start=buff; - from_ptr=(my_string) from; -#ifdef FN_DEVCHAR - if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0) - { /* Skipp device part */ - length=(uint) (pos-from_ptr)+1; - start=strnmov(buff,from_ptr,length); from_ptr+=length; - } -#endif - - parent[0]=FN_LIBCHAR; - length=(uint) (strmov(parent+1,FN_PARENTDIR)-parent); - for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++) - { - if (*pos == '/') - *pos = FN_LIBCHAR; - if (*pos == FN_LIBCHAR) - { - if ((uint) (pos-start) > length && bcmp(pos-length,parent,length) == 0) - { /* If .../../; skipp prev */ - pos-=length; - if (pos != start) - { /* not /../ */ - pos--; - if (*pos == FN_HOMELIB && (pos == start || pos[-1] == FN_LIBCHAR)) - { - if (!home_dir) - { - pos+=length+1; /* Don't unpack ~/.. */ - continue; - } - pos=strmov(buff,home_dir)-1; /* Unpacks ~/.. */ - if (*pos == FN_LIBCHAR) - pos--; /* home ended with '/' */ - } - if (*pos == FN_CURLIB && (pos == start || pos[-1] == FN_LIBCHAR)) - { - if (my_getwd(curr_dir,FN_REFLEN,MYF(0))) - { - pos+=length+1; /* Don't unpack ./.. */ - continue; - } - pos=strmov(buff,curr_dir)-1; /* Unpacks ./.. */ - if (*pos == FN_LIBCHAR) - pos--; /* home ended with '/' */ - } - end_parentdir=pos; - while (pos >= start && *pos != FN_LIBCHAR) /* remove prev dir */ - pos--; - if (pos[1] == FN_HOMELIB || bcmp(pos,parent,length) == 0) - { /* Don't remove ~user/ */ - pos=strmov(end_parentdir+1,parent); - *pos=FN_LIBCHAR; - continue; - } - } - } - else if ((uint) (pos-start) == length-1 && - !bcmp(start,parent+1,length-1)) - start=pos; /* Starts with "../" */ - else if (pos-start > 0 && pos[-1] == FN_LIBCHAR) - { -#ifdef FN_NETWORK_DRIVES - if (pos-start != 1) -#endif - pos--; /* Remove dupplicate '/' */ - } - else if (pos-start > 1 && pos[-1] == FN_CURLIB && pos[-2] == FN_LIBCHAR) - pos-=2; /* Skipp /./ */ - else if (pos > buff+1 && pos[-1] == FN_HOMELIB && pos[-2] == FN_LIBCHAR) - { /* Found ..../~/ */ - buff[0]=FN_HOMELIB; - buff[1]=FN_LIBCHAR; - start=buff; pos=buff+1; - } - } - } - (void) strmov(to,buff); - DBUG_PRINT("exit",("to: '%s'",to)); - DBUG_RETURN((uint) (pos-buff)); -} /* cleanup_dirname */ - - - /* - On system where you don't have symbolic links, the following - code will allow you to create a file: - directory-name.lnk that should contain the real path - to the directory. This will be used if the directory name - doesn't exists - */ - - -my_bool my_use_symdir=0; /* Set this if you want to use symdirs */ - -#ifdef USE_SYMDIR -void symdirget(char *dir) -{ - char buff[FN_REFLEN]; - char *pos=strend(dir); - if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK)) - { - FILE *fp; - char temp= *(--pos); /* May be "/" or "\" */ - strmov(pos,".sym"); - fp = my_fopen(dir, O_RDONLY,MYF(0)); - *pos++=temp; *pos=0; /* Restore old filename */ - if (fp) - { - if (fgets(buff, sizeof(buff)-1, fp)) - { - for (pos=strend(buff); - pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ; - pos --); - - /* Ensure that the symlink ends with the directory symbol */ - if (pos == buff || pos[-1] != FN_LIBCHAR) - *pos++=FN_LIBCHAR; - - strmake(dir,buff, (uint) (pos-buff)); - } - my_fclose(fp,MYF(0)); - } - } -} -#endif /* USE_SYMDIR */ - - /* Unpacks dirname to name that can be used by open... */ - /* Make that last char of to is '/' if from not empty and - from doesn't end in FN_DEVCHAR */ - /* Uses cleanup_dirname and changes ~/.. to home_dir/.. */ - /* Returns length of new directory */ - -uint unpack_dirname(my_string to, const char *from) - - /* to may be == from */ -{ - uint length,h_length; - char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion; - DBUG_ENTER("unpack_dirname"); - - (void) intern_filename(buff,from); /* Change to intern name */ - length= (uint) strlen(buff); /* Fix that '/' is last */ - if (length && -#ifdef FN_DEVCHAR - buff[length-1] != FN_DEVCHAR && -#endif - buff[length-1] != FN_LIBCHAR && buff[length-1] != '/') - { - buff[length]=FN_LIBCHAR; - buff[length+1]= '\0'; - } - - length=cleanup_dirname(buff,buff); - if (buff[0] == FN_HOMELIB) - { - suffix=buff+1; tilde_expansion=expand_tilde(&suffix); - if (tilde_expansion) - { - length-=(uint) (suffix-buff)-1; - if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN) - { - if (tilde_expansion[h_length-1] == FN_LIBCHAR) - h_length--; - if (buff+h_length < suffix) - bmove(buff+h_length,suffix,length); - else - bmove_upp(buff+h_length+length,suffix+length,length); - bmove(buff,tilde_expansion,h_length); - } - } - } -#ifdef USE_SYMDIR - if (my_use_symdir) - symdirget(buff); -#endif - DBUG_RETURN(system_filename(to,buff)); /* Fix for open */ -} /* unpack_dirname */ - - - /* Expand tilde to home or user-directory */ - /* Path is reset to point at FN_LIBCHAR after ~xxx */ - -static my_string NEAR_F expand_tilde(my_string *path) -{ - if (path[0][0] == FN_LIBCHAR) - return home_dir; /* ~/ expanded to home */ -#ifdef HAVE_GETPWNAM - { - char *str,save; - struct passwd *user_entry; - - if (!(str=strchr(*path,FN_LIBCHAR))) - str=strend(*path); - save= *str; *str= '\0'; - user_entry=getpwnam(*path); - *str=save; - endpwent(); - if (user_entry) - { - *path=str; - return user_entry->pw_dir; - } - } -#endif - return (my_string) 0; -} - - /* fix filename so it can be used by open, create .. */ - /* to may be == from */ - /* Returns to */ - -my_string unpack_filename(my_string to, const char *from) -{ - uint length,n_length; - char buff[FN_REFLEN]; - DBUG_ENTER("unpack_filename"); - - length=dirname_part(buff,from); /* copy & convert dirname */ - n_length=unpack_dirname(buff,buff); - if (n_length+strlen(from+length) < FN_REFLEN) - { - (void) strmov(buff+n_length,from+length); - (void) system_filename(to,buff); /* Fix to usably filename */ - } - else - (void) system_filename(to,from); /* Fix to usably filename */ - DBUG_RETURN(to); -} /* unpack_filename */ - - - /* Convert filename (unix standard) to system standard */ - /* Used before system command's like open(), create() .. */ - /* Returns to */ - -uint system_filename(my_string to, const char *from) -{ -#ifndef FN_C_BEFORE_DIR - return (uint) (strmake(to,from,FN_REFLEN-1)-to); -#else /* VMS */ - - /* change 'dev:lib/xxx' to 'dev:[lib]xxx' */ - /* change 'dev:xxx' to 'dev:xxx' */ - /* change './xxx' to 'xxx' */ - /* change './lib/' or lib/ to '[.lib]' */ - /* change '/x/y/z to '[x.y]x' */ - /* change 'dev:/x' to 'dev:[000000]x' */ - - int libchar_found,length; - my_string to_pos,from_pos,pos; - char buff[FN_REFLEN]; - DBUG_ENTER("system_filename"); - - libchar_found=0; - (void) strmov(buff,from); /* If to == from */ - from_pos= buff; - if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skipp device part */ - { - pos++; - to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos)); - from_pos=pos; - } - else - to_pos=to; - - if (from_pos[0] == FN_CURLIB && from_pos[1] == FN_LIBCHAR) - from_pos+=2; /* Skipp './' */ - if (strchr(from_pos,FN_LIBCHAR)) - { - *(to_pos++) = FN_C_BEFORE_DIR; - if (strinstr(from_pos,FN_ROOTDIR) == 1) - { - from_pos+=strlen(FN_ROOTDIR); /* Actually +1 but... */ - if (! strchr(from_pos,FN_LIBCHAR)) - { /* No dir, use [000000] */ - to_pos=strmov(to_pos,FN_C_ROOT_DIR); - libchar_found++; - } - } - else - *(to_pos++)=FN_C_DIR_SEP; /* '.' gives current dir */ - - while ((pos=strchr(from_pos,FN_LIBCHAR))) - { - if (libchar_found++) - *(to_pos++)=FN_C_DIR_SEP; /* Add '.' between dirs */ - if (strinstr(from_pos,FN_PARENTDIR) == 1 && - from_pos+strlen(FN_PARENTDIR) == pos) - to_pos=strmov(to_pos,FN_C_PARENT_DIR); /* Found '../' */ - else - to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos)); - from_pos=pos+1; - } - *(to_pos++)=FN_C_AFTER_DIR; - } - length=(int) (strmov(to_pos,from_pos)-to); - DBUG_PRINT("exit",("name: '%s'",to)); - DBUG_RETURN((uint) length); -#endif -} /* system_filename */ - - - /* Fix a filename to intern (UNIX format) */ - -my_string intern_filename(my_string to, const char *from) -{ -#ifndef VMS - { - uint length; - char buff[FN_REFLEN]; - if (from == to) - { /* Dirname may destroy from */ - strmov(buff,from); - from=buff; - } - length=dirname_part(to,from); /* Copy dirname & fix chars */ - (void) strcat(to,from+length); - return (to); - } -#else /* VMS */ - - /* change 'dev:[lib]xxx' to 'dev:lib/xxx' */ - /* change 'dev:xxx' to 'dev:xxx' */ - /* change 'dev:x/y/[.lib]' to 'dev:x/y/lib/ */ - /* change '[.lib]' to './lib/' */ - /* change '[x.y]' or '[x.][y]' or '[x][.y]' to '/x/y/' */ - /* change '[000000.x] or [x.000000]' to '/x/' */ - - int par_length,root_length; - my_string pos,from_pos,to_pos,end_pos; - char buff[FN_REFLEN]; - - (void) strmov(buff,from); - convert_dirname(buff); /* change '<>' to '[]' */ - from_pos=buff; - if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skipp device part */ - { - pos++; - to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos)); - from_pos=pos; - } - else - to_pos=to; - - root_length=strlen(FN_C_ROOT_DIR); - if ((pos = strchr(from_pos,FN_C_BEFORE_DIR)) && - (end_pos = strrchr(pos+1,FN_C_AFTER_DIR))) - { - to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos)); - /* Copy all between ':' and '[' */ - from_pos=pos+1; - if (strinstr(from_pos,FN_C_ROOT_DIR) == 1 && - (from_pos[root_length] == FN_C_DIR_SEP || - from_pos[root_length] == FN_C_AFTER_DIR)) - { - from_pos+=root_length+1; - } - else if (*from_pos == FN_C_DIR_SEP) - *(to_pos++) = FN_CURLIB; /* Set ./ first */ - *(to_pos++) = FN_LIBCHAR; - - par_length=strlen(FN_C_PARENT_DIR); - pos=to_pos; - for (; from_pos <= end_pos ; from_pos++) - { - switch (*from_pos) { - case FN_C_DIR_SEP: - case FN_C_AFTER_DIR: - if (pos != to_pos) - { - if ((int) (to_pos-pos) == root_length && - is_suffix(pos,FN_C_ROOT_DIR)) - to_pos=pos; /* remove root-pos */ - else - { - *(to_pos++)=FN_LIBCHAR; /* Find lib */ - pos=to_pos; - } - } - break; - case FN_C_BEFORE_DIR: - break; - case '-': /* *(FN_C_PARENT_DIR): */ - if (to_pos[-1] == FN_LIBCHAR && - strncmp(from_pos,FN_C_PARENT_DIR,par_length) == 0) - { /* Change '-' to '..' */ - to_pos=strmov(to_pos,FN_PARENTDIR); - *(to_pos++)=FN_LIBCHAR; - pos=to_pos; - from_pos+=par_length-1; - break; - } - /* Fall through */ - default: - *(to_pos++)= *from_pos; - break; - } - } - } - (void) strmov(to_pos,from_pos); - return (to); -#endif /* VMS */ -} /* intern_filename */ diff --git a/libmariadb/mf_path.c b/libmariadb/mf_path.c deleted file mode 100644 index c53157de..00000000 --- a/libmariadb/mf_path.c +++ /dev/null @@ -1,120 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - -static char *find_file_in_path(char *to,const char *name); - - /* Finds where program can find it's files. - pre_pathname is found by first locking at progname (argv[0]). - if progname contains path the path is returned. - else if progname is found in path, return it - else if progname is given and POSIX environment variable "_" is set - then path is taken from "_". - If filename doesn't contain a path append MY_BASEDIR_VERSION or - MY_BASEDIR if defined, else append "/my/running". - own_path_name_part is concatinated to result. - my_path puts result in to and returns to */ - -my_string my_path(my_string to, const char *progname, - const char *own_pathname_part) -{ - my_string start,end,prog; - DBUG_ENTER("my_path"); - - start=to; /* Return this */ - if (progname && (dirname_part(to, progname) || - find_file_in_path(to,progname) || - ((prog=getenv("_")) != 0 && dirname_part(to,prog)))) - { - VOID(intern_filename(to,to)); - if (!test_if_hard_path(to)) - { - if (!my_getwd(curr_dir,FN_REFLEN,MYF(0))) - bchange(to,0,curr_dir, (uint) strlen(curr_dir), (uint) strlen(to)+1); - } - } - else - { - if ((end = getenv("MY_BASEDIR_VERSION")) == 0 && - (end = getenv("MY_BASEDIR")) == 0) - { -#ifdef DEFAULT_BASEDIR - end= (char*) DEFAULT_BASEDIR; -#else - end= (char*) "/my/"; -#endif - } - VOID(intern_filename(to,end)); - to=strend(to); - if (to != start && to[-1] != FN_LIBCHAR) - *to++ = FN_LIBCHAR; - VOID(strmov(to,own_pathname_part)); - } - DBUG_PRINT("exit",("to: '%s'",start)); - DBUG_RETURN(start); -} /* my_path */ - - - /* test if file without filename is found in path */ - /* Returns to if found and to has dirpart if found, else NullS */ - -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) -#define F_OK 0 -#define PATH_SEP ';' -#define PROGRAM_EXTENSION ".exe" -#else -#define PATH_SEP ':' -#endif - -static char *find_file_in_path(char *to, const char *name) -{ - char *path,*pos,dir[2]; - const char *ext=""; - - if (!(path=getenv("PATH"))) - return NullS; - dir[0]=FN_LIBCHAR; dir[1]=0; -#ifdef PROGRAM_EXTENSION - if (!fn_ext(name)[0]) - ext=PROGRAM_EXTENSION; -#endif - - for (pos=path ; (pos=strchr(pos,PATH_SEP)) ; path= ++pos) - { - if (path != pos) - { - strxmov(strnmov(to,path,(uint) (pos-path)),dir,name,ext,NullS); - if (!access(to,F_OK)) - { - to[(uint) (pos-path)+1]=0; /* Return path only */ - return to; - } - } - } -#ifdef _WIN32 - to[0]=FN_CURLIB; - strxmov(to+1,dir,name,ext,NullS); - if (!access(to,F_OK)) /* Test in current dir */ - { - to[2]=0; /* Leave ".\" */ - return to; - } -#endif - return NullS; /* File not found */ -} diff --git a/libmariadb/mf_unixpath.c b/libmariadb/mf_unixpath.c deleted file mode 100644 index 6ae29f99..00000000 --- a/libmariadb/mf_unixpath.c +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include - - /* convert filename to unix style filename */ - /* If MSDOS converts '\' to '/' */ - -void to_unix_path(my_string to __attribute__((unused))) -{ -#if FN_LIBCHAR != '/' - { - to--; - while ((to=strchr(to+1,FN_LIBCHAR)) != 0) - *to='/'; - } -#endif -} diff --git a/libmariadb/mf_wcomp.c b/libmariadb/mf_wcomp.c deleted file mode 100644 index 5f1ab9b8..00000000 --- a/libmariadb/mf_wcomp.c +++ /dev/null @@ -1,68 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Funktions for comparing with wild-cards */ - -#include "mysys_priv.h" - - /* Test if a string is "comparable" to a wild-card string */ - /* returns 0 if the strings are "comparable" */ - -char wild_many='*'; -char wild_one='?'; -char wild_prefix=0; - -int wild_compare(register const char *str, register const char *wildstr) -{ - reg3 int flag; - DBUG_ENTER("wild_compare"); - - while (*wildstr) - { - while (*wildstr && *wildstr != wild_many && *wildstr != wild_one) - { - if (*wildstr == wild_prefix && wildstr[1]) - wildstr++; - if (*wildstr++ != *str++) DBUG_RETURN(1); - } - if (! *wildstr ) DBUG_RETURN (*str != 0); - if (*wildstr++ == wild_one) - { - if (! *str++) DBUG_RETURN (1); /* One char; skipp */ - } - else - { /* Found '*' */ - if (!*wildstr) DBUG_RETURN(0); /* '*' as last char: OK */ - flag=(*wildstr != wild_many && *wildstr != wild_one); - do - { - if (flag) - { - char cmp; - if ((cmp= *wildstr) == wild_prefix && wildstr[1]) - cmp=wildstr[1]; - while (*str && *str != cmp) - str++; - if (!*str) DBUG_RETURN (1); - } - if (wild_compare(str,wildstr) == 0) DBUG_RETURN (0); - } while (*str++ && wildstr[0] != wild_many); - DBUG_RETURN(1); - } - } - DBUG_RETURN (*str != '\0'); -} /* wild_compare */ diff --git a/libmariadb/mulalloc.c b/libmariadb/mulalloc.c deleted file mode 100644 index 8a7ee312..00000000 --- a/libmariadb/mulalloc.c +++ /dev/null @@ -1,53 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - - /* Malloc many pointers at the same time */ - /* format myFlags,ptr,length,ptr,length ... until null ptr */ - -#include "mysys_priv.h" -#include - -gptr my_multi_malloc(myf myFlags, ...) -{ - va_list args; - char **ptr,*start,*res; - uint tot_length,length; - DBUG_ENTER("my_multi_malloc"); - - va_start(args,myFlags); - tot_length=0; - while ((ptr=va_arg(args, char **))) - { - length=va_arg(args,uint); - tot_length+=ALIGN_SIZE(length); - } - va_end(args); - - if (!(start=(char *) my_malloc(tot_length,myFlags))) - DBUG_RETURN(0); /* purecov: inspected */ - - va_start(args,myFlags); - res=start; - while ((ptr=va_arg(args, char **))) - { - *ptr=res; - length=va_arg(args,uint); - res+=ALIGN_SIZE(length); - } - va_end(args); - DBUG_RETURN((gptr) start); -} diff --git a/libmariadb/my_div.c b/libmariadb/my_div.c deleted file mode 100644 index 24794679..00000000 --- a/libmariadb/my_div.c +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" - -my_string my_filename(File fd) -{ - DBUG_ENTER("my_filename"); - if (fd >= MY_NFILE) - DBUG_RETURN((char*) "UNKNOWN"); - if (fd >= 0 && my_file_info[fd].type != UNOPEN) - { - DBUG_RETURN(my_file_info[fd].name); - } - else - DBUG_RETURN((char*) "UNOPENED"); /* Debug message */ -} diff --git a/libmariadb/my_error.c b/libmariadb/my_error.c deleted file mode 100644 index 9778206a..00000000 --- a/libmariadb/my_error.c +++ /dev/null @@ -1,124 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#include - -/* Define some external variables for error handling */ - -const char ** NEAR my_errmsg[MAXMAPS]={0,0,0,0}; -char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE]; - -/* Error message to user */ -/*VARARGS2*/ - -int my_error(int nr,myf MyFlags, ...) -{ - va_list ap; - uint olen, plen; - reg1 const char *tpos; - reg2 char *endpos; - char * par; - char ebuff[ERRMSGSIZE+20]; - DBUG_ENTER("my_error"); - - va_start(ap,MyFlags); - DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); - - if (nr / ERRMOD == GLOB && my_errmsg[GLOB] == 0) - init_glob_errs(); - - olen=(uint) strlen(tpos=my_errmsg[nr / ERRMOD][nr % ERRMOD - EE_FIRSTERROR]); - endpos=ebuff; - - while (*tpos) - { - if (tpos[0] != '%') - { - *endpos++= *tpos++; /* Copy ordinary char */ - olen++; - continue; - } - if (*++tpos == '%') /* test if %% */ - { - olen--; - } - else - { - /* Skipp if max size is used (to be compatible with printf) */ - while (isdigit(*tpos) || *tpos == '.' || *tpos == '-') - tpos++; - if (*tpos == 'l') /* Skipp 'l' argument */ - tpos++; - if (*tpos == 's') /* String parameter */ - { - par = va_arg(ap, char *); - plen = (uint) strlen(par); - if (olen + plen < ERRMSGSIZE+2) /* Replace if possible */ - { - endpos=strmov(endpos,par); - tpos++; - olen+=plen-2; - continue; - } - } - else if (*tpos == 'd' || *tpos == 'u') /* Integer parameter */ - { - register int iarg; - iarg = va_arg(ap, int); - if (*tpos == 'd') - plen= (uint) (int2str((long) iarg,endpos, -10) - endpos); - else - plen= (uint) (int2str((long) (uint) iarg,endpos,10)- endpos); - if (olen + plen < ERRMSGSIZE+2) /* Replace parameter if possible */ - { - endpos+=plen; - tpos++; - olen+=plen-2; - continue; - } - } - } - *endpos++='%'; /* % used as % or unknown code */ - } - *endpos='\0'; /* End of errmessage */ - va_end(ap); - DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags)); -} - - /* Error as printf */ - -int my_printf_error (uint error, const char *format, myf MyFlags, ...) -{ - va_list args; - char ebuff[ERRMSGSIZE+20]; - - va_start(args,MyFlags); - (void) vsprintf (ebuff,format,args); - va_end(args); - return (*error_handler_hook)(error, ebuff, MyFlags); -} - - /* Give message using error_handler_hook */ - -int my_message(uint error, const char *str, register myf MyFlags) -{ - return (*error_handler_hook)(error, str, MyFlags); -} diff --git a/libmariadb/my_fopen.c b/libmariadb/my_fopen.c deleted file mode 100644 index 5c0fb40d..00000000 --- a/libmariadb/my_fopen.c +++ /dev/null @@ -1,178 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "my_static.h" -#include -#include "mysys_err.h" - -static void make_ftype(my_string to,int flag); - - /* Open a file as stream */ - -FILE *my_fopen(const char *FileName, int Flags, myf MyFlags) - /* Path-name of file */ - /* Read | write .. */ - /* Special flags */ -{ - FILE *fd; - char type[5]; - DBUG_ENTER("my_fopen"); - DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); - - make_ftype(type,Flags); -#ifdef _WIN32 - if (fopen_s(&fd, FileName, type) == 0) -#else - if ((fd = fopen(FileName, type)) != 0) -#endif - { - /* - The test works if MY_NFILE < 128. The problem is that fileno() is char - on some OS (SUNOS). Actually the filename save isn't that important - so we can ignore if this doesn't work. - */ - if ((uint) fileno(fd) >= MY_NFILE) - { - thread_safe_increment(my_stream_opened,&THR_LOCK_open); - DBUG_RETURN(fd); /* safeguard */ - } - pthread_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fileno(fd)].name = (char*) - my_strdup(FileName,MyFlags))) - { - my_stream_opened++; - my_file_info[fileno(fd)].type = STREAM_BY_FOPEN; - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("stream: %lx",fd)); - DBUG_RETURN(fd); - } - pthread_mutex_unlock(&THR_LOCK_open); - (void) my_fclose(fd,MyFlags); - my_errno=ENOMEM; - } - else - my_errno=errno; - DBUG_PRINT("error",("Got error %d on open",my_errno)); - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error((Flags & O_RDONLY) || (Flags == O_RDONLY ) ? EE_FILENOTFOUND : - EE_CANTCREATEFILE, - MYF(ME_BELL+ME_WAITTANG), FileName,my_errno); - DBUG_RETURN((FILE*) 0); -} /* my_fopen */ - - - /* Close a stream */ - -int my_fclose(FILE *fd, myf MyFlags) -{ - int err,file; - DBUG_ENTER("my_fclose"); - DBUG_PRINT("my",("stream: %lx MyFlags: %d",fd, MyFlags)); - - pthread_mutex_lock(&THR_LOCK_open); - file=fileno(fd); - if ((err = fclose(fd)) < 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG), - my_filename(file),errno); - } - else - my_stream_opened--; - if ((uint) file < MY_NFILE && my_file_info[file].type != UNOPEN) - { - my_file_info[file].type = UNOPEN; - my_free(my_file_info[file].name); - } - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_RETURN(err); -} /* my_fclose */ - - - /* Make a stream out of a file handle */ - /* Name may be 0 */ - -FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags) -{ - FILE *fd; - char type[5]; - DBUG_ENTER("my_fdopen"); - DBUG_PRINT("my",("Fd: %d Flags: %d MyFlags: %d", - Filedes, Flags, MyFlags)); - - make_ftype(type,Flags); - if ((fd = fdopen(Filedes, type)) == 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_CANT_OPEN_STREAM, MYF(ME_BELL+ME_WAITTANG),errno); - } - else - { - pthread_mutex_lock(&THR_LOCK_open); - my_stream_opened++; - if (Filedes < MY_NFILE) - { - if (my_file_info[Filedes].type != UNOPEN) - { - my_file_opened--; /* File is opened with my_open ! */ - } - else - { - my_file_info[Filedes].name= my_strdup(name,MyFlags); - } - my_file_info[Filedes].type = STREAM_BY_FDOPEN; - } - pthread_mutex_unlock(&THR_LOCK_open); - } - - DBUG_PRINT("exit",("stream: %lx",fd)); - DBUG_RETURN(fd); -} /* my_fdopen */ - - - /* Make a filehandler-open-typestring from ordinary inputflags */ - -static void make_ftype(register my_string to, register int flag) -{ -#if FILE_BINARY /* If we have binary-files */ - reg3 int org_flag=flag; -#endif - flag&= ~FILE_BINARY; /* remove binary bit */ - if (flag == O_RDONLY) - *to++= 'r'; - else if (flag == O_WRONLY) - *to++= 'w'; - else - { /* Add '+' after theese */ - if (flag == O_RDWR) - *to++= 'r'; - else if (flag & O_APPEND) - *to++= 'a'; - else - *to++= 'w'; /* Create file */ - *to++= '+'; - } -#if FILE_BINARY /* If we have binary-files */ - if (org_flag & FILE_BINARY) - *to++='b'; -#endif - *to='\0'; -} /* make_ftype */ diff --git a/libmariadb/my_fstream.c b/libmariadb/my_fstream.c deleted file mode 100644 index 39a15b10..00000000 --- a/libmariadb/my_fstream.c +++ /dev/null @@ -1,171 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* USE_MY_STREAM isn't set because we can't thrust my_fclose! */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include - -#ifdef HAVE_FSEEKO -#undef ftell -#undef fseek -#define ftell(A) ftello(A) -#define fseek(A,B,C) fseeko((A),(B),(C)) -#endif - - /* Read a chunk of bytes from a file */ - /* Returns (uint) -1 if error as my_read() */ - -uint my_fread(FILE *stream, unsigned char *Buffer, uint Count, myf MyFlags) - /* File descriptor */ - /* Buffer must be at least count bytes */ - /* Max number of bytes returnd */ - /* Flags on what to do on error */ -{ - uint readbytes; - DBUG_ENTER("my_fread"); - DBUG_PRINT("my",("stream: %lx Buffer: %lx Count: %u MyFlags: %d", - stream, Buffer, Count, MyFlags)); - - if ((readbytes = (uint) fread(Buffer,sizeof(char),(size_t) Count,stream)) - != Count) - { - DBUG_PRINT("error",("Read only %d bytes",readbytes)); - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if (ferror(stream)) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - else - if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - } - my_errno=errno ? errno : -1; - if (ferror(stream) || MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN((uint) -1); /* Return with error */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Read ok */ - DBUG_RETURN(readbytes); -} /* my_fread */ - - -/* -** Write a chunk of bytes to a stream -** Returns (uint) -1 if error as my_write() -** Does retries if interrupted -*/ - -uint my_fwrite(FILE *stream, const unsigned char *Buffer, uint Count, myf MyFlags) -{ - uint writenbytes=0; - off_t seekptr; -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) - uint errors; -#endif - DBUG_ENTER("my_fwrite"); - DBUG_PRINT("my",("stream: %lx Buffer: %lx Count: %u MyFlags: %d", - stream, Buffer, Count, MyFlags)); - -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) - errors=0; -#endif - seekptr=ftell(stream); - for (;;) - { - uint writen; - if ((writen = (uint) fwrite((char*) Buffer,sizeof(char), - (size_t) Count, stream)) != Count) - { - DBUG_PRINT("error",("Write only %d bytes",writenbytes)); - my_errno=errno; - if (writen != (uint) -1) - { - seekptr+=writen; - Buffer+=writen; - writenbytes+=writen; - Count-=writen; - } -#ifdef EINTR - if (errno == EINTR) - { - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); - continue; - } -#endif -#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM) -#ifdef THREAD - if (my_thread_var->abort) - MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif - if (errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL)) - { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH)); - sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); - VOID(my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0))); - continue; - } -#endif - if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP))) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(fileno(stream)),errno); - } - writenbytes=(uint) -1; /* Return that we got error */ - break; - } - } - if (MyFlags & (MY_NABP | MY_FNABP)) - writenbytes=0; /* Everything OK */ - else - writenbytes+=writen; - break; - } - DBUG_RETURN(writenbytes); -} /* my_fwrite */ - - /* Seek to position in file */ - /* ARGSUSED */ - -my_off_t my_fseek(FILE *stream, my_off_t pos, int whence, myf MyFlags) -{ - DBUG_ENTER("my_fseek"); - DBUG_PRINT("my",("stream: %lx pos: %lu whence: %d MyFlags: %d", - stream, pos, whence, MyFlags)); - DBUG_RETURN(fseek(stream, (off_t) pos, whence) ? - MY_FILEPOS_ERROR : (my_off_t) ftell(stream)); -} /* my_seek */ - - - /* Tell current position of file */ - /* ARGSUSED */ - -my_off_t my_ftell(FILE *stream, myf MyFlags) -{ - off_t pos; - DBUG_ENTER("my_ftell"); - DBUG_PRINT("my",("stream: %lx MyFlags: %d",stream, MyFlags)); - pos=ftell(stream); - DBUG_PRINT("exit",("ftell: %lu",(ulong) pos)); - DBUG_RETURN((my_off_t) pos); -} /* my_ftell */ diff --git a/libmariadb/my_getwd.c b/libmariadb/my_getwd.c deleted file mode 100644 index 6e32b9c1..00000000 --- a/libmariadb/my_getwd.c +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* my_setwd() and my_getwd() works with intern_filenames !! */ - -#include "mysys_priv.h" -#include -#include "mysys_err.h" -#ifdef HAVE_GETWD -#include -#endif -#if defined(MSDOS) || defined(_WIN32) -#include -#include -#include -#endif -#if defined(OS2) -#include -#endif - -#ifdef __EMX__ -// chdir2 support also drive change -#define chdir _chdir2 -#endif - - /* Gets current working directory in buff. Directory is allways ended - with FN_LIBCHAR */ - /* One must pass a buffer to my_getwd. One can allways use - curr_dir[] */ - -int my_getwd(my_string buf, uint size, myf MyFlags) -{ - my_string pos; - DBUG_ENTER("my_getwd"); - DBUG_PRINT("my",("buf: %lx size: %d MyFlags %d", buf,size,MyFlags)); - -#if ! defined(MSDOS) - if (curr_dir[0]) /* Current pos is saved here */ - VOID(strmake(buf,&curr_dir[0],size-1)); - else -#endif - { -#if defined(HAVE_GETCWD) -#ifdef _WIN32 - if (!(_getcwd(buf,size-2)) && MyFlags & MY_WME) -#else - if (!(getcwd(buf,size-2)) && MyFlags & MY_WME) -#endif - { - my_errno=errno; - my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); - } -#elif defined(HAVE_GETWD) - { - char pathname[MAXPATHLEN]; - getwd(pathname); - strmake(buf,pathname,size-1); - } -#elif defined(VMS) - if (!getcwd(buf,size-2,1) && MyFlags & MY_WME) - { - my_errno=errno; - my_error(EE_GETWD,MYF(ME_BELL+ME_WAITTANG),errno); - return(-1); - } - intern_filename(buf,buf); -#else -#error "No way to get current directory" -#endif - if (*((pos=strend(buf))-1) != FN_LIBCHAR) /* End with FN_LIBCHAR */ - { - pos[0]= FN_LIBCHAR; - pos[1]=0; - } - (void) strmake(&curr_dir[0],buf,(size_s) (FN_REFLEN-1)); - } - DBUG_RETURN(0); -} /* my_getwd */ - - - /* Set new working directory */ - -int my_setwd(const char *dir, myf MyFlags) -{ - int res; - size_s length; - my_string start,pos; -#if defined(VMS) || defined(MSDOS) || defined(OS2) - char buff[FN_REFLEN]; -#endif - DBUG_ENTER("my_setwd"); - DBUG_PRINT("my",("dir: '%s' MyFlags %d", dir, MyFlags)); - - start=(my_string) dir; -#if defined(MSDOS) || defined(OS2) /* OS2/MSDOS chdir can't change drive */ -#if !defined(_DDL) && !defined(WIN32) - if ((pos=(char*) strchr(dir,FN_DEVCHAR)) != 0) - { - uint drive,drives; - - pos++; /* Skipp FN_DEVCHAR */ - drive=(uint) (toupper(dir[0])-'A'+1); drives= (uint) -1; - if ((pos-(byte*) dir) == 2 && drive > 0 && drive < 32) - { -#ifdef OS2 - _chdrive(drive); - drives = _getdrive(); -#else - _dos_setdrive(drive,&drives); - _dos_getdrive(&drives); -#endif - } - if (drive != drives) - { - *pos='\0'; /* Dir is now only drive */ - my_errno=errno; - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),dir,ENOENT); - DBUG_RETURN(-1); - } - dir=pos; /* drive changed, change now path */ - } -#endif - if (*((pos=strend(dir)-1)) == FN_LIBCHAR && pos != dir) - { - strmov(buff,dir)[-1]=0; /* Remove last '/' */ - dir=buff; - } -#endif /* MSDOS*/ - if (! dir[0] || (dir[0] == FN_LIBCHAR && dir[1] == 0)) - dir=FN_ROOTDIR; -#ifdef VMS - { - pos=strmov(buff,dir); - if (pos[-1] != FN_LIBCHAR) - { - pos[0]=FN_LIBCHAR; /* Mark as directory */ - pos[1]=0; - } - system_filename(buff,buff); /* Change to VMS format */ - dir=buff; - } -#endif /* VMS */ -#ifdef _WIN32 - if ((res=_chdir((char*) dir)) != 0) -#else - if ((res=chdir((char*) dir)) != 0) -#endif - { - my_errno=errno; - if (MyFlags & MY_WME) - my_error(EE_SETWD,MYF(ME_BELL+ME_WAITTANG),start,errno); - } - else - { - if (test_if_hard_path(start)) - { /* Hard pathname */ - pos=strmake(&curr_dir[0],start,(size_s) FN_REFLEN-1); - if (pos[-1] != FN_LIBCHAR) - { - length=(uint) (pos-(char*) curr_dir); - curr_dir[length]=FN_LIBCHAR; /* must end with '/' */ - curr_dir[length+1]='\0'; - } - } - else - curr_dir[0]='\0'; /* Don't save name */ - } - DBUG_RETURN(res); -} /* my_setwd */ - - - - /* Test if hard pathname */ - /* Returns 1 if dirname is a hard path */ - -int test_if_hard_path(register const char *dir_name) -{ - if (dir_name[0] == FN_HOMELIB && dir_name[1] == FN_LIBCHAR) - return (home_dir != NullS && test_if_hard_path(home_dir)); - if (dir_name[0] == FN_LIBCHAR) - return (TRUE); -#ifdef FN_DEVCHAR - return (strchr(dir_name,FN_DEVCHAR) != 0); -#else - return FALSE; -#endif -} /* test_if_hard_path */ diff --git a/libmariadb/my_init.c b/libmariadb/my_init.c deleted file mode 100644 index 391f5290..00000000 --- a/libmariadb/my_init.c +++ /dev/null @@ -1,273 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "my_static.h" -#include "mysys_err.h" -#include "m_ctype.h" -#include -#include -#ifdef HAVE_GETRUSAGE -#include -/* extern int getrusage(int, struct rusage *); */ -#endif -#include -#ifdef VMS -#include -#include -#endif -#ifdef _WIN32 -#ifdef _MSC_VER -#include -#include -#endif -my_bool have_tcpip=0; -static void my_win_init(void); -static my_bool win32_have_tcpip(void); -static my_bool win32_init_tcp_ip(); -#else -#define my_win_init() -#endif - -my_bool my_init_done=0; - - - -static ulong atoi_octal(const char *str) -{ - long int tmp; - while (*str && isspace(*str)) - str++; - str2int(str, - (*str == '0' ? 8 : 10), /* Octalt or decimalt */ - 0, INT_MAX, &tmp); - return (ulong) tmp; -} - - - /* Init my_sys functions and my_sys variabels */ - -void my_init(void) -{ - my_string str; - if (my_init_done) - return; - my_init_done=1; -#ifdef THREAD -#if defined(HAVE_PTHREAD_INIT) - pthread_init(); /* Must be called before DBUG_ENTER */ -#endif - my_thread_global_init(); -#ifndef _WIN32 - sigfillset(&my_signals); /* signals blocked by mf_brkhant */ -#endif -#endif /* THREAD */ -#ifdef UNIXWARE_7 - (void) isatty(0); /* Go around connect() bug in UW7 */ -#endif - { - DBUG_ENTER("my_init"); - DBUG_PROCESS(my_progname ? my_progname : (char*) "unknown"); - if (!home_dir) - { /* Don't initialize twice */ - if ((home_dir=getenv("HOME")) != 0) - home_dir=intern_filename(home_dir_buff,home_dir); -#ifndef VMS - /* Default creation of new files */ - if ((str=getenv("UMASK")) != 0) - my_umask=(int) (atoi_octal(str) | 0600); - /* Default creation of new dir's */ - if ((str=getenv("UMASK_DIR")) != 0) - my_umask_dir=(int) (atoi_octal(str) | 0700); -#endif -#ifdef VMS - init_ctype(); /* Stupid linker don't link _ctype.c */ -#endif - DBUG_PRINT("exit",("home: '%s'",home_dir)); - } -#ifdef _WIN32 - my_win_init(); -#endif - DBUG_VOID_RETURN; - } -} /* my_init */ - - - /* End my_sys */ - -void my_end(int infoflag) -{ - FILE *info_file; - if (!(info_file=DBUG_FILE)) - info_file=stderr; - if (infoflag & MY_CHECK_ERROR || info_file != stderr) - { /* Test if some file is left open */ - if (my_file_opened | my_stream_opened) - { - sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened); - (void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); - DBUG_PRINT("error",("%s",errbuff[0])); - } - } - if (infoflag & MY_GIVE_INFO || info_file != stderr) - { -#ifdef HAVE_GETRUSAGE - struct rusage rus; - if (!getrusage(RUSAGE_SELF, &rus)) - fprintf(info_file,"\n\ -User time %.2f, System time %.2f\n\ -Maximum resident set size %ld, Integral resident set size %ld\n\ -Non-physical pagefaults %ld, Physical pagefaults %ld, Swaps %ld\n\ -Blocks in %ld out %ld, Messages in %ld out %ld, Signals %ld\n\ -Voluntary context switches %ld, Involuntary context switches %ld\n", - (rus.ru_utime.tv_sec * SCALE_SEC + - rus.ru_utime.tv_usec / SCALE_USEC) / 100.0, - (rus.ru_stime.tv_sec * SCALE_SEC + - rus.ru_stime.tv_usec / SCALE_USEC) / 100.0, - rus.ru_maxrss, rus.ru_idrss, - rus.ru_minflt, rus.ru_majflt, - rus.ru_nswap, rus.ru_inblock, rus.ru_oublock, - rus.ru_msgsnd, rus.ru_msgrcv, rus.ru_nsignals, - rus.ru_nvcsw, rus.ru_nivcsw); -#endif -#if defined(MSDOS) && !defined(_WIN32) - fprintf(info_file,"\nRun time: %.1f\n",(double) clock()/CLOCKS_PER_SEC); -#endif -#if defined(SAFEMALLOC) - TERMINATE(stderr); /* Give statistic on screen */ -#elif defined(_WIN32) && defined(_MSC_VER) - _CrtSetReportMode( _CRT_WARN, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_WARN, _CRTDBG_FILE_STDERR ); - _CrtSetReportMode( _CRT_ERROR, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_ERROR, _CRTDBG_FILE_STDERR ); - _CrtSetReportMode( _CRT_ASSERT, _CRTDBG_MODE_FILE ); - _CrtSetReportFile( _CRT_ASSERT, _CRTDBG_FILE_STDERR ); - _CrtCheckMemory(); - _CrtDumpMemoryLeaks(); -#endif - } -#ifdef THREAD - pthread_mutex_destroy(&THR_LOCK_malloc); - pthread_mutex_destroy(&THR_LOCK_open); - pthread_mutex_destroy(&THR_LOCK_net); - DBUG_END(); /* Must be done before my_thread_end */ - my_thread_end(); - my_thread_global_end(); -#endif -#ifdef _WIN32 - if (have_tcpip); - WSACleanup( ); -#endif /* _WIN32 */ - my_init_done=0; -} /* my_end */ - -#ifdef _WIN32 - -/* - This code is specially for running MySQL, but it should work in - other cases too. - - Inizializzazione delle variabili d'ambiente per Win a 32 bit. - - Vengono inserite nelle variabili d'ambiente (utilizzando cosi' - le funzioni getenv e putenv) i valori presenti nelle chiavi - del file di registro: - - HKEY_LOCAL_MACHINE\software\MySQL - - Se la kiave non esiste nonn inserisce nessun valore -*/ - -/* Crea la stringa d'ambiente */ - -void setEnvString(char *ret, const char *name, const char *value) -{ - DBUG_ENTER("setEnvString"); - strxmov(ret, name,"=",value,NullS); - DBUG_VOID_RETURN ; -} - -static void my_win_init(void) -{ - DBUG_ENTER("my_win_init"); - win32_init_tcp_ip(); - DBUG_VOID_RETURN ; -} - - -/*------------------------------------------------------------------ -** Name: CheckForTcpip| Desc: checks if tcpip has been installed on system -** According to Microsoft Developers documentation the first registry -** entry should be enough to check if TCP/IP is installed, but as expected -** this doesn't work on all Win32 machines :( -------------------------------------------------------------------*/ - -#define TCPIPKEY "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters" -#define WINSOCK2KEY "SYSTEM\\CurrentControlSet\\Services\\Winsock2\\Parameters" -#define WINSOCKKEY "SYSTEM\\CurrentControlSet\\Services\\Winsock\\Parameters" - -static my_bool win32_have_tcpip(void) -{ - HKEY hTcpipRegKey; - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, TCPIPKEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) - { - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCK2KEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) - { - if (RegOpenKeyEx ( HKEY_LOCAL_MACHINE, WINSOCKKEY, 0, KEY_READ, - &hTcpipRegKey) != ERROR_SUCCESS) - if (!getenv("HAVE_TCPIP") || have_tcpip) /* Provide a workaround */ - return (FALSE); - } - } - RegCloseKey ( hTcpipRegKey); - return (TRUE); -} - -static my_bool win32_init_tcp_ip() -{ - if (win32_have_tcpip()) - { - WORD wVersionRequested = MAKEWORD( 2, 0 ); - WSADATA wsaData; - /* Be a good citizen: maybe another lib has already initialised - sockets, so dont clobber them unless necessary */ - if (WSAStartup( wVersionRequested, &wsaData )) - { - /* Load failed, maybe because of previously loaded - incompatible version; try again */ - WSACleanup( ); - if (!WSAStartup( wVersionRequested, &wsaData )) - have_tcpip=1; - } - else - { - if (wsaData.wVersion != wVersionRequested) - { - /* Version is no good, try again */ - WSACleanup( ); - if (!WSAStartup( wVersionRequested, &wsaData )) - have_tcpip=1; - } - else - have_tcpip=1; - } - } - return(0); -} -#endif diff --git a/libmariadb/my_lib.c b/libmariadb/my_lib.c deleted file mode 100644 index b0092c4b..00000000 --- a/libmariadb/my_lib.c +++ /dev/null @@ -1,614 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* TODO: check for overun of memory for names. */ -/* Convert MSDOS-TIME to standar time_t */ - -#define USES_TYPES /* sys/types is included */ -#include "mysys_priv.h" -#include -#include /* Structs used by my_dir,includes sys/types */ -#include "mysys_err.h" -#if defined(HAVE_DIRENT_H) -# include -# define NAMLEN(dirent) strlen((dirent)->d_name) -#else -#ifndef OS2 -# define dirent direct -#endif -# define NAMLEN(dirent) (dirent)->d_namlen -# if defined(HAVE_SYS_NDIR_H) -# include -# endif -# if defined(HAVE_SYS_DIR_H) -# include -# endif -# if defined(HAVE_NDIR_H) -# include -# endif -# if defined(MSDOS) || defined(_WIN32) -# include -# ifdef __BORLANDC__ -# include -# endif -# endif -#endif -#ifdef VMS -#include -#include -#include -#endif - -#ifdef OS2 -#include "my_os2dirsrch.h" -#endif - -#if defined(THREAD) && defined(HAVE_READDIR_R) -#define READDIR(A,B,C) ((errno=readdir_r(A,B,&C)) != 0 || !C) -#else -#define READDIR(A,B,C) (!(C=readdir(A))) -#endif - - -#define STARTSIZE ONCE_ALLOC_INIT*8 /* some mallocmargin */ - -static int comp_names(struct fileinfo *a,struct fileinfo *b); - - - /* We need this because program don't know with malloc we used */ - -void my_dirend(MY_DIR *buffer) -{ - DBUG_ENTER("my_dirend"); - if (buffer) - my_free(buffer); - DBUG_VOID_RETURN; -} /* my_dirend */ - - - /* Compare in sort of filenames */ - -static int comp_names(struct fileinfo *a, struct fileinfo *b) -{ - return (strcmp(a->name,b->name)); -} /* comp_names */ - - -#if !defined(MSDOS) && !defined(_WIN32) - -MY_DIR *my_dir(const char *path, myf MyFlags) -{ - DIR *dirp; - struct dirent *dp; - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - uint fcnt,i,size,firstfcnt, maxfcnt,length; - char tmp_path[FN_REFLEN+1],*tmp_file; - my_ptrdiff_t diff; - bool eof; -#ifdef THREAD - char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1]; -#endif - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_lock(&THR_LOCK_open); -#endif - - dirp = opendir(directory_file_name(tmp_path,(my_string) path)); - size = STARTSIZE; - if (dirp == NULL || ! (buffer = (char *) my_malloc(size, MyFlags))) - goto error; - - fcnt = 0; - tmp_file=strend(tmp_path); - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - -#ifdef THREAD - dp= (struct dirent*) dirent_tmp; -#else - dp=0; -#endif - eof=0; - for (;;) - { - while (fcnt < maxfcnt && - !(eof= READDIR(dirp,(struct dirent*) dirent_tmp,dp))) - { - bzero((gptr) (fnames+fcnt),sizeof(fnames[0])); /* for purify */ - fnames[fcnt].name = tempptr; - tempptr = strmov(tempptr,dp->d_name) + 1; - if (MyFlags & MY_WANT_STAT) - { - (void)strmov(tmp_file,dp->d_name); - (void)my_stat(tmp_path, &fnames[fcnt].mystat, MyFlags); - } - ++fcnt; - } - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) - goto error; /* No memory */ - length= (uint) (sizeof(struct fileinfo ) * firstfcnt); - diff= PTR_BYTE_DIFF(buffer , obuffer) + (int) length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,tempptr-length, - (uint) (tempptr- (char*) (fnames+maxfcnt))); - } - - (void) closedir(dirp); - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort((void *) fnames, (size_s) fcnt, sizeof(struct fileinfo), - (qsort_cmp) comp_names); -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_unlock(&THR_LOCK_open); -#endif - DBUG_RETURN((MY_DIR *) buffer); - - error: -#if defined(THREAD) && !defined(HAVE_READDIR_R) - pthread_mutex_unlock(&THR_LOCK_open); -#endif - my_errno=errno; - if (dirp) - (void) closedir(dirp); - if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - - -/* - * Convert from directory name to filename. - * On VMS: - * xyzzy:[mukesh.emacs] => xyzzy:[mukesh]emacs.dir.1 - * xyzzy:[mukesh] => xyzzy:[000000]mukesh.dir.1 - * On UNIX, it's simple: just make sure there is a terminating / - - * Returns pointer to dst; - */ - -my_string directory_file_name (my_string dst, const char *src) -{ -#ifndef VMS - - /* Process as Unix format: just remove test the final slash. */ - - my_string end; - - if (src[0] == 0) - src= (char*) "."; /* Use empty as current */ - end=strmov(dst, src); - if (end[-1] != FN_LIBCHAR) - { - end[0]=FN_LIBCHAR; /* Add last '/' */ - end[1]='\0'; - } - return dst; - -#else /* VMS */ - - long slen; - long rlen; - my_string ptr, rptr; - char bracket; - struct FAB fab = cc$rms_fab; - struct NAM nam = cc$rms_nam; - char esa[NAM$C_MAXRSS]; - - if (! src[0]) - src="[.]"; /* Empty is == current dir */ - - slen = strlen (src) - 1; - if (src[slen] == FN_C_AFTER_DIR || src[slen] == FN_C_AFTER_DIR_2 || - src[slen] == FN_DEVCHAR) - { - /* VMS style - convert [x.y.z] to [x.y]z, [x] to [000000]x */ - fab.fab$l_fna = src; - fab.fab$b_fns = slen + 1; - fab.fab$l_nam = &nam; - fab.fab$l_fop = FAB$M_NAM; - - nam.nam$l_esa = esa; - nam.nam$b_ess = sizeof esa; - nam.nam$b_nop |= NAM$M_SYNCHK; - - /* We call SYS$PARSE to handle such things as [--] for us. */ - if (SYS$PARSE(&fab, 0, 0) == RMS$_NORMAL) - { - slen = nam.nam$b_esl - 1; - if (esa[slen] == ';' && esa[slen - 1] == '.') - slen -= 2; - esa[slen + 1] = '\0'; - src = esa; - } - if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) - { - /* what about when we have logical_name:???? */ - if (src[slen] == FN_DEVCHAR) - { /* Xlate logical name and see what we get */ - VOID(strmov(dst,src)); - dst[slen] = 0; /* remove colon */ - if (!(src = getenv (dst))) - return dst; /* Can't translate */ - - /* should we jump to the beginning of this procedure? - Good points: allows us to use logical names that xlate - to Unix names, - Bad points: can be a problem if we just translated to a device - name... - For now, I'll punt and always expect VMS names, and hope for - the best! */ - - slen = strlen (src) - 1; - if (src[slen] != FN_C_AFTER_DIR && src[slen] != FN_C_AFTER_DIR_2) - { /* no recursion here! */ - VOID(strmov(dst, src)); - return(dst); - } - } - else - { /* not a directory spec */ - VOID(strmov(dst, src)); - return(dst); - } - } - - bracket = src[slen]; /* End char */ - if (!(ptr = strchr (src, bracket - 2))) - { /* no opening bracket */ - VOID(strmov (dst, src)); - return dst; - } - if (!(rptr = strrchr (src, '.'))) - rptr = ptr; - slen = rptr - src; - VOID(strmake (dst, src, slen)); - - if (*rptr == '.') - { /* Put bracket and add */ - dst[slen++] = bracket; /* (rptr+1) after this */ - } - else - { - /* If we have the top-level of a rooted directory (i.e. xx:[000000]), - then translate the device and recurse. */ - - if (dst[slen - 1] == ':' - && dst[slen - 2] != ':' /* skip decnet nodes */ - && strcmp(src + slen, "[000000]") == 0) - { - dst[slen - 1] = '\0'; - if ((ptr = getenv (dst)) - && (rlen = strlen (ptr) - 1) > 0 - && (ptr[rlen] == FN_C_AFTER_DIR || ptr[rlen] == FN_C_AFTER_DIR_2) - && ptr[rlen - 1] == '.') - { - VOID(strmov(esa,ptr)); - esa[rlen - 1] = FN_C_AFTER_DIR; - esa[rlen] = '\0'; - return (directory_file_name (dst, esa)); - } - else - dst[slen - 1] = ':'; - } - VOID(strmov(dst+slen,"[000000]")); - slen += 8; - } - VOID(strmov(strmov(dst+slen,rptr+1)-1,".DIR.1")); - return dst; - } - VOID(strmov(dst, src)); - if (dst[slen] == '/' && slen > 1) - dst[slen] = 0; - return dst; -#endif /* VMS */ -} /* directory_file_name */ - -#elif defined(_WIN32) - -/* -***************************************************************************** -** Read long filename using windows rutines -***************************************************************************** -*/ - -MY_DIR *my_dir(const char *path, myf MyFlags) -{ - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - int eof,i,fcnt,firstfcnt,length,maxfcnt; - uint size; -#ifdef __BORLANDC__ - struct ffblk find; -#else - struct _finddata_t find; -#endif - ushort mode; - char tmp_path[FN_REFLEN],*tmp_file,attrib; - my_ptrdiff_t diff; -#ifdef _WIN64 - __int64 handle; -#else - long handle; -#endif - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - - /* Put LIB-CHAR as last path-character if not there */ - - tmp_file=tmp_path; - if (!*path) - *tmp_file++ ='.'; /* From current dir */ - tmp_file= strmov(tmp_file,path); - if (tmp_file[-1] == FN_DEVCHAR) - *tmp_file++= '.'; /* From current dev-dir */ - if (tmp_file[-1] != FN_LIBCHAR) - *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ - tmp_file[1]='.'; - tmp_file[2]='*'; - tmp_file[3]='\0'; - -#ifdef __BORLANDC__ - if ((handle= findfirst(tmp_path,&find,0)) == -1L) - goto error; -#else - if ((handle=_findfirst(tmp_path,&find)) == -1L) - goto error; -#endif - - size = STARTSIZE; - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) my_malloc(size, MyFlags)) == 0) - goto error; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - - fcnt = 0; - for (;;) - { - do - { - fnames[fcnt].name = tempptr; -#ifdef __BORLANDC__ - tempptr = strmov(tempptr,find.ff_name) + 1; - fnames[fcnt].mystat.st_size=find.ff_fsize; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.ff_attrib; -#else - tempptr = strmov(tempptr,find.name) + 1; - fnames[fcnt].mystat.st_size=find.size; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.attrib; -#endif - if (!(attrib & _A_RDONLY)) - mode|=MY_S_IWRITE; - if (attrib & _A_SUBDIR) - mode|=MY_S_IFDIR; - fnames[fcnt].mystat.st_mode=mode; -#ifdef __BORLANDC__ - fnames[fcnt].mystat.st_mtime=((uint32) find.ff_ftime); -#else - fnames[fcnt].mystat.st_mtime=((uint32) find.time_write); -#endif - ++fcnt; -#ifdef __BORLANDC__ - } while ((eof= findnext(&find)) == 0 && fcnt < maxfcnt); -#else - } while ((eof= _findnext(handle,&find)) == 0 && fcnt < maxfcnt); -#endif - - DBUG_PRINT("test",("eof: %d errno: %d",eof,errno)); - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) - goto error; - length= sizeof(struct fileinfo ) * firstfcnt; - diff= PTR_BYTE_DIFF(buffer , obuffer) +length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*), - (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt)); - } - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names); -#ifndef __BORLANDC__ - _findclose(handle); -#endif - DBUG_RETURN((MY_DIR *) buffer); - -error: - my_errno=errno; -#ifndef __BORLANDC__ - if (handle != -1) - _findclose(handle); -#endif - if (MyFlags & MY_FAE+MY_WME) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - -#else /* MSDOS and not WIN32 */ - - -/****************************************************************************** -** At MSDOS you always get stat of files, but time is in packed MSDOS-format -******************************************************************************/ - -MY_DIR *my_dir(const char* path, myf MyFlags) -{ - struct fileinfo *fnames; - char *buffer, *obuffer, *tempptr; - int eof,i,fcnt,firstfcnt,length,maxfcnt; - uint size; - struct find_t find; - ushort mode; - char tmp_path[FN_REFLEN],*tmp_file,attrib; - my_ptrdiff_t diff; - DBUG_ENTER("my_dir"); - DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags)); - - /* Put LIB-CHAR as last path-character if not there */ - - tmp_file=tmp_path; - if (!*path) - *tmp_file++ ='.'; /* From current dir */ - tmp_file= strmov(tmp_file,path); - if (tmp_file[-1] == FN_DEVCHAR) - *tmp_file++= '.'; /* From current dev-dir */ - if (tmp_file[-1] != FN_LIBCHAR) - *tmp_file++ =FN_LIBCHAR; - tmp_file[0]='*'; /* MSDOS needs this !??? */ - tmp_file[1]='.'; - tmp_file[2]='*'; - tmp_file[3]='\0'; - - if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find)) - goto error; - - size = STARTSIZE; - firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) / - (sizeof(struct fileinfo) + FN_LEN); - if ((buffer = (char *) my_malloc(size, MyFlags)) == 0) - goto error; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr = (char *) (fnames + maxfcnt); - - fcnt = 0; - for (;;) - { - do - { - fnames[fcnt].name = tempptr; - tempptr = strmov(tempptr,find.name) + 1; - fnames[fcnt].mystat.st_size=find.size; - fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0; - mode=MY_S_IREAD; attrib=find.attrib; - if (!(attrib & _A_RDONLY)) - mode|=MY_S_IWRITE; - if (attrib & _A_SUBDIR) - mode|=MY_S_IFDIR; - fnames[fcnt].mystat.st_mode=mode; - fnames[fcnt].mystat.st_mtime=((uint32) find.wr_date << 16) + - find.wr_time; - ++fcnt; - } while ((eof= _dos_findnext(&find)) == 0 && fcnt < maxfcnt); - - DBUG_PRINT("test",("eof: %d errno: %d",eof,errno)); - if (eof) - break; - size += STARTSIZE; obuffer = buffer; - if (!(buffer = (char *) my_realloc((gptr) buffer, size, - MyFlags | MY_FREE_ON_ERROR))) - goto error; - length= sizeof(struct fileinfo ) * firstfcnt; - diff= PTR_BYTE_DIFF(buffer , obuffer) +length; - fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR)); - tempptr= ADD_TO_PTR(tempptr,diff,char*); - for (i = 0; i < maxfcnt; i++) - fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*); - - /* move filenames upp a bit */ - maxfcnt += firstfcnt; - bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*), - (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt)); - } - { - MY_DIR * s = (MY_DIR *) buffer; - s->number_off_files = (uint) fcnt; - s->dir_entry = fnames; - } - if (!(MyFlags & MY_DONT_SORT)) - qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names); - DBUG_RETURN((MY_DIR *) buffer); - -error: - if (MyFlags & MY_FAE+MY_WME) - my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno); - DBUG_RETURN((MY_DIR *) NULL); -} /* my_dir */ - -#endif /* WIN32 && MSDOS */ - -/**************************************************************************** -** File status -** Note that MY_STAT is assumed to be same as struct stat -****************************************************************************/ - -int my_fstat(int Filedes, MY_STAT *stat_area, myf MyFlags ) -{ - DBUG_ENTER("my_fstat"); - DBUG_PRINT("my",("fd: %d MyFlags: %d",Filedes,MyFlags)); - DBUG_RETURN(fstat(Filedes, (struct stat *) stat_area)); -} - -MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags) -{ - int m_used; - DBUG_ENTER("my_stat"); - DBUG_PRINT("my", ("path: '%s', stat_area: %lx, MyFlags: %d", path, - (unsigned char *) stat_area, my_flags)); - - if ((m_used= (stat_area == NULL))) - if (!(stat_area = (MY_STAT *) my_malloc(sizeof(MY_STAT), my_flags))) - goto error; - if ( ! stat((my_string) path, (struct stat *) stat_area) ) - DBUG_RETURN(stat_area); - my_errno=errno; - if (m_used) /* Free if new area */ - my_free(stat_area); - -error: - if (my_flags & (MY_FAE+MY_WME)) - { - my_error(EE_STAT, MYF(ME_BELL+ME_WAITTANG),path,my_errno); - DBUG_RETURN((MY_STAT *) NULL); - } - DBUG_RETURN((MY_STAT *) NULL); -} /* my_stat */ - diff --git a/libmariadb/my_malloc.c b/libmariadb/my_malloc.c deleted file mode 100644 index 665d767c..00000000 --- a/libmariadb/my_malloc.c +++ /dev/null @@ -1,101 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - /* My memory allocator */ - -gptr my_malloc(size_t Size, myf MyFlags) -{ - gptr point; - DBUG_ENTER("my_malloc"); - DBUG_PRINT("my",("Size: %u MyFlags: %d",Size, MyFlags)); - - if (!Size) - Size=1; /* Safety */ - if ((point = (char*)malloc(Size)) == NULL) - { - my_errno=errno; - if (MyFlags & MY_FAE) - error_handler_hook=fatal_error_handler_hook; - if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); - if (MyFlags & MY_FAE) - exit(1); - } - else if (MyFlags & MY_ZEROFILL) - bzero(point,Size); - DBUG_PRINT("exit",("ptr: %lx",point)); - DBUG_RETURN(point); -} /* my_malloc */ - - - /* Free memory allocated with my_malloc */ - /*ARGSUSED*/ - -void my_no_flags_free(void *ptr) -{ - DBUG_ENTER("my_free"); - DBUG_PRINT("my",("ptr: %lx",ptr)); - if (ptr) - free(ptr); - DBUG_VOID_RETURN; -} /* my_free */ - - - /* malloc and copy */ - -gptr my_memdup(const unsigned char *from, size_t length, myf MyFlags) -{ - gptr ptr; - if ((ptr=my_malloc(length,MyFlags)) != 0) - memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); - return(ptr); -} - - -my_string my_strdup(const char *from, myf MyFlags) -{ - gptr ptr; - uint length; - - if ((MyFlags & MY_ALLOW_ZERO_PTR) && !from) - return NULL; - - length=(uint) strlen(from)+1; - if ((ptr=my_malloc(length,MyFlags)) != 0) - memcpy((unsigned char*) ptr, (unsigned char*) from,(size_t) length); - return((my_string) ptr); -} - -my_string my_strndup(const char *src, size_t length, myf MyFlags) -{ - gptr ptr; - - if ((ptr= my_malloc(length+1, MyFlags))) { - memcpy(ptr, src, length); - ptr[length] = 0; - } - return ptr; -} -/* }}} */ diff --git a/libmariadb/my_messnc.c b/libmariadb/my_messnc.c deleted file mode 100644 index 0dd3be5b..00000000 --- a/libmariadb/my_messnc.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" - -int my_message_no_curses(uint error __attribute__((unused)), - const char *str, myf MyFlags) -{ - DBUG_ENTER("my_message_no_curses"); - DBUG_PRINT("enter",("message: %s",str)); - (void) fflush(stdout); - if (MyFlags & ME_BELL) - (void) fputc('\007',stderr); /* Bell */ - if (my_progname) - { - (void)fputs(my_progname,stderr); (void)fputs(": ",stderr); - } - (void)fputs(str,stderr); - (void)fputc('\n',stderr); - (void)fflush(stderr); - DBUG_RETURN(0); -} diff --git a/libmariadb/my_net.c b/libmariadb/my_net.c deleted file mode 100644 index 2e6fa03b..00000000 --- a/libmariadb/my_net.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* thread safe version of some common functions */ - -#include "mysys_priv.h" -#include - -/* for thread safe my_inet_ntoa */ -#if !defined(MSDOS) && !defined(_WIN32) -#include -#ifdef HAVE_SYS_SOCKET_H -#include -#endif -#ifdef HAVE_NETINET_IN_H -#include -#endif -#ifdef HAVE_ARPA_INET_H -#include -#endif -#endif /* !defined(MSDOS) && !defined(_WIN32) */ - -void my_inet_ntoa(struct in_addr in, char *buf) -{ - char *ptr; - pthread_mutex_lock(&THR_LOCK_net); - ptr=inet_ntoa(in); - strmov(buf,ptr); - pthread_mutex_unlock(&THR_LOCK_net); -} diff --git a/libmariadb/my_once.c b/libmariadb/my_once.c deleted file mode 100644 index 15ce18e1..00000000 --- a/libmariadb/my_once.c +++ /dev/null @@ -1,88 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Not MT-SAFE */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "my_static.h" -#include "mysys_err.h" - - /* alloc for things we don't nead to free */ - /* No DBUG_ENTER... here to get smaller dbug-startup */ - -gptr my_once_alloc(unsigned int Size, myf MyFlags) -{ - size_t get_size,max_left; - gptr point; - reg1 USED_MEM *next; - reg2 USED_MEM **prev; - - Size= ALIGN_SIZE(Size); - prev= &my_once_root_block; - max_left=0; - for (next=my_once_root_block ; next && next->left < Size ; next= next->next) - { - if (next->left > max_left) - max_left=next->left; - prev= &next->next; - } - if (! next) - { /* Time to alloc new block */ - get_size= Size+ALIGN_SIZE(sizeof(USED_MEM)); - if (max_left*4 < my_once_extra && get_size < my_once_extra) - get_size=my_once_extra; /* Normal alloc */ - - if ((next = (USED_MEM*) malloc(get_size)) == 0) - { - my_errno=errno; - if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),get_size); - return((gptr) 0); - } - DBUG_PRINT("test",("my_once_malloc %u byte malloced",get_size)); - next->next= 0; - next->size= get_size; - next->left= get_size-ALIGN_SIZE(sizeof(USED_MEM)); - *prev=next; - } - point= (gptr) ((char*) next+ (next->size-next->left)); - next->left-= Size; - - return(point); -} /* my_once_alloc */ - - - /* deallocate everything used by my_once_alloc */ - -void my_once_free(void) -{ - reg1 USED_MEM *next,*old; - DBUG_ENTER("my_once_free"); - - for (next=my_once_root_block ; next ; ) - { - old=next; next= next->next ; - free((gptr) old); - } - my_once_root_block=0; - - DBUG_VOID_RETURN; -} /* my_once_free */ diff --git a/libmariadb/my_open.c b/libmariadb/my_open.c deleted file mode 100644 index 6fc8ee45..00000000 --- a/libmariadb/my_open.c +++ /dev/null @@ -1,126 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#define USES_TYPES -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) -#include -#endif - - /* Open a file */ - -File my_open(const char *FileName, int Flags, myf MyFlags) - /* Path-name of file */ - /* Read | write .. */ - /* Special flags */ -{ - File fd; - DBUG_ENTER("my_open"); - DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d", - FileName, Flags, MyFlags)); -#if defined(MSDOS) || defined(_WIN32) || defined(__EMX__) || defined(OS2) - if (Flags & O_SHARE) - fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO, - MY_S_IREAD | MY_S_IWRITE); - else - fd = open((my_string) FileName, Flags | O_BINARY, - MY_S_IREAD | MY_S_IWRITE); -#elif !defined(NO_OPEN_3) - fd = open(FileName, Flags, my_umask); /* Normal unix */ -#else - fd = open((my_string) FileName, Flags); -#endif - DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_OPEN, - EE_FILENOTFOUND, MyFlags)); -} /* my_open */ - - - /* Close a file */ - -int my_close(File fd, myf MyFlags) -{ - int err; - DBUG_ENTER("my_close"); - DBUG_PRINT("my",("fd: %d MyFlags: %d",fd, MyFlags)); - - pthread_mutex_lock(&THR_LOCK_open); - if ((err = close(fd))) - { - DBUG_PRINT("error",("Got error %d on close",err)); - my_errno=errno; - if (MyFlags & (MY_FAE | MY_WME)) - my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno); - } - if ((uint) fd < MY_NFILE && my_file_info[fd].type != UNOPEN) - { - my_free(my_file_info[fd].name); -#if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_destroy(&my_file_info[fd].mutex); -#endif - my_file_info[fd].type = UNOPEN; - } - my_file_opened--; - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_RETURN(err); -} /* my_close */ - - -File my_register_filename(File fd, const char *FileName, enum file_type - type_of_file, uint error_message_number, myf MyFlags) -{ - if ((int) fd >= 0) - { - if ((int) fd >= MY_NFILE) - { -#if defined(THREAD) && !defined(HAVE_PREAD) - (void) my_close(fd,MyFlags); - my_errno=EMFILE; - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error(EE_OUT_OF_FILERESOURCES, MYF(ME_BELL+ME_WAITTANG), - FileName, my_errno); - return(-1); -#endif - thread_safe_increment(my_file_opened,&THR_LOCK_open); - return(fd); /* safeguard */ - } - pthread_mutex_lock(&THR_LOCK_open); - if ((my_file_info[fd].name = (char*) my_strdup(FileName,MyFlags))) - { - my_file_opened++; - my_file_info[fd].type = type_of_file; -#if defined(THREAD) && !defined(HAVE_PREAD) - pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST); -#endif - pthread_mutex_unlock(&THR_LOCK_open); - DBUG_PRINT("exit",("fd: %d",fd)); - return(fd); - } - pthread_mutex_unlock(&THR_LOCK_open); - (void) my_close(fd, MyFlags); - my_errno=ENOMEM; - } - else - my_errno=errno; - DBUG_PRINT("error",("Got error %d on open",my_errno)); - if (MyFlags & (MY_FFNF | MY_FAE | MY_WME)) - my_error(error_message_number, MYF(ME_BELL+ME_WAITTANG), - FileName, my_errno); - return(fd); -} diff --git a/libmariadb/my_port.c b/libmariadb/my_port.c deleted file mode 100644 index bf5dbcba..00000000 --- a/libmariadb/my_port.c +++ /dev/null @@ -1,40 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Small functions to make code portable -*/ - -#include "mysys_priv.h" - -#ifdef _AIX - -/* - On AIX, at least with gcc 3.1, the expression - '(double) (ulonglong) var' doesn't always work for big unsigned - integers like '18446744073709551615'. The end result is that the - high bit is simply dropped. (probably bug in gcc optimizations) - Handling the conversion in a sub function seems to work. -*/ - - - -double my_ulonglong2double(unsigned long long nr) -{ - return (double) nr; -} -#endif /* _AIX */ diff --git a/libmariadb/my_pthread.c b/libmariadb/my_pthread.c deleted file mode 100644 index 37d4e58e..00000000 --- a/libmariadb/my_pthread.c +++ /dev/null @@ -1,555 +0,0 @@ -/* Copyright (C) 2000 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Functions to get threads more portable */ - -#define DONT_REMAP_PTHREAD_FUNCTIONS - -#include "mysys_priv.h" -#ifdef THREAD -#include -#include -#include -#include - -#ifdef _WIN32 - -int -pthread_cond_init (pthread_cond_t *cv, const pthread_condattr_t *attr) -{ - DBUG_ENTER("pthread_cond_init"); - /* Initialize the count to 0 */ - InitializeCriticalSection(&cv->waiters_count_lock); - cv->waiting = 0; - - /* Create an auto-reset and manual-reset event */ - if (!(cv->events[SIGNAL] = CreateEvent (NULL, FALSE, FALSE, NULL)) || - !(cv->events[BROADCAST] = CreateEvent (NULL, TRUE, FALSE, NULL))) - { - DBUG_RETURN(GetLastError()); - } - DBUG_RETURN(0); -} - -int pthread_cond_timedwait(pthread_cond_t *cond, - pthread_mutex_t *mutex, - struct timespec *abstime) -{ - int result= 0; - return result == WAIT_TIMEOUT ? ETIMEDOUT : 0; -} - -int pthread_cond_wait(pthread_cond_t *cv, pthread_mutex_t *mutex) -{ - return pthread_cond_timedwait(cv,mutex,NULL); -} - -int pthread_cond_destroy(pthread_cond_t *cv) -{ - DeleteCriticalSection(&cv->waiters_count_lock); - - if (CloseHandle(cv->events[SIGNAL]) == 0 || - CloseHandle(cv->events[BROADCAST]) == 0) - return EINVAL; - return 0; -} - -#endif - -#if (defined(__BSD__) || defined(_BSDI_VERSION)) && !defined(HAVE_mit_thread) -#define SCHED_POLICY SCHED_RR -#else -#define SCHED_POLICY SCHED_OTHER -#endif - -#ifndef my_pthread_setprio -void my_pthread_setprio(pthread_t thread_id,int prior) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=prior; - VOID(pthread_setschedparam(thread_id,SCHED_POLICY,&tmp_sched_param)); -#endif -} -#endif - -#ifndef my_pthread_getprio -int my_pthread_getprio(pthread_t thread_id) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - int policy; - if (!pthread_getschedparam(thread_id,&policy,&tmp_sched_param)) - { - DBUG_PRINT("thread",("policy: %d priority: %d", - policy,tmp_sched_param.sched_priority)); - return tmp_sched_param.sched_priority; - } -#endif - return -1; -} -#endif - -#ifndef my_pthread_attr_setprio -void my_pthread_attr_setprio(pthread_attr_t *attr, int priority) -{ -#ifdef HAVE_PTHREAD_SETSCHEDPARAM - struct sched_param tmp_sched_param; - bzero((char*) &tmp_sched_param,sizeof(tmp_sched_param)); - tmp_sched_param.sched_priority=priority; - VOID(pthread_attr_setschedparam(attr,&tmp_sched_param)); -#endif -} -#endif - - -/* To allow use of pthread_getspecific with two arguments */ - -#ifdef HAVE_NONPOSIX_PTHREAD_GETSPECIFIC -#undef pthread_getspecific -#ifdef HAVE_UNIXWARE7_THREADS -#define pthread_getspecific thr_getspecific -#endif - -void *my_pthread_getspecific_imp(pthread_key_t key) -{ - void *value; - if (pthread_getspecific(key,(void *) &value)) - return 0; - return value; -} -#endif - - -/* Some functions for RTS threads, AIX, Siemens Unix and UnixWare 7 - (and DEC OSF/1 3.2 too) */ - -int my_pthread_create_detached=1; - -#if defined(HAVE_NONPOSIX_SIGWAIT) || defined(HAVE_DEC_3_2_THREADS) - -int my_sigwait(const sigset_t *set,int *sig) -{ - int signal=sigwait((sigset_t*) set); - if (signal < 0) - return errno; - *sig=signal; - return 0; -} -#endif - -/* localtime_r for SCO 3.2V4.2 */ - -#ifndef HAVE_LOCALTIME_R - -extern pthread_mutex_t LOCK_localtime_r; - -struct tm *localtime_r(const time_t *clock, struct tm *res) -{ - struct tm *tmp; - pthread_mutex_lock(&LOCK_localtime_r); - tmp=localtime(clock); - *res= *tmp; - pthread_mutex_unlock(&LOCK_localtime_r); - return res; -} -#endif - - -/**************************************************************************** -** Replacement of sigwait if the system doesn't have one (like BSDI 3.0) -** -** Note: -** This version of sigwait() is assumed to called in a loop so the signalmask -** is permanently modified to reflect the signal set. This is done to get -** a much faster implementation. -** -** This implementation isn't thread safe: It assumes that only one -** thread is using sigwait. -** -** If one later supplies a different signal mask, all old signals that -** was used before are unblocked and set to SIGDFL. -** -** Author: Gary Wisniewski , much modified by Monty -****************************************************************************/ - -#if !defined(HAVE_SIGWAIT) && !defined(HAVE_mit_thread) && !defined(sigwait) && !defined(_WIN32) && !defined(HAVE_rts_threads) && !defined(HAVE_NONPOSIX_SIGWAIT) && !defined(HAVE_DEC_3_2_THREADS) && !defined(OS2) - -#if !defined(DONT_USE_SIGSUSPEND) - -static sigset_t sigwait_set,rev_sigwait_set,px_recd; - -void px_handle_sig(int sig) -{ - sigaddset(&px_recd, sig); -} - - -void sigwait_setup(sigset_t *set) -{ - int i; - struct sigaction sact,sact1; - sigset_t unblock_mask; - - sact.sa_flags = 0; - sact.sa_handler = px_handle_sig; - memcpy_fixed(&sact.sa_mask,set,sizeof(*set)); /* handler isn't thread_safe */ - sigemptyset(&unblock_mask); - pthread_sigmask(SIG_UNBLOCK,(sigset_t*) 0,&rev_sigwait_set); - - for (i = 1; i <= sizeof(sigwait_set)*8; i++) - { - if (sigismember(set,i)) - { - sigdelset(&rev_sigwait_set,i); - if (!sigismember(&sigwait_set,i)) - sigaction(i, &sact, (struct sigaction*) 0); - } - else - { - sigdelset(&px_recd,i); /* Don't handle this */ - if (sigismember(&sigwait_set,i)) - { /* Remove the old handler */ - sigaddset(&unblock_mask,i); - sigdelset(&rev_sigwait_set,i); - sact1.sa_flags = 0; - sact1.sa_handler = SIG_DFL; - sigemptyset(&sact1.sa_mask); - sigaction(i, &sact1, 0); - } - } - } - memcpy_fixed(&sigwait_set,set,sizeof(*set)); - pthread_sigmask(SIG_BLOCK,(sigset_t*) set,(sigset_t*) 0); - pthread_sigmask(SIG_UNBLOCK,&unblock_mask,(sigset_t*) 0); -} - - -int sigwait(sigset_t *setp, int *sigp) -{ - if (memcmp(setp,&sigwait_set,sizeof(sigwait_set))) - sigwait_setup(setp); /* Init or change of set */ - - for (;;) - { - /* - This is a fast, not 100% portable implementation to find the signal. - Because the handler is blocked there should be at most 1 bit set, but - the specification on this is somewhat shady so we use a set instead a - single variable. - */ - - ulong *ptr= (ulong*) &px_recd; - ulong *end=ptr+sizeof(px_recd)/sizeof(ulong); - - for ( ; ptr != end ; ptr++) - { - if (*ptr) - { - ulong set= *ptr; - int found= (int) ((char*) ptr - (char*) &px_recd)*8+1; - while (!(set & 1)) - { - found++; - set>>=1; - } - *sigp=found; - sigdelset(&px_recd,found); - return 0; - } - } - sigsuspend(&rev_sigwait_set); - } - return 0; -} -#else /* !DONT_USE_SIGSUSPEND */ - -/**************************************************************************** -** Replacement of sigwait if the system doesn't have one (like BSDI 3.0) -** -** Note: -** This version of sigwait() is assumed to called in a loop so the signalmask -** is permanently modified to reflect the signal set. This is done to get -** a much faster implementation. -** -** This implementation uses a extra thread to handle the signals and one -** must always call sigwait() with the same signal mask! -** -** BSDI 3.0 NOTE: -** -** pthread_kill() doesn't work on a thread in a select() or sleep() loop? -** After adding the sleep to sigwait_thread, all signals are checked and -** delivered every second. This isn't that terrible performance vice, but -** someone should report this to BSDI and ask for a fix! -** Another problem is that when the sleep() ends, every select() in other -** threads are interrupted! -****************************************************************************/ - -static sigset_t pending_set; -static bool inited=0; -static pthread_cond_t COND_sigwait; -static pthread_mutex_t LOCK_sigwait; - - -void sigwait_handle_sig(int sig) -{ - pthread_mutex_lock(&LOCK_sigwait); - sigaddset(&pending_set, sig); - VOID(pthread_cond_signal(&COND_sigwait)); /* inform sigwait() about signal */ - pthread_mutex_unlock(&LOCK_sigwait); -} - -extern pthread_t alarm_thread; - -void *sigwait_thread(void *set_arg) -{ - sigset_t *set=(sigset_t*) set_arg; - - int i; - struct sigaction sact; - sact.sa_flags = 0; - sact.sa_handler = sigwait_handle_sig; - memcpy_fixed(&sact.sa_mask,set,sizeof(*set)); /* handler isn't thread_safe */ - sigemptyset(&pending_set); - - for (i = 1; i <= sizeof(pending_set)*8; i++) - { - if (sigismember(set,i)) - { - sigaction(i, &sact, (struct sigaction*) 0); - } - } - sigaddset(set,THR_CLIENT_ALARM); - pthread_sigmask(SIG_UNBLOCK,(sigset_t*) set,(sigset_t*) 0); - alarm_thread=pthread_self(); /* For thr_alarm */ - - for (;;) - { /* Wait for signals */ -#ifdef HAVE_NOT_BROKEN_SELECT - fd_set fd; - FD_ZERO(&fd); - select(0,&fd,0,0,0); -#else - sleep(1); /* Because of broken BSDI */ -#endif - } -} - - -int sigwait(sigset_t *setp, int *sigp) -{ - if (!inited) - { - pthread_attr_t thr_attr; - pthread_t sigwait_thread_id; - inited=1; - sigemptyset(&pending_set); - pthread_mutex_init(&LOCK_sigwait,MY_MUTEX_INIT_FAST); - pthread_cond_init(&COND_sigwait,NULL); - - pthread_attr_init(&thr_attr); - pthread_attr_setscope(&thr_attr,PTHREAD_SCOPE_PROCESS); - pthread_attr_setdetachstate(&thr_attr,PTHREAD_CREATE_DETACHED); - pthread_attr_setstacksize(&thr_attr,8196); - my_pthread_attr_setprio(&thr_attr,100); /* Very high priority */ - VOID(pthread_create(&sigwait_thread_id,&thr_attr,sigwait_thread,setp)); - VOID(pthread_attr_destroy(&thr_attr)); - } - - pthread_mutex_lock(&LOCK_sigwait); - for (;;) - { - ulong *ptr= (ulong*) &pending_set; - ulong *end=ptr+sizeof(pending_set)/sizeof(ulong); - - for ( ; ptr != end ; ptr++) - { - if (*ptr) - { - ulong set= *ptr; - int found= (int) ((char*) ptr - (char*) &pending_set)*8+1; - while (!(set & 1)) - { - found++; - set>>=1; - } - *sigp=found; - sigdelset(&pending_set,found); - pthread_mutex_unlock(&LOCK_sigwait); - return 0; - } - } - VOID(pthread_cond_wait(&COND_sigwait,&LOCK_sigwait)); - } - return 0; -} - -#endif /* DONT_USE_SIGSUSPEND */ -#endif /* HAVE_SIGWAIT */ - -/***************************************************************************** -** Implement pthread_signal for systems that can't use signal() with threads -** Currently this is only used with BSDI 3.0 -*****************************************************************************/ - -#ifdef USE_PTHREAD_SIGNAL - -int pthread_signal(int sig, void (*func)()) -{ - struct sigaction sact; - sact.sa_flags= 0; - sact.sa_handler= func; - sigemptyset(&sact.sa_mask); - sigaction(sig, &sact, (struct sigaction*) 0); - return 0; -} -#endif - -/**************************************************************************** - The following functions fixes that all pthread functions should work - according to latest posix standard -****************************************************************************/ - -/* Undefined wrappers set my_pthread.h so that we call os functions */ -#undef pthread_mutex_init -#undef pthread_mutex_lock -#undef pthread_mutex_unlock -#undef pthread_mutex_destroy -#undef pthread_mutex_wait -#undef pthread_mutex_timedwait -#undef pthread_mutex_trylock -#undef pthread_mutex_t -#undef pthread_cond_init -#undef pthread_cond_wait -#undef pthread_cond_timedwait -#undef pthread_cond_t - - -/***************************************************************************** -** Patches for AIX and DEC OSF/1 3.2 -*****************************************************************************/ - -#if (defined(HAVE_NONPOSIX_PTHREAD_MUTEX_INIT) && !defined(HAVE_UNIXWARE7_THREADS)) || defined(HAVE_DEC_3_2_THREADS) - -#include - -int my_pthread_mutex_init(pthread_mutex_t *mp, const pthread_mutexattr_t *attr) -{ - int error; - if (!attr) - error=pthread_mutex_init(mp,pthread_mutexattr_default); - else - error=pthread_mutex_init(mp,*attr); - return error; -} - -int my_pthread_cond_init(pthread_cond_t *mp, const pthread_condattr_t *attr) -{ - int error; - if (!attr) - error=pthread_cond_init(mp,pthread_condattr_default); - else - error=pthread_cond_init(mp,*attr); - return error; -} - -#endif - - -/***************************************************************************** - Patches for HPUX - We need these because the pthread_mutex.. code returns -1 on error, - instead of the error code. - - Note that currently we only remap pthread_ functions used by MySQL. - If we are depending on the value for some other pthread_xxx functions, - this has to be added here. -****************************************************************************/ - -#if defined(HPUX) || defined(HAVE_BROKEN_PTHREAD_COND_TIMEDWAIT) - -int my_pthread_cond_timedwait(pthread_cond_t *cond, pthread_mutex_t *mutex, - struct timespec *abstime) -{ - int error=pthread_cond_timedwait(cond, mutex, abstime); - if (error == -1) /* Safety if the lib is fixed */ - { - if (!(error=errno)) - error= ETIMEDOUT; /* Can happen on HPUX */ - } - if (error == EAGAIN) /* Correct errno to Posix */ - error= ETIMEDOUT; - return error; -} -#endif - - -#ifdef HAVE_POSIX1003_4a_MUTEX -/* - In HP-UX-10.20 and other old Posix 1003.4a Draft 4 implementations - pthread_mutex_trylock returns 1 on success, not 0 like - pthread_mutex_lock - - From the HP-UX-10.20 man page: - RETURN VALUES - If the function fails, errno may be set to one of the following - values: - Return | Error | Description - _______|__________|_________________________________________ - 1 | | Successful completion. - 0 | | The mutex is locked; therefore, it was - | | not acquired. - -1 | [EINVAL] | The value specified by mutex is invalid. - -*/ - -/* - Convert pthread_mutex_trylock to return values according to latest POSIX - - RETURN VALUES - 0 If we are able successfully lock the mutex. - EBUSY Mutex was locked by another thread - # Other error number returned by pthread_mutex_trylock() - (Not likely) -*/ - -int my_pthread_mutex_trylock(pthread_mutex_t *mutex) -{ - int error= pthread_mutex_trylock(mutex); - if (error == 1) - return 0; /* Got lock on mutex */ - if (error == 0) /* Someon else is locking mutex */ - return EBUSY; - if (error == -1) /* Safety if the lib is fixed */ - error= errno; /* Probably invalid parameter */ - return error; -} -#endif /* HAVE_POSIX1003_4a_MUTEX */ - -/* Some help functions */ - -int pthread_no_free(void *not_used __attribute__((unused))) -{ - return 0; -} - -int pthread_dummy(int ret) -{ - return ret; -} -#endif /* THREAD */ diff --git a/libmariadb/my_read.c b/libmariadb/my_read.c deleted file mode 100644 index 4e4999af..00000000 --- a/libmariadb/my_read.c +++ /dev/null @@ -1,66 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - - /* Read a chunk of bytes from a file */ - -uint my_read(File Filedes, unsigned char *Buffer, uint Count, myf MyFlags) - /* File descriptor */ - /* Buffer must be at least count bytes */ - /* Max number of bytes returnd */ - /* Flags on what to do on error */ -{ - uint readbytes; - DBUG_ENTER("my_read"); - DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %u MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - - for (;;) - { - errno=0; /* Linux doesn't reset this */ - if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count) - { - my_errno=errno ? errno : -1; - DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", - readbytes,Count,Filedes,my_errno)); -#ifdef THREAD - if (readbytes == 0 && errno == EINTR) - continue; /* Interrupted */ -#endif - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - if ((int) readbytes == -1) - my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - else if (MyFlags & (MY_NABP | MY_FNABP)) - my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - if ((int) readbytes == -1 || (MyFlags & (MY_FNABP | MY_NABP))) - DBUG_RETURN(MY_FILE_ERROR); /* Return with error */ - } - - if (MyFlags & (MY_NABP | MY_FNABP)) - readbytes=0; /* Ok on read */ - break; - } - DBUG_RETURN(readbytes); -} /* my_read */ diff --git a/libmariadb/my_realloc.c b/libmariadb/my_realloc.c deleted file mode 100644 index 49107a05..00000000 --- a/libmariadb/my_realloc.c +++ /dev/null @@ -1,65 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#ifdef SAFEMALLOC /* We don't need SAFEMALLOC here */ -#undef SAFEMALLOC -#endif - -#include "mysys_priv.h" -#include "mysys_err.h" - - /* My memory re allocator */ - -gptr my_realloc(gptr oldpoint, size_t Size, myf MyFlags) -{ - gptr point; - DBUG_ENTER("my_realloc"); - DBUG_PRINT("my",("ptr: %lx Size: %u MyFlags: %d",oldpoint, Size, MyFlags)); - - if (!oldpoint && (MyFlags & MY_ALLOW_ZERO_PTR)) - DBUG_RETURN(my_malloc(Size,MyFlags)); -#ifdef USE_HALLOC - if (!(point = malloc(Size))) - { - if (MyFlags & MY_FREE_ON_ERROR) - my_free(oldpoint); - if (MyFlags & MY_HOLD_ON_ERROR) - DBUG_RETURN(oldpoint); - my_errno=errno; - if (MyFlags & MY_FAE+MY_WME) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG),Size); - } - else - { - memcpy(point,oldpoint,Size); - free(oldpoint); - } -#else - if ((point = (char*)realloc(oldpoint,Size)) == NULL) - { - if (MyFlags & MY_FREE_ON_ERROR) - my_free(oldpoint); - if (MyFlags & MY_HOLD_ON_ERROR) - DBUG_RETURN(oldpoint); - my_errno=errno; - if (MyFlags & (MY_FAE+MY_WME)) - my_error(EE_OUTOFMEMORY, MYF(ME_BELL+ME_WAITTANG), Size); - } -#endif - DBUG_PRINT("exit",("ptr: %lx",point)); - DBUG_RETURN(point); -} /* my_realloc */ diff --git a/libmariadb/my_seek.c b/libmariadb/my_seek.c deleted file mode 100644 index 7c4da4f6..00000000 --- a/libmariadb/my_seek.c +++ /dev/null @@ -1,58 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" - - /* Seek to position in file */ - /*ARGSUSED*/ - -my_off_t my_seek(File fd, my_off_t pos, int whence, - myf MyFlags __attribute__((unused))) -{ - reg1 os_off_t newpos; - DBUG_ENTER("my_seek"); - DBUG_PRINT("my",("Fd: %d Hpos: %lu Pos: %lu Whence: %d MyFlags: %d", - fd, ((ulonglong) pos) >> 32, (ulong) pos, whence, MyFlags)); - newpos=lseek(fd, pos, whence); - if (newpos == (os_off_t) -1) - { - my_errno=errno; - DBUG_PRINT("error",("lseek: %lu, errno: %d",newpos,errno)); - DBUG_RETURN(MY_FILEPOS_ERROR); - } - DBUG_RETURN((my_off_t) newpos); -} /* my_seek */ - - - /* Tell current position of file */ - /* ARGSUSED */ - -my_off_t my_tell(File fd, myf MyFlags __attribute__((unused))) -{ - os_off_t pos; - DBUG_ENTER("my_tell"); - DBUG_PRINT("my",("Fd: %d MyFlags: %d",fd, MyFlags)); -#ifdef HAVE_TELL - pos=tell(fd); -#else - pos=lseek(fd, 0L, MY_SEEK_CUR); -#endif - if (pos == (os_off_t) -1) - my_errno=errno; - DBUG_PRINT("exit",("pos: %lu",pos)); - DBUG_RETURN((my_off_t) pos); -} /* my_tell */ diff --git a/libmariadb/my_static.c b/libmariadb/my_static.c deleted file mode 100644 index 9a892996..00000000 --- a/libmariadb/my_static.c +++ /dev/null @@ -1,99 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Static variables for mysys library. All definied here for easy making of - a shared library -*/ - -#if !defined(stdin) || defined(OS2) -#include "mysys_priv.h" -#include "my_static.h" -#include "my_alarm.h" -#endif - - /* from my_init */ -my_string home_dir=0,my_progname=0; -char NEAR curr_dir[FN_REFLEN]= {0}, - NEAR home_dir_buff[FN_REFLEN]= {0}; -ulong my_stream_opened=0,my_file_opened=0, my_tmp_file_created=0; -int NEAR my_umask=0664, NEAR my_umask_dir=0777; -#ifndef THREAD -int NEAR my_errno=0; -#endif -struct my_file_info my_file_info[MY_NFILE]= {{0,UNOPEN}}; - - /* From mf_brkhant */ -int NEAR my_dont_interrupt=0; -volatile int _my_signals=0; -struct st_remember _my_sig_remember[MAX_SIGNALS]={{0,0}}; -#ifdef THREAD -sigset_t my_signals; /* signals blocked by mf_brkhant */ -#endif - - /* from mf_keycache.c */ -my_bool key_cache_inited=0; - - /* from mf_reccache.c */ -ulong my_default_record_cache_size=RECORD_CACHE_SIZE; - - /* from soundex.c */ - /* ABCDEFGHIJKLMNOPQRSTUVWXYZ */ - /* :::::::::::::::::::::::::: */ -const char *soundex_map= "01230120022455012623010202"; - - /* from my_malloc */ -USED_MEM* my_once_root_block=0; /* pointer to first block */ -uint my_once_extra=ONCE_ALLOC_INIT; /* Memory to alloc / block */ - - /* from my_tempnam */ -#if !defined(HAVE_TEMPNAM) || defined(HPUX11) -int _my_tempnam_used=0; -#endif - - /* from safe_malloc */ -uint sf_malloc_prehunc=0, /* If you have problem with core- */ - sf_malloc_endhunc=0, /* dump when malloc-message.... */ - /* set theese to 64 or 128 */ - sf_malloc_quick=0; /* set if no calls to sanity */ -size_t lCurMemory = 0L; /* Current memory usage */ -size_t lMaxMemory = 0L; /* Maximum memory usage */ -uint cNewCount = 0; /* Number of times NEW() was called */ - -/* Root of the linked list of remembers */ -struct remember *pRememberRoot = NULL; - - /* from my_alarm */ -int volatile my_have_got_alarm=0; /* declare variable to reset */ -ulong my_time_to_wait_for_lock=2; /* In seconds */ - - /* from errors.c */ -#ifdef SHARED_LIBRARY -char * NEAR globerrs[GLOBERRS]; /* my_error_messages is here */ -#endif -void (*my_abort_hook)(int) = (void(*)(int)) exit; -int (*error_handler_hook)(uint error,const char *str,myf MyFlags)= - my_message_no_curses; -int (*fatal_error_handler_hook)(uint error,const char *str,myf MyFlags)= - my_message_no_curses; - - /* How to disable options */ -my_bool NEAR my_disable_locking=0; -my_bool NEAR my_disable_async_io=0; -my_bool NEAR my_disable_flush_key_blocks=0; -my_bool NEAR my_disable_symlinks=0; -my_bool NEAR mysys_uses_curses=0; diff --git a/libmariadb/my_static.h b/libmariadb/my_static.h deleted file mode 100644 index 8a6be025..00000000 --- a/libmariadb/my_static.h +++ /dev/null @@ -1,69 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - Static variables for mysys library. All definied here for easy making of - a shared library -*/ - -#include "mysys_priv.h" -#include - -#define MAX_SIGNALS 10 /* Max signals under a dont-allow */ -#define MIN_KEYBLOCK (min(IO_SIZE,1024)) -#define MAX_KEYBLOCK 8192 /* Max keyblocklength == 8*IO_SIZE */ -#define MAX_BLOCK_TYPES MAX_KEYBLOCK/MIN_KEYBLOCK - -struct st_remember { - int number; - sig_handler (*func)(int number); -}; - -struct irem { - struct remember *_pNext; /* Linked list of structures */ - struct remember *_pPrev; /* Other link */ - my_string _sFileName; /* File in which memory was new'ed */ - uint _uLineNum; /* Line number in above file */ - uint _uDataSize; /* Size requested */ - long _lSpecialValue; /* Underrun marker value */ -}; - -struct remember { - struct irem tInt; - char aData[1]; -}; - -extern char NEAR curr_dir[FN_REFLEN],NEAR home_dir_buff[FN_REFLEN]; - -extern volatile int _my_signals; -extern struct st_remember _my_sig_remember[MAX_SIGNALS]; - -extern const char *soundex_map; - -extern USED_MEM* my_once_root_block; -extern uint my_once_extra; - -#if !defined(HAVE_TEMPNAM) || defined(HPUX11) -extern int _my_tempnam_used; -#endif - -extern uint cNewCount; -extern struct remember *pRememberRoot; - -#if defined(THREAD) && !defined(__WIN__) -extern sigset_t my_signals; /* signals blocked by mf_brkhant */ -#endif diff --git a/libmariadb/my_symlink.c b/libmariadb/my_symlink.c deleted file mode 100644 index 65d165fc..00000000 --- a/libmariadb/my_symlink.c +++ /dev/null @@ -1,138 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#ifdef HAVE_REALPATH -#include -#include -#endif - -/* - Reads the content of a symbolic link - If the file is not a symbolic link, return the original file name in to. - Returns: 0 if table was a symlink, - 1 if table was a normal file - -1 on error. -*/ - -int my_readlink(char *to, const char *filename, myf MyFlags) -{ -#ifndef HAVE_READLINK - strmov(to,filename); - return 1; -#else - int result=0; - int length; - DBUG_ENTER("my_readlink"); - - if ((length=readlink(filename, to, FN_REFLEN-1)) < 0) - { - /* Don't give an error if this wasn't a symlink */ - if ((my_errno=errno) == EINVAL) - { - result= 1; - strmov(to,filename); - } - else - { - if (MyFlags & MY_WME) - my_error(EE_CANT_READLINK, MYF(0), filename, errno); - result= -1; - } - } - else - to[length]=0; - DBUG_RETURN(result); -#endif /* HAVE_READLINK */ -} - - -/* Create a symbolic link */ - -int my_symlink(const char *content, const char *linkname, myf MyFlags) -{ -#ifndef HAVE_READLINK - return 0; -#else - int result; - DBUG_ENTER("my_symlink"); - - result= 0; - if (symlink(content, linkname)) - { - result= -1; - my_errno=errno; - if (MyFlags & MY_WME) - my_error(EE_CANT_SYMLINK, MYF(0), linkname, content, errno); - } - DBUG_RETURN(result); -#endif /* HAVE_READLINK */ -} - -/* - Resolve all symbolic links in path - 'to' may be equal to 'filename' - - Because purify gives a lot of UMR errors when using realpath(), - this code is disabled when using purify. - - If MY_RESOLVE_LINK is given, only do realpath if the file is a link. -*/ - -#if defined(SCO) -#define BUFF_LEN 4097 -#elif defined(MAXPATHLEN) -#define BUFF_LEN MAXPATHLEN -#else -#define BUFF_LEN FN_LEN -#endif - -int my_realpath(char *to, const char *filename, myf MyFlags) -{ -#if defined(HAVE_REALPATH) && !defined(HAVE_purify) && !defined(HAVE_BROKEN_REALPATH) - int result=0; - char buff[BUFF_LEN]; - struct stat stat_buff; - DBUG_ENTER("my_realpath"); - - if (!(MyFlags & MY_RESOLVE_LINK) || - (!lstat(filename,&stat_buff) && S_ISLNK(stat_buff.st_mode))) - { - char *ptr; - if ((ptr=realpath(filename,buff))) - strmake(to,ptr,FN_REFLEN-1); - else - { - /* Realpath didn't work; Use original name */ - my_errno=errno; - if (MyFlags & MY_WME) - my_error(EE_REALPATH, MYF(0), filename, my_errno); - if (to != filename) - strmov(to,filename); - result= -1; - } - } - DBUG_RETURN(result); -#else - if (to != filename) - strmov(to,filename); - return 0; -#endif -} diff --git a/libmariadb/my_thr_init.c b/libmariadb/my_thr_init.c deleted file mode 100644 index 23625693..00000000 --- a/libmariadb/my_thr_init.c +++ /dev/null @@ -1,245 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* -** Functions to handle initializating and allocationg of all mysys & debug -** thread variables. -*/ - -#include "mysys_priv.h" -#include -#include - -#ifdef THREAD -#ifdef USE_TLS -pthread_key(struct st_my_thread_var*, THR_KEY_mysys); -#else -pthread_key(struct st_my_thread_var, THR_KEY_mysys); -#endif /* USE_TLS */ -pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open, - THR_LOCK_lock, THR_LOCK_net, THR_LOCK_mysys; -#ifdef HAVE_OPENSSL -pthread_mutex_t LOCK_ssl_config; -#endif -#ifndef HAVE_LOCALTIME_R -pthread_mutex_t LOCK_localtime_r; -#endif -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP -pthread_mutexattr_t my_fast_mutexattr; -#endif -#ifdef PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP -pthread_mutexattr_t my_errchk_mutexattr; -#endif -my_bool THR_KEY_mysys_initialized= FALSE; - -/* FIXME Note. TlsAlloc does not set an auto destructor, so - the function my_thread_global_free must be called from - somewhere before final exit of the library */ - -my_bool my_thread_global_init(void) -{ - if (pthread_key_create(&THR_KEY_mysys,free)) - { - fprintf(stderr,"Can't initialize threads: error %d\n",errno); - exit(1); - } -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP - pthread_mutexattr_init(&my_fast_mutexattr); - pthread_mutexattr_setkind_np(&my_fast_mutexattr,PTHREAD_MUTEX_ADAPTIVE_NP); -#endif -#ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP - pthread_mutexattr_init(&my_errchk_mutexattr); - pthread_mutexattr_setkind_np(&my_errchk_mutexattr, - PTHREAD_MUTEX_ERRORCHECK_NP); -#endif - THR_KEY_mysys_initialized= TRUE; -#ifdef HAVE_OPENSSL - pthread_mutex_init(&LOCK_ssl_config,MY_MUTEX_INIT_FAST); -#endif - pthread_mutex_init(&THR_LOCK_malloc,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_open,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_lock,MY_MUTEX_INIT_FAST); - pthread_mutex_init(&THR_LOCK_net,MY_MUTEX_INIT_FAST); -#ifdef _WIN32 - /* win_pthread_init(); */ -#endif -#ifndef HAVE_LOCALTIME_R - pthread_mutex_init(&LOCK_localtime_r,MY_MUTEX_INIT_SLOW); -#endif - return my_thread_init(); -} - -void my_thread_global_end(void) -{ -#if defined(USE_TLS) - (void) TlsFree(THR_KEY_mysys); -#endif -#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP - pthread_mutexattr_destroy(&my_fast_mutexattr); -#endif -#ifdef PPTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP - pthread_mutexattr_destroy(&my_errchk_mutexattr); -#endif -#ifdef HAVE_OPENSSL - pthread_mutex_destroy(&LOCK_ssl_config); -#endif -} - -static long thread_id=0; - -/* - We can't use mutex_locks here if we are using windows as - we may have compiled the program with SAFE_MUTEX, in which - case the checking of mutex_locks will not work until - the pthread_self thread specific variable is initialized. -*/ - -my_bool my_thread_init(void) -{ - struct st_my_thread_var *tmp; - if (my_pthread_getspecific(struct st_my_thread_var *,THR_KEY_mysys)) - { - DBUG_PRINT("info", ("my_thread_init was already called. Thread id: %lu", - pthread_self())); - return 0; /* Safequard */ - } - /* We must have many calloc() here because these are freed on - pthread_exit */ - if (!(tmp=(struct st_my_thread_var *) - calloc(1,sizeof(struct st_my_thread_var)))) - { - return 1; - } - pthread_setspecific(THR_KEY_mysys,tmp); - - if (tmp->initialized) /* Already initialized */ - { - return 0; - } - - pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST); - pthread_cond_init(&tmp->suspend, NULL); - pthread_mutex_lock(&THR_LOCK_lock); - tmp->id= ++thread_id; - pthread_mutex_unlock(&THR_LOCK_lock); - tmp->initialized= TRUE; - return 0; -} - -void my_thread_end(void) -{ - struct st_my_thread_var *tmp= - my_pthread_getspecific(struct st_my_thread_var *, THR_KEY_mysys); - - if (tmp && tmp->initialized) - { -#ifdef HAVE_OPENSSL -#if OPENSSL_VERSION_NUMBER >= 0x10000001L - ERR_remove_thread_state(NULL); -#else - ERR_remove_state(0); -#endif -#endif -#if !defined(DBUG_OFF) - if (tmp->dbug) - { - DBUG_POP(); - free(tmp->dbug); - tmp->dbug=0; - } -#endif -#if !defined(__bsdi__) || defined(HAVE_mit_thread) /* bsdi dumps core here */ - pthread_cond_destroy(&tmp->suspend); -#endif - pthread_mutex_destroy(&tmp->mutex); - free(tmp); - pthread_setspecific(THR_KEY_mysys,0); - } - else - pthread_setspecific(THR_KEY_mysys,0); -} - -struct st_my_thread_var *_my_thread_var(void) -{ - struct st_my_thread_var *tmp= - my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); -#if defined(USE_TLS) - if (!tmp) - { - my_thread_init(); - tmp=my_pthread_getspecific(struct st_my_thread_var*,THR_KEY_mysys); - } -#endif - return tmp; -} - -/**************************************************************************** -** Get name of current thread. -****************************************************************************/ - -#define UNKNOWN_THREAD -1 - -long my_thread_id() -{ -#if defined(HAVE_PTHREAD_GETSEQUENCE_NP) - return pthread_getsequence_np(pthread_self()); -#elif (defined(__sun) || defined(__sgi) || defined(__linux__)) && !defined(HAVE_mit_thread) - return pthread_self(); -#else - return my_thread_var->id; -#endif -} - -#ifdef DBUG_OFF -const char *my_thread_name(void) -{ - return "no_name"; -} - -#else - -const char *my_thread_name(void) -{ - char name_buff[100]; - struct st_my_thread_var *tmp=my_thread_var; - if (!tmp->name[0]) - { - long id=my_thread_id(); - sprintf(name_buff,"T@%ld", id); - strmake(tmp->name,name_buff,THREAD_NAME_SIZE); - } - return tmp->name; -} - -extern void **my_thread_var_dbug() -{ - struct st_my_thread_var *tmp; - /* - Instead of enforcing DBUG_ASSERT(THR_KEY_mysys_initialized) here, - which causes any DBUG_ENTER and related traces to fail when - used in init / cleanup code, we are more tolerant: - using DBUG_ENTER / DBUG_PRINT / DBUG_RETURN - when the dbug instrumentation is not in place will do nothing. - */ - if (! THR_KEY_mysys_initialized) - return NULL; - tmp= _my_thread_var(); - return tmp && tmp->initialized ? (void **)&tmp->dbug : 0; -} -#endif /* DBUG_OFF */ - -#endif /* THREAD */ diff --git a/libmariadb/my_vsnprintf.c b/libmariadb/my_vsnprintf.c deleted file mode 100644 index 9bc33e28..00000000 --- a/libmariadb/my_vsnprintf.c +++ /dev/null @@ -1,119 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include -#include -#include - - -int my_snprintf(char* to, size_t n, const char* fmt, ...) -{ - int result; - va_list args; - va_start(args,fmt); - result= my_vsnprintf(to, n, fmt, args); - va_end(args); - return result; -} - - -int my_vsnprintf(char *to, size_t n, const char* fmt, va_list ap) -{ - char *start=to, *end=to+n-1; - for (; *fmt ; fmt++) - { - if (fmt[0] != '%') - { - if (to == end) /* End of buffer */ - break; - *to++= *fmt; /* Copy ordinary char */ - continue; - } - /* Skipp if max size is used (to be compatible with printf) */ - fmt++; - while (isdigit(*fmt) || *fmt == '.' || *fmt == '-') - fmt++; - if (*fmt == 'l') - fmt++; - if (*fmt == 's') /* String parameter */ - { - reg2 char *par = va_arg(ap, char *); - uint plen; - if (!par) par = (char*)"(null)"; - plen = (uint) strlen(par); - if ((uint) (end-to) > plen) /* Replace if possible */ - { - to=strmov(to,par); - continue; - } - } - else if (*fmt == 'd' || *fmt == 'u') /* Integer parameter */ - { - register int iarg; - if ((uint) (end-to) < 16) - break; - iarg = va_arg(ap, int); - if (*fmt == 'd') - to=int10_to_str((long) iarg,to, -10); - else - to=int10_to_str((long) (uint) iarg,to,10); - continue; - } - /* We come here on '%%', unknown code or too long parameter */ - if (to == end) - break; - *to++='%'; /* % used as % or unknown code */ - } - *to='\0'; /* End of errmessage */ - return (uint) (to - start); -} - - -#ifdef MAIN -static void my_printf(const char * fmt, ...) -{ - char buf[32]; - int n; - va_list ar; - va_start(ar, fmt); - n = my_vsnprintf(buf, sizeof(buf),fmt, ar); - printf(buf); - printf("n=%d, strlen=%d\n", n, strlen(buf)); - va_end(ar); -} - - -int main() -{ - - my_printf("Hello\n"); - my_printf("Hello int, %d\n", 1); - my_printf("Hello string '%s'\n", "I am a string"); - my_printf("Hello hack hack hack hack hack hack hack %d\n", 1); - my_printf("Hello %d hack %d\n", 1, 4); - my_printf("Hello %d hack hack hack hack hack %d\n", 1, 4); - my_printf("Hello '%s' hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh\n", "hack"); - my_printf("Hello hhhhhhhhhhhhhh %d sssssssssssssss\n", 1); - my_printf("Hello %u\n", 1); - my_printf("conn %ld to: '%-.64s' user: '%-.32s' host:\ - `%-.64s' (%-.64s)", 1, 0,0,0,0); - return 0; -} -#endif - diff --git a/libmariadb/my_write.c b/libmariadb/my_write.c deleted file mode 100644 index 9a271d44..00000000 --- a/libmariadb/my_write.c +++ /dev/null @@ -1,90 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include "mysys_priv.h" -#include "mysys_err.h" -#include - - - /* Write a chunk of bytes to a file */ - -uint my_write(int Filedes, const unsigned char *Buffer, uint Count, myf MyFlags) -{ - uint writenbytes,errors; - ulong written; - DBUG_ENTER("my_write"); - DBUG_PRINT("my",("Fd: %d Buffer: %lx Count: %d MyFlags: %d", - Filedes, Buffer, Count, MyFlags)); - errors=0; written=0L; - - for (;;) - { - if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count) - break; - if ((int) writenbytes != -1) - { /* Safeguard */ - written+=writenbytes; - Buffer+=writenbytes; - Count-=writenbytes; - } - my_errno=errno; - DBUG_PRINT("error",("Write only %d bytes, error: %d", - writenbytes,my_errno)); -#ifndef NO_BACKGROUND -#ifdef THREAD - if (my_thread_var->abort) - MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ -#endif - if (my_errno == ENOSPC && (MyFlags & MY_WAIT_IF_FULL) && - (uint) writenbytes != (uint) -1) - { - if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) - my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), - my_filename(Filedes)); - VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC)); - continue; - } - if (!writenbytes) - { - /* We may come here on an interrupt or if the file quote is exeeded */ - if (my_errno == EINTR) - continue; - if (!errors++) /* Retry once */ - { - errno=EFBIG; /* Assume this is the error */ - continue; - } - } - else if ((uint) writenbytes != (uint) -1) - continue; /* Retry */ -#endif - if (MyFlags & (MY_NABP | MY_FNABP)) - { - if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) - { - my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), - my_filename(Filedes),my_errno); - } - DBUG_RETURN(MY_FILE_ERROR); /* Error on read */ - } - else - break; /* Return bytes written */ - } - if (MyFlags & (MY_NABP | MY_FNABP)) - DBUG_RETURN(0); /* Want only errors */ - DBUG_RETURN(writenbytes+written); -} /* my_write */ diff --git a/libmariadb/mysys_priv.h b/libmariadb/mysys_priv.h deleted file mode 100644 index 9e7f9c42..00000000 --- a/libmariadb/mysys_priv.h +++ /dev/null @@ -1,32 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -#include -#include - -#ifdef USE_SYSTEM_WRAPPERS -#include "system_wrappers.h" -#endif - -#ifdef THREAD -#include -extern pthread_mutex_t THR_LOCK_malloc,THR_LOCK_open,THR_LOCK_keycache, - THR_LOCK_lock,THR_LOCK_isam,THR_LOCK_net,THR_LOCK_charset; -extern pthread_mutex_t LOCK_bitmap; -#else -#include -#endif diff --git a/libmariadb/secure/gnutls.c b/libmariadb/secure/gnutls.c index ebbf1787..7ce154fc 100644 --- a/libmariadb/secure/gnutls.c +++ b/libmariadb/secure/gnutls.c @@ -21,12 +21,12 @@ #include #include -#include -#include +#include +#include #include #include -#include -#include +#include +#include #include #include #include @@ -58,7 +58,7 @@ static void ma_ssl_set_error(MYSQL *mysql, int ssl_errno) ssl_error_reason); return; } - my_snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); + snprintf(ssl_error, MAX_SSL_ERR_LEN, "SSL errno=%lu", ssl_errno, mysql->charset); pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ssl_error); } @@ -187,7 +187,7 @@ static int ma_ssl_set_certs(MYSQL *mysql) error: if (cipher) - my_free(cipher); + free(cipher); return ssl_error; } diff --git a/libmariadb/secure/ma_schannel.c b/libmariadb/secure/ma_schannel.c index 4da14cbe..e871d71c 100644 --- a/libmariadb/secure/ma_schannel.c +++ b/libmariadb/secure/ma_schannel.c @@ -922,7 +922,6 @@ my_bool ma_ssl_get_protocol_version(MARIADB_SSL *cssl, struct st_ssl_version *ve { SC_CTX *sctx; SecPkgContext_ConnectionInfo ConnectionInfo; - if (!cssl->ssl) return 1; diff --git a/libmariadb/secure/ma_schannel.h b/libmariadb/secure/ma_schannel.h index 359b6aae..e2fe6391 100644 --- a/libmariadb/secure/ma_schannel.h +++ b/libmariadb/secure/ma_schannel.h @@ -23,11 +23,11 @@ #define _ma_schannel_h_ #define SECURITY_WIN32 -#include -#include +#include +#include #include #include -#include +#include typedef void VOID; @@ -46,12 +46,7 @@ typedef void VOID; #define SC_IO_BUFFER_SIZE 0x4000 -#ifndef HAVE_SCHANNEL_DEFAULT -#define my_snprintf snprintf -#define my_vsnprintf vsnprintf -#undef SAFE_MUTEX -#endif -#include +#include struct st_schannel { HCERTSTORE cert_store; diff --git a/libmariadb/secure/openssl.c b/libmariadb/secure/openssl.c index 7053e0d5..b22a420b 100644 --- a/libmariadb/secure/openssl.c +++ b/libmariadb/secure/openssl.c @@ -17,11 +17,11 @@ 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include -#include +#include +#include #include #include -#include +#include #include #include #include @@ -31,14 +31,14 @@ #ifndef HAVE_OPENSSL_DEFAULT #include -#define my_malloc(A,B) malloc((A)) -#undef my_free -#define my_free(A) free((A)) -#define my_snprintf snprintf -#define my_vsnprintf vsnprintf +#define ma_malloc(A,B) malloc((A)) +#undef ma_free +#define ma_free(A) free((A)) +#define ma_snprintf snprintf +#define ma_vsnprintf vsnprintf #undef SAFE_MUTEX #endif -#include +#include extern my_bool ma_ssl_initialized; extern unsigned int mariadb_deinitialize_ssl; @@ -64,6 +64,7 @@ static void ma_ssl_set_error(MYSQL *mysql) } if ((ssl_error_reason= ERR_reason_error_string(ssl_errno))) { + printf("reason: %s\n", ssl_error_reason); pvio->set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, 0, ssl_error_reason); return; @@ -126,7 +127,7 @@ static int ssl_thread_init() if (LOCK_crypto == NULL) { if (!(LOCK_crypto= - (pthread_mutex_t *)my_malloc(sizeof(pthread_mutex_t) * max, MYF(0)))) + (pthread_mutex_t *)ma_malloc(sizeof(pthread_mutex_t) * max, MYF(0)))) return 1; for (i=0; i < max; i++) @@ -219,7 +220,7 @@ void ma_ssl_end() for (i=0; i < CRYPTO_num_locks(); i++) pthread_mutex_destroy(&LOCK_crypto[i]); - my_free((gptr)LOCK_crypto); + ma_free((gptr)LOCK_crypto); LOCK_crypto= NULL; if (SSL_context) @@ -246,7 +247,7 @@ void ma_ssl_end() int ma_ssl_get_password(char *buf, int size, int rwflag, void *userdata) { - bzero(buf, size); + memset(buf, 0, size); if (userdata) strncpy(buf, (char *)userdata, size); return strlen(buf); @@ -426,6 +427,7 @@ my_bool ma_ssl_connect(MARIADB_SSL *cssl) rc= SSL_get_verify_result(ssl); if (rc != X509_V_OK) { + printf("--------------------\n"); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), X509_verify_cert_error_string(rc)); /* restore blocking mode */ @@ -572,7 +574,7 @@ unsigned int ma_ssl_get_finger_print(MARIADB_SSL *cssl, unsigned char *fp, unsig fp_len= len; if (!X509_digest(cert, digest, fp, &fp_len)) { - my_free(fp); + ma_free(fp); my_set_error(mysql, CR_SSL_CONNECTION_ERROR, SQLSTATE_UNKNOWN, ER(CR_SSL_CONNECTION_ERROR), "invalid finger print of server certificate"); diff --git a/libmariadb/sha1.c b/libmariadb/sha1.c deleted file mode 100644 index b1c231af..00000000 --- a/libmariadb/sha1.c +++ /dev/null @@ -1,325 +0,0 @@ -/**************************************************************************** - Copyright (C) 2012 Monty Program AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not see - or write to the Free Software Foundation, Inc., - 51 Franklin St., Fifth Floor, Boston, MA 02110, USA -*****************************************************************************/ - -/* This code came from the PHP project, initially written by - Stefan Esser */ - - -#include "my_global.h" -#include "string.h" - -/* This code is heavily based on the PHP md5 implementation */ - -#include "sha1.h" - - -static void SHA1Transform(uint32[5], const unsigned char[64]); -static void SHA1Encode(unsigned char *, uint32 *, unsigned int); -static void SHA1Decode(uint32 *, const unsigned char *, unsigned int); - -static unsigned char PADDING[64] = -{ - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -/* F, G, H and I are basic SHA1 functions. - */ -#define F(x, y, z) ((z) ^ ((x) & ((y) ^ (z)))) -#define G(x, y, z) ((x) ^ (y) ^ (z)) -#define H(x, y, z) (((x) & (y)) | ((z) & ((x) | (y)))) -#define I(x, y, z) ((x) ^ (y) ^ (z)) - -/* ROTATE_LEFT rotates x left n bits. - */ -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32-(n)))) - -/* W[i] - */ -#define W(i) ( tmp=x[(i-3)&15]^x[(i-8)&15]^x[(i-14)&15]^x[i&15], \ - (x[i&15]=ROTATE_LEFT(tmp, 1)) ) - -/* FF, GG, HH, and II transformations for rounds 1, 2, 3, and 4. - */ -#define FF(a, b, c, d, e, w) { \ - (e) += F ((b), (c), (d)) + (w) + (uint32)(0x5A827999); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define GG(a, b, c, d, e, w) { \ - (e) += G ((b), (c), (d)) + (w) + (uint32)(0x6ED9EBA1); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define HH(a, b, c, d, e, w) { \ - (e) += H ((b), (c), (d)) + (w) + (uint32)(0x8F1BBCDC); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } -#define II(a, b, c, d, e, w) { \ - (e) += I ((b), (c), (d)) + (w) + (uint32)(0xCA62C1D6); \ - (e) += ROTATE_LEFT ((a), 5); \ - (b) = ROTATE_LEFT((b), 30); \ - } - - -/* {{{ MYSQL_SHA1Init - * SHA1 initialization. Begins an SHA1 operation, writing a new context. - */ -void MYSQL_SHA1Init(MYSQL_SHA1_CTX * context) -{ - context->count[0] = context->count[1] = 0; - /* Load magic initialization constants. - */ - context->state[0] = 0x67452301; - context->state[1] = 0xefcdab89; - context->state[2] = 0x98badcfe; - context->state[3] = 0x10325476; - context->state[4] = 0xc3d2e1f0; -} -/* }}} */ - -/* {{{ MYSQL_SHA1Update - SHA1 block update operation. Continues an SHA1 message-digest - operation, processing another message block, and updating the - context. - */ -void MYSQL_SHA1Update(MYSQL_SHA1_CTX * context, const unsigned char *input, - size_t inputLen) -{ - unsigned int i, index, partLen; - - /* Compute number of bytes mod 64 */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3F); - - /* Update number of bits */ - if ((context->count[0] += ((uint32) inputLen << 3)) - < ((uint32) inputLen << 3)) - context->count[1]++; - context->count[1] += ((uint32) inputLen >> 29); - - partLen = 64 - index; - - /* Transform as many times as possible. - */ - if (inputLen >= partLen) { - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) input, partLen); - SHA1Transform(context->state, context->buffer); - - for (i = partLen; i + 63 < inputLen; i += 64) - SHA1Transform(context->state, &input[i]); - - index = 0; - } else - i = 0; - - /* Buffer remaining input */ - memcpy - ((unsigned char*) & context->buffer[index], (unsigned char*) & input[i], - inputLen - i); -} -/* }}} */ - -/* {{{ MYSQL_SHA1Final - SHA1 finalization. Ends an SHA1 message-digest operation, writing the - the message digest and zeroizing the context. - */ -void MYSQL_SHA1Final(unsigned char digest[20], MYSQL_SHA1_CTX * context) -{ - unsigned char bits[8]; - unsigned int index, padLen; - - /* Save number of bits */ - bits[7] = context->count[0] & 0xFF; - bits[6] = (context->count[0] >> 8) & 0xFF; - bits[5] = (context->count[0] >> 16) & 0xFF; - bits[4] = (context->count[0] >> 24) & 0xFF; - bits[3] = context->count[1] & 0xFF; - bits[2] = (context->count[1] >> 8) & 0xFF; - bits[1] = (context->count[1] >> 16) & 0xFF; - bits[0] = (context->count[1] >> 24) & 0xFF; - - /* Pad out to 56 mod 64. - */ - index = (unsigned int) ((context->count[0] >> 3) & 0x3f); - padLen = (index < 56) ? (56 - index) : (120 - index); - MYSQL_SHA1Update(context, PADDING, padLen); - - /* Append length (before padding) */ - MYSQL_SHA1Update(context, bits, 8); - - /* Store state in digest */ - SHA1Encode(digest, context->state, 20); - - /* Zeroize sensitive information. - */ - memset((unsigned char*) context, 0, sizeof(*context)); -} -/* }}} */ - -/* {{{ SHA1Transform - * SHA1 basic transformation. Transforms state based on block. - */ -static void SHA1Transform(uint32 state[5], const unsigned char block[64]) -{ - uint32 a = state[0], b = state[1], c = state[2]; - uint32 d = state[3], e = state[4], x[16], tmp; - - SHA1Decode(x, block, 64); - - /* Round 1 */ - FF(a, b, c, d, e, x[0]); /* 1 */ - FF(e, a, b, c, d, x[1]); /* 2 */ - FF(d, e, a, b, c, x[2]); /* 3 */ - FF(c, d, e, a, b, x[3]); /* 4 */ - FF(b, c, d, e, a, x[4]); /* 5 */ - FF(a, b, c, d, e, x[5]); /* 6 */ - FF(e, a, b, c, d, x[6]); /* 7 */ - FF(d, e, a, b, c, x[7]); /* 8 */ - FF(c, d, e, a, b, x[8]); /* 9 */ - FF(b, c, d, e, a, x[9]); /* 10 */ - FF(a, b, c, d, e, x[10]); /* 11 */ - FF(e, a, b, c, d, x[11]); /* 12 */ - FF(d, e, a, b, c, x[12]); /* 13 */ - FF(c, d, e, a, b, x[13]); /* 14 */ - FF(b, c, d, e, a, x[14]); /* 15 */ - FF(a, b, c, d, e, x[15]); /* 16 */ - FF(e, a, b, c, d, W(16)); /* 17 */ - FF(d, e, a, b, c, W(17)); /* 18 */ - FF(c, d, e, a, b, W(18)); /* 19 */ - FF(b, c, d, e, a, W(19)); /* 20 */ - - /* Round 2 */ - GG(a, b, c, d, e, W(20)); /* 21 */ - GG(e, a, b, c, d, W(21)); /* 22 */ - GG(d, e, a, b, c, W(22)); /* 23 */ - GG(c, d, e, a, b, W(23)); /* 24 */ - GG(b, c, d, e, a, W(24)); /* 25 */ - GG(a, b, c, d, e, W(25)); /* 26 */ - GG(e, a, b, c, d, W(26)); /* 27 */ - GG(d, e, a, b, c, W(27)); /* 28 */ - GG(c, d, e, a, b, W(28)); /* 29 */ - GG(b, c, d, e, a, W(29)); /* 30 */ - GG(a, b, c, d, e, W(30)); /* 31 */ - GG(e, a, b, c, d, W(31)); /* 32 */ - GG(d, e, a, b, c, W(32)); /* 33 */ - GG(c, d, e, a, b, W(33)); /* 34 */ - GG(b, c, d, e, a, W(34)); /* 35 */ - GG(a, b, c, d, e, W(35)); /* 36 */ - GG(e, a, b, c, d, W(36)); /* 37 */ - GG(d, e, a, b, c, W(37)); /* 38 */ - GG(c, d, e, a, b, W(38)); /* 39 */ - GG(b, c, d, e, a, W(39)); /* 40 */ - - /* Round 3 */ - HH(a, b, c, d, e, W(40)); /* 41 */ - HH(e, a, b, c, d, W(41)); /* 42 */ - HH(d, e, a, b, c, W(42)); /* 43 */ - HH(c, d, e, a, b, W(43)); /* 44 */ - HH(b, c, d, e, a, W(44)); /* 45 */ - HH(a, b, c, d, e, W(45)); /* 46 */ - HH(e, a, b, c, d, W(46)); /* 47 */ - HH(d, e, a, b, c, W(47)); /* 48 */ - HH(c, d, e, a, b, W(48)); /* 49 */ - HH(b, c, d, e, a, W(49)); /* 50 */ - HH(a, b, c, d, e, W(50)); /* 51 */ - HH(e, a, b, c, d, W(51)); /* 52 */ - HH(d, e, a, b, c, W(52)); /* 53 */ - HH(c, d, e, a, b, W(53)); /* 54 */ - HH(b, c, d, e, a, W(54)); /* 55 */ - HH(a, b, c, d, e, W(55)); /* 56 */ - HH(e, a, b, c, d, W(56)); /* 57 */ - HH(d, e, a, b, c, W(57)); /* 58 */ - HH(c, d, e, a, b, W(58)); /* 59 */ - HH(b, c, d, e, a, W(59)); /* 60 */ - - /* Round 4 */ - II(a, b, c, d, e, W(60)); /* 61 */ - II(e, a, b, c, d, W(61)); /* 62 */ - II(d, e, a, b, c, W(62)); /* 63 */ - II(c, d, e, a, b, W(63)); /* 64 */ - II(b, c, d, e, a, W(64)); /* 65 */ - II(a, b, c, d, e, W(65)); /* 66 */ - II(e, a, b, c, d, W(66)); /* 67 */ - II(d, e, a, b, c, W(67)); /* 68 */ - II(c, d, e, a, b, W(68)); /* 69 */ - II(b, c, d, e, a, W(69)); /* 70 */ - II(a, b, c, d, e, W(70)); /* 71 */ - II(e, a, b, c, d, W(71)); /* 72 */ - II(d, e, a, b, c, W(72)); /* 73 */ - II(c, d, e, a, b, W(73)); /* 74 */ - II(b, c, d, e, a, W(74)); /* 75 */ - II(a, b, c, d, e, W(75)); /* 76 */ - II(e, a, b, c, d, W(76)); /* 77 */ - II(d, e, a, b, c, W(77)); /* 78 */ - II(c, d, e, a, b, W(78)); /* 79 */ - II(b, c, d, e, a, W(79)); /* 80 */ - - state[0] += a; - state[1] += b; - state[2] += c; - state[3] += d; - state[4] += e; - - /* Zeroize sensitive information. */ - memset((unsigned char*) x, 0, sizeof(x)); -} -/* }}} */ - -/* {{{ SHA1Encode - Encodes input (uint32) into output (unsigned char). Assumes len is - a multiple of 4. - */ -static void SHA1Encode(unsigned char *output, uint32 *input, unsigned int len) -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) { - output[j] = (unsigned char) ((input[i] >> 24) & 0xff); - output[j + 1] = (unsigned char) ((input[i] >> 16) & 0xff); - output[j + 2] = (unsigned char) ((input[i] >> 8) & 0xff); - output[j + 3] = (unsigned char) (input[i] & 0xff); - } -} -/* }}} */ - -/* {{{ SHA1Decode - Decodes input (unsigned char) into output (uint32). Assumes len is - a multiple of 4. - */ -static void SHA1Decode(uint32 *output, const unsigned char * input, unsigned int len) -{ - unsigned int i, j; - - for (i = 0, j = 0; j < len; i++, j += 4) - output[i] = ((uint32) input[j + 3]) | (((uint32) input[j + 2]) << 8) | - (((uint32) input[j + 1]) << 16) | (((uint32) input[j]) << 24); -} -/* }}} */ - -/* - * Local variables: - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600: sw=4 ts=4 fdm=marker - * vim<600: sw=4 ts=4 - */ diff --git a/libmariadb/str2int.c b/libmariadb/str2int.c deleted file mode 100644 index 7f42b028..00000000 --- a/libmariadb/str2int.c +++ /dev/null @@ -1,202 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - str2int(src, radix, lower, upper, &val) - converts the string pointed to by src to an integer and stores it in - val. It skips leading spaces and tabs (but not newlines, formfeeds, - backspaces), then it accepts an optional sign and a sequence of digits - in the specified radix. The result should satisfy lower <= *val <= upper. - The result is a pointer to the first character after the number; - trailing spaces will NOT be skipped. - - If an error is detected, the result will be NullS, the value put - in val will be 0, and errno will be set to - EDOM if there are no digits - ERANGE if the result would overflow or otherwise fail to lie - within the specified bounds. - Check that the bounds are right for your machine. - This looks amazingly complicated for what you probably thought was an - easy task. Coping with integer overflow and the asymmetric range of - twos complement machines is anything but easy. - - So that users of atoi and atol can check whether an error occured, - I have taken a wholly unprecedented step: errno is CLEARED if this - call has no problems. -*/ - -#include -#include "m_string.h" -#include "m_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#define char_val(X) (X >= '0' && X <= '9' ? X-'0' :\ - X >= 'A' && X <= 'Z' ? X-'A'+10 :\ - X >= 'a' && X <= 'z' ? X-'a'+10 :\ - '\177') - -char *str2int(register const char *src, register int radix, long int lower, long int upper, long int *val) -{ - int sign; /* is number negative (+1) or positive (-1) */ - int n; /* number of digits yet to be converted */ - long limit; /* "largest" possible valid input */ - long scale; /* the amount to multiply next digit by */ - long sofar; /* the running value */ - register int d; /* (negative of) next digit */ - char *start; - int digits[32]; /* Room for numbers */ - - /* Make sure *val is sensible in case of error */ - - *val = 0; - - /* Check that the radix is in the range 2..36 */ - -#ifndef DBUG_OFF - if (radix < 2 || radix > 36) { - errno=EDOM; - return NullS; - } -#endif - - /* The basic problem is: how do we handle the conversion of - a number without resorting to machine-specific code to - check for overflow? Obviously, we have to ensure that - no calculation can overflow. We are guaranteed that the - "lower" and "upper" arguments are valid machine integers. - On sign-and-magnitude, twos-complement, and ones-complement - machines all, if +|n| is representable, so is -|n|, but on - twos complement machines the converse is not true. So the - "maximum" representable number has a negative representative. - Limit is set to min(-|lower|,-|upper|); this is the "largest" - number we are concerned with. */ - - /* Calculate Limit using Scale as a scratch variable */ - - if ((limit = lower) > 0) limit = -limit; - if ((scale = upper) > 0) scale = -scale; - if (scale < limit) limit = scale; - - /* Skip leading spaces and check for a sign. - Note: because on a 2s complement machine MinLong is a valid - integer but |MinLong| is not, we have to keep the current - converted value (and the scale!) as *negative* numbers, - so the sign is the opposite of what you might expect. - */ - while (isspace(*src)) src++; - sign = -1; - if (*src == '+') src++; else - if (*src == '-') src++, sign = 1; - - /* Skip leading zeros so that we never compute a power of radix - in scale that we won't have a need for. Otherwise sticking - enough 0s in front of a number could cause the multiplication - to overflow when it neededn't. - */ - start=(char*) src; - while (*src == '0') src++; - - /* Move over the remaining digits. We have to convert from left - to left in order to avoid overflow. Answer is after last digit. - */ - - for (n = 0; (digits[n]=char_val(*src)) < radix && n < 20; n++,src++) ; - - /* Check that there is at least one digit */ - - if (start == src) { - errno=EDOM; - return NullS; - } - - /* The invariant we want to maintain is that src is just - to the right of n digits, we've converted k digits to - sofar, scale = -radix**k, and scale < sofar < 0. Now - if the final number is to be within the original - Limit, we must have (to the left)*scale+sofar >= Limit, - or (to the left)*scale >= Limit-sofar, i.e. the digits - to the left of src must form an integer <= (Limit-sofar)/(scale). - In particular, this is true of the next digit. In our - incremental calculation of Limit, - - IT IS VITAL that (-|N|)/(-|D|) = |N|/|D| - */ - - for (sofar = 0, scale = -1; --n >= 1;) - { - if ((long) -(d=digits[n]) < limit) { - errno=ERANGE; - return NullS; - } - limit = (limit+d)/radix, sofar += d*scale; scale *= radix; - } - if (n == 0) - { - if ((long) -(d=digits[n]) < limit) /* get last digit */ - { - errno=ERANGE; - return NullS; - } - sofar+=d*scale; - } - - /* Now it might still happen that sofar = -32768 or its equivalent, - so we can't just multiply by the sign and check that the result - is in the range lower..upper. All of this caution is a right - pain in the neck. If only there were a standard routine which - says generate thus and such a signal on integer overflow... - But not enough machines can do it *SIGH*. - */ - if (sign < 0) - { - if (sofar < -LONG_MAX || (sofar= -sofar) > upper) - { - errno=ERANGE; - return NullS; - } - } - else if (sofar < lower) - { - errno=ERANGE; - return NullS; - } - *val = sofar; - errno=0; /* indicate that all went well */ - return (char*) src; -} - - /* Theese are so slow compared with ordinary, optimized atoi */ - -#ifdef WANT_OUR_ATOI - -int atoi(const char *src) -{ - long val; - str2int(src, 10, (long) INT_MIN, (long) INT_MAX, &val); - return (int) val; -} - - -long atol(const char *src) -{ - long val; - str2int(src, 10, LONG_MIN, LONG_MAX, &val); - return val; -} - -#endif /* WANT_OUR_ATOI */ diff --git a/libmariadb/strcend.c b/libmariadb/strcend.c deleted file mode 100644 index 0b7e9acf..00000000 --- a/libmariadb/strcend.c +++ /dev/null @@ -1,48 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strcend.c - Author : Michael Widenius: ifdef MC68000 - Updated: 20 April 1984 - Defines: strcend() - - strcend(s, c) returns a pointer to the first place in s where c - occurs, or a pointer to the end-null of s if c does not occur in s. -*/ - -#include -#include "m_string.h" - -/** - \fn char *strcend - \brief returns a pointer to the first occurence of specified stopchar - \param str char * - \param stopchar char - - returns a poimter to the first occurence of stopchar or to null char, - if stopchar wasn't found. -*/ -char *strcend(register const char *str, register char stopchar) -{ - for (;;) - { - if (*str == stopchar) - return (char*) str; - if (!*str++) - return (char*) str-1; - } -} diff --git a/libmariadb/strcont.c b/libmariadb/strcont.c deleted file mode 100644 index d4e903a1..00000000 --- a/libmariadb/strcont.c +++ /dev/null @@ -1,46 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strcont.c - Author : Monty - Updated: 1988.07.27 - Defines: strcont() - - strcont(str, set) if str contanies any character in the string set. - The result is the position of the first found character in str, or NullS - if there isn't anything found. - -*/ - -#include -#include "m_string.h" - -my_string strcont(reg1 const char *str,reg2 const char *set) -{ - reg3 my_string start = (my_string) set; - - while (*str) - { - while (*set) - { - if (*set++ == *str) - return ((char*) str); - } - set=start; str++; - } - return (NullS); -} /* strcont */ diff --git a/libmariadb/strend.c b/libmariadb/strend.c deleted file mode 100644 index 0e9c0333..00000000 --- a/libmariadb/strend.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strend.c - Author : Richard A. O'Keefe. - Updated: 23 April 1984 - Defines: strend() - - strend(s) returns a character pointer to the NUL which ends s. That - is, strend(s)-s == strlen(s). This is useful for adding things at - the end of strings. It is redundant, because strchr(s,'\0') could - be used instead, but this is clearer and faster. - Beware: the asm version works only if strlen(s) < 65535. -*/ - -#include -#include "m_string.h" - -#if VaxAsm - -char *strend(s) -const char *s; -{ - asm("locc $0,$65535,*4(ap)"); - asm("movl r1,r0"); -} - -#else /* ~VaxAsm */ - -char *strend(register const char *s) -{ - while (*s++); - return (char*) (s-1); -} - -#endif /* VaxAsm */ diff --git a/libmariadb/strfill.c b/libmariadb/strfill.c deleted file mode 100644 index 0559f171..00000000 --- a/libmariadb/strfill.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strfill.c - Author : Monty - Updated: 1987.04.16 - Defines: strfill() - - strfill(dest, len, fill) makes a string of fill-characters. The result - string is of length == len. The des+len character is allways set to NULL. - strfill() returns pointer to dest+len; -*/ - -#include -#include "m_string.h" - -my_string strfill(my_string s, size_t len, pchar fill) -{ - while (len--) *s++ = fill; - *(s) = '\0'; - return(s); -} /* strfill */ diff --git a/libmariadb/strinstr.c b/libmariadb/strinstr.c deleted file mode 100644 index 8ebd6afb..00000000 --- a/libmariadb/strinstr.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strinstr.c - Author : Monty & David - Updated: 1986.12.08 - Defines: strinstr() - - strinstr(src, pat) looks for an instance of pat in src. pat is not a - regex(3) pattern, it is a literal string which must be matched exactly. - The result 0 if the pattern was not found else it is the start char of - the pattern counted from the beginning of the string, where the first - char is 1. -*/ - -#include -#include "m_string.h" - -uint strinstr(reg1 const char *str,reg4 const char *search) -{ - reg2 my_string i,j; - my_string start = (my_string) str; - - skipp: - while (*str != '\0') - { - if (*str++ == *search) - { - i=(my_string) str; j= (my_string) search+1; - while (*j) - if (*i++ != *j++) goto skipp; - return ((uint) (str - start)); - } - } - return (0); -} diff --git a/libmariadb/strmake.c b/libmariadb/strmake.c deleted file mode 100644 index c7820947..00000000 --- a/libmariadb/strmake.c +++ /dev/null @@ -1,54 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strmake.c - Author : Michael Widenius - Updated: 20 Jul 1984 - Defines: strmake() - - strmake(dst,src,length) moves length characters, or until end, of src to - dst and appends a closing NUL to dst. - Note that is strlen(src) >= length then dst[length] will be set to \0 - strmake() returns pointer to closing null -*/ - -#include -#include "m_string.h" - -#ifdef BAD_STRING_COMPILER - -char *strmake(char *dst,const char *src, size_t length) -{ - reg1 char *res; - - if ((res=memccpy(dst,src,0,length))) - return res-1; - dst[length]=0; - return dst+length; -} - -#define strmake strmake_overlapp /* Use orginal for overlapping str */ -#endif - -char *strmake(register char *dst, register const char *src, size_t length) -{ - while (length--) - if (! (*dst++ = *src++)) - return dst-1; - *dst=0; - return dst; -} diff --git a/libmariadb/strmov.c b/libmariadb/strmov.c deleted file mode 100644 index 5502c40b..00000000 --- a/libmariadb/strmov.c +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strmov(dst, src) moves all the characters of src (including the - closing NUL) to dst, and returns a pointer to the new closing NUL in - dst. The similar UNIX routine strcpy returns the old value of dst, - which I have never found useful. strmov(strmov(dst,a),b) moves a//b - into dst, which seems useful. -*/ - -#include -#include "m_string.h" - -#ifdef BAD_STRING_COMPILER -#undef strmov -#define strmov strmov_overlapp -#endif - -#ifndef strmov - -#if !defined(MC68000) && !defined(DS90) - -char *strmov(register char *dst, register const char *src) -{ - while ((*dst++ = *src++)) ; - return dst-1; -} - -#else - -char *strmov(dst, src) - char *dst, *src; -{ - asm(" movl 4(a7),a1 "); - asm(" movl 8(a7),a0 "); - asm(".L4: movb (a0)+,(a1)+ "); - asm(" jne .L4 "); - asm(" movl a1,d0 "); - asm(" subql #1,d0 "); -} - -#endif - -#endif /* strmov */ diff --git a/libmariadb/strnlen.c b/libmariadb/strnlen.c deleted file mode 100644 index b630edec..00000000 --- a/libmariadb/strnlen.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strnlen.c - Author : Michael Widenius - Updated: 20 April 1984 - Defines: strnlen. - strnlen(s, len) returns the length of s or len if s is longer than len. -*/ - -#include -#include "m_string.h" - -#ifndef HAVE_STRNLEN - -uint strnlen(register const char *s, register uint maxlen) -{ - const char *end= (const char *)memchr(s, '\0', maxlen); - return end ? (uint) (end - s) : maxlen; -} - -#endif diff --git a/libmariadb/strnmov.c b/libmariadb/strnmov.c deleted file mode 100644 index 5b3e3b3b..00000000 --- a/libmariadb/strnmov.c +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strnmov(dst,src,length) moves length characters, or until end, of src to - dst and appends a closing NUL to dst if src is shorter than length. - The result is a pointer to the first NUL in dst, or is dst+n if dst was - truncated. -*/ - -#include -#include "m_string.h" - -char *strnmov(register char *dst, register const char *src, uint n) -{ - while (n-- != 0) { - if (!(*dst++ = *src++)) { - return (char*) dst-1; - } - } - return dst; -} diff --git a/libmariadb/strto.c b/libmariadb/strto.c deleted file mode 100644 index 097fc012..00000000 --- a/libmariadb/strto.c +++ /dev/null @@ -1,209 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* - strtol,strtoul,strtoll,strtoull - convert string to long, unsigned long, long long or unsigned long long. - strtoxx(char *src,char **ptr,int base) - converts the string pointed to by src to an long of appropriate long and - returnes it. It skips leading spaces and tabs (but not newlines, formfeeds, - backspaces), then it accepts an optional sign and a sequence of digits - in the specified radix. - If the value of ptr is not (char **)NULL, a pointer to the character - terminating the scan is returned in the location pointed to by ptr. - Trailing spaces will NOT be skipped. - - If an error is detected, the result will be LONG_MIN, 0 or LONG_MAX, - (or LONGLONG..) and errno will be set to - EDOM if there are no digits - ERANGE if the result would overflow. - the ptr will be set to src. - This file is based on the strtol from the the GNU C Library. - it can be compiled with the UNSIGNED and/or LONGLONG flag set -*/ - -#define strtoll glob_strtoll /* Fix for True64 */ - -#include "m_string.h" -#include "m_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#undef strtoull -#undef strtoll -#undef strtoul -#undef strtol -#ifdef USE_LONGLONG -#define UTYPE_MAX (~(ulonglong) 0) -#define TYPE_MIN LONGLONG_MIN -#define TYPE_MAX LONGLONG_MAX -#define longtype longlong -#define ulongtype ulonglong -#ifdef USE_UNSIGNED -#define function ulongtype strtoull -#else -#define function longtype strtoll -#endif -#else -#define UTYPE_MAX (ulong) ~0L -#define TYPE_MIN LONG_MIN -#define TYPE_MAX LONG_MAX -#define longtype long -#define ulongtype unsigned long -#ifdef USE_UNSIGNED -#define function ulongtype strtoul -#else -#define function longtype strtol -#endif -#endif - - -/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. - If BASE is 0 the base is determined by the presence of a leading - zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. - If BASE is < 2 or > 36, it is reset to 10. - If ENDPTR is not NULL, a pointer to the character after the last - one converted is stored in *ENDPTR. */ - - -function (const char *nptr,char **endptr,int base) -{ - int negative; - register ulongtype cutoff; - register unsigned int cutlim; - register ulongtype i; - register const char *s; - register unsigned char c; - const char *save; - int overflow; - - if (base < 0 || base == 1 || base > 36) - base = 10; - - s = nptr; - - /* Skip white space. */ - while (isspace (*s)) - ++s; - if (*s == '\0') - { - goto noconv; - } - - /* Check for a sign. */ - if (*s == '-') - { - negative = 1; - ++s; - } - else if (*s == '+') - { - negative = 0; - ++s; - } - else - negative = 0; - - if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') - s += 2; - - /* If BASE is zero, figure it out ourselves. */ - if (base == 0) - { - if (*s == '0') - { - if (toupper (s[1]) == 'X') - { - s += 2; - base = 16; - } - else - base = 8; - } - else - base = 10; - } - - /* Save the pointer so we can check later if anything happened. */ - save = s; - - cutoff = UTYPE_MAX / (unsigned long int) base; - cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); - - overflow = 0; - i = 0; - for (c = *s; c != '\0'; c = *++s) - { - if (isdigit (c)) - c -= '0'; - else if (isalpha (c)) - c = toupper (c) - 'A' + 10; - else - break; - if (c >= base) - break; - /* Check for overflow. */ - if (i > cutoff || (i == cutoff && c > cutlim)) - overflow = 1; - else - { - i *= (ulongtype) base; - i += c; - } - } - - /* Check if anything actually happened. */ - if (s == save) - goto noconv; - - /* Store in ENDPTR the address of one character - past the last character we converted. */ - if (endptr != NULL) - *endptr = (char *) s; - -#ifndef USE_UNSIGNED - /* Check for a value that is within the range of - `unsigned long int', but outside the range of `long int'. */ - if (negative) - { - if (i > (ulongtype) TYPE_MIN) - overflow = 1; - } - else if (i > (ulongtype) TYPE_MAX) - overflow = 1; -#endif - - if (overflow) - { - my_errno=ERANGE; -#ifdef USE_UNSIGNED - return UTYPE_MAX; -#else - return negative ? TYPE_MIN : TYPE_MAX; -#endif - } - - /* Return the result of the appropriate sign. */ - return (negative ? -((longtype) i) : (longtype) i); - -noconv: - /* There was no number to convert. */ - my_errno=EDOM; - if (endptr != NULL) - *endptr = (char *) nptr; - return 0L; -} diff --git a/libmariadb/strtoll.c b/libmariadb/strtoll.c deleted file mode 100644 index ba72a83f..00000000 --- a/libmariadb/strtoll.c +++ /dev/null @@ -1,198 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This is defines strtoll() if neaded */ - -#include -#include -#if !defined(HAVE_STRTOLL) && defined(HAVE_LONG_LONG) -#define USE_LONGLONG - -#define strtoll glob_strtoll /* Fix for True64 */ - -#include "m_string.h" -#include "m_ctype.h" -#include "my_sys.h" /* defines errno */ -#include - -#undef strtoull -#undef strtoll -#undef strtoul -#undef strtol -#ifdef USE_LONGLONG -#define UTYPE_MAX (~(ulonglong) 0) -#define TYPE_MIN LONGLONG_MIN -#define TYPE_MAX LONGLONG_MAX -#define longtype longlong -#define ulongtype ulonglong -#ifdef USE_UNSIGNED -#define function ulongtype strtoull -#else -#define function longtype strtoll -#endif -#else -#define UTYPE_MAX (ulong) ~0L -#define TYPE_MIN LONG_MIN -#define TYPE_MAX LONG_MAX -#define longtype long -#define ulongtype unsigned long -#ifdef USE_UNSIGNED -#define function ulongtype strtoul -#else -#define function longtype strtol -#endif -#endif - - -/* Convert NPTR to an `unsigned long int' or `long int' in base BASE. - If BASE is 0 the base is determined by the presence of a leading - zero, indicating octal or a leading "0x" or "0X", indicating hexadecimal. - If BASE is < 2 or > 36, it is reset to 10. - If ENDPTR is not NULL, a pointer to the character after the last - one converted is stored in *ENDPTR. */ - - -function (const char *nptr,char **endptr,int base) -{ - int negative; - register ulongtype cutoff; - register unsigned int cutlim; - register ulongtype i; - register const char *s; - register unsigned char c; - const char *save; - int overflow; - - if (base < 0 || base == 1 || base > 36) - base = 10; - - s = nptr; - - /* Skip white space. */ - while (isspace (*s)) - ++s; - if (*s == '\0') - { - goto noconv; - } - - /* Check for a sign. */ - if (*s == '-') - { - negative = 1; - ++s; - } - else if (*s == '+') - { - negative = 0; - ++s; - } - else - negative = 0; - - if (base == 16 && s[0] == '0' && toupper (s[1]) == 'X') - s += 2; - - /* If BASE is zero, figure it out ourselves. */ - if (base == 0) - { - if (*s == '0') - { - if (toupper (s[1]) == 'X') - { - s += 2; - base = 16; - } - else - base = 8; - } - else - base = 10; - } - - /* Save the pointer so we can check later if anything happened. */ - save = s; - - cutoff = UTYPE_MAX / (unsigned long int) base; - cutlim = (uint) (UTYPE_MAX % (unsigned long int) base); - - overflow = 0; - i = 0; - for (c = *s; c != '\0'; c = *++s) - { - if (isdigit (c)) - c -= '0'; - else if (isalpha (c)) - c = toupper (c) - 'A' + 10; - else - break; - if (c >= base) - break; - /* Check for overflow. */ - if (i > cutoff || (i == cutoff && c > cutlim)) - overflow = 1; - else - { - i *= (ulongtype) base; - i += c; - } - } - - /* Check if anything actually happened. */ - if (s == save) - goto noconv; - - /* Store in ENDPTR the address of one character - past the last character we converted. */ - if (endptr != NULL) - *endptr = (char *) s; - -#ifndef USE_UNSIGNED - /* Check for a value that is within the range of - `unsigned long int', but outside the range of `long int'. */ - if (negative) - { - if (i > (ulongtype) TYPE_MIN) - overflow = 1; - } - else if (i > (ulongtype) TYPE_MAX) - overflow = 1; -#endif - - if (overflow) - { - my_errno=ERANGE; -#ifdef USE_UNSIGNED - return UTYPE_MAX; -#else - return negative ? TYPE_MIN : TYPE_MAX; -#endif - } - - /* Return the result of the appropriate sign. */ - return (negative ? -((longtype) i) : (longtype) i); - -noconv: - /* There was no number to convert. */ - my_errno=EDOM; - if (endptr != NULL) - *endptr = (char *) nptr; - return 0L; -} - - -#endif diff --git a/libmariadb/strxmov.c b/libmariadb/strxmov.c deleted file mode 100644 index fe1e88c1..00000000 --- a/libmariadb/strxmov.c +++ /dev/null @@ -1,50 +0,0 @@ -/* Copyright (C) 2002 MySQL AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* File : strxmov.c - Author : Richard A. O'Keefe. - Updated: 25 may 1984 - Defines: strxmov() - - strxmov(dst, src1, ..., srcn, NullS) - moves the concatenation of src1,...,srcn to dst, terminates it - with a NUL character, and returns a pointer to the terminating NUL. - It is just like strmov except that it concatenates multiple sources. - Beware: the last argument should be the null character pointer. - Take VERY great care not to omit it! Also be careful to use NullS - and NOT to use 0, as on some machines 0 is not the same size as a - character pointer, or not the same bit pattern as NullS. -*/ - -#include -#include "m_string.h" -#include - -char *strxmov(char *dst,const char *src, ...) -{ - va_list pvar; - - va_start(pvar,src); - while (src != NullS) { - while ((*dst++ = *src++)) ; - dst--; - src = va_arg(pvar, char *); - } - va_end(pvar); - *dst = 0; /* there might have been no sources! */ - return dst; -} diff --git a/libmariadb/strxnmov.c b/libmariadb/strxnmov.c deleted file mode 100644 index d5167f69..00000000 --- a/libmariadb/strxnmov.c +++ /dev/null @@ -1,48 +0,0 @@ -/* File : strxnmov.c - Author : Richard A. O'Keefe. - Updated: 2 June 1984 - Defines: strxnmov() - - strxnmov(dst, len, src1, ..., srcn, NullS) - moves the first len characters of the concatenation of src1,...,srcn - to dst. If there aren't that many characters, a NUL character will - be added to the end of dst to terminate it properly. This gives the - same effect as calling strxcpy(buff, src1, ..., srcn, NullS) with a - large enough buffer, and then calling strnmov(dst, buff, len). - It is just like strnmov except that it concatenates multiple sources. - Beware: the last argument should be the null character pointer. - Take VERY great care not to omit it! Also be careful to use NullS - and NOT to use 0, as on some machines 0 is not the same size as a - character pointer, or not the same bit pattern as NullS. - - Note: strxnmov is like strnmov in that it moves up to len - characters; dst will be padded on the right with one NUL characters if - needed. -*/ - -#include -#include "m_string.h" -#include - -char *strxnmov(char *dst, size_t len, const char *src, ...) -{ - va_list pvar; - char *end_of_dst=dst+len; - - va_start(pvar,src); - while (src != NullS) - { - do - { - if (dst == end_of_dst) - goto end; - } - while ((*dst++ = *src++)); - dst--; - src = va_arg(pvar, char *); - } - *dst=0; -end: - va_end(pvar); - return dst; -} diff --git a/libmariadb/thr_mutex.c b/libmariadb/thr_mutex.c deleted file mode 100644 index a985c58b..00000000 --- a/libmariadb/thr_mutex.c +++ /dev/null @@ -1,231 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* This makes a wrapper for mutex handling to make it easier to debug mutex */ - -#include -#if defined(HAVE_LINUXTHREADS) && !defined (__USE_UNIX98) -#define __USE_UNIX98 /* To get rw locks under Linux */ -#endif -#include -#if defined(THREAD) && defined(SAFE_MUTEX) -#undef SAFE_MUTEX /* Avoid safe_mutex redefinitions */ -#include - -#ifndef DO_NOT_REMOVE_THREAD_WRAPPERS -/* Remove wrappers */ -#undef pthread_mutex_init -#undef pthread_mutex_lock -#undef pthread_mutex_unlock -#undef pthread_mutex_destroy -#undef pthread_cond_wait -#undef pthread_cond_timedwait -#ifdef HAVE_NONPOSIX_PTHREAD_MUTEX_INIT -#define pthread_mutex_init(a,b) my_pthread_mutex_init((a),(b)) -#endif -#endif /* DO_NOT_REMOVE_THREAD_WRAPPERS */ - -int safe_mutex_init(safe_mutex_t *mp, - const pthread_mutexattr_t *attr __attribute__((unused))) -{ - bzero((char*) mp,sizeof(*mp)); - pthread_mutex_init(&mp->global,MY_MUTEX_INIT_ERRCHK); - pthread_mutex_init(&mp->mutex,attr); - return 0; -} - -int safe_mutex_lock(safe_mutex_t *mp,const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count > 0 && pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to lock mutex at %s, line %d, when the mutex was already locked at %s, line %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - pthread_mutex_unlock(&mp->global); - error=pthread_mutex_lock(&mp->mutex); - if (error || (error=pthread_mutex_lock(&mp->global))) - { - fprintf(stderr,"Got error %d when trying to lock mutex at %s, line %d\n", - error, file, line); - fflush(stderr); - abort(); - } - if (mp->count++) - { - fprintf(stderr,"safe_mutex: Error in thread libray: Got mutex at %s, line %d more than 1 time\n", file,line); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_mutex_unlock(safe_mutex_t *mp,const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count == 0) - { - fprintf(stderr,"safe_mutex: Trying to unlock mutex that wasn't locked at %s, line %d\n Last used at %s, line: %d\n", - file,line,mp->file ? mp->file : "",mp->line); - fflush(stderr); - abort(); - } - if (!pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to unlock mutex at %s, line %d that was locked by another thread at: %s, line: %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - mp->count--; -#ifdef _WIN32 - pthread_mutex_unlock(&mp->mutex); - error=0; -#else - error=pthread_mutex_unlock(&mp->mutex); - if (error) - { - fprintf(stderr,"safe_mutex: Got error: %d when trying to unlock mutex at %s, line %d\n", error, file, line); - fflush(stderr); - abort(); - } -#endif /* _WIN32 */ - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_cond_wait(pthread_cond_t *cond, safe_mutex_t *mp, const char *file, - uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count == 0) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait on a unlocked mutex at %s, line %d\n",file,line); - fflush(stderr); - abort(); - } - if (!pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait on a mutex at %s, line %d that was locked by another thread at: %s, line: %d\n", - file,line,mp->file,mp->line); - fflush(stderr); - abort(); - } - - if (mp->count-- != 1) - { - fprintf(stderr,"safe_mutex: Count was %d on locked mutex at %s, line %d\n", - mp->count+1, file, line); - fflush(stderr); - abort(); - } - pthread_mutex_unlock(&mp->global); - error=pthread_cond_wait(cond,&mp->mutex); - pthread_mutex_lock(&mp->global); - if (error) - { - fprintf(stderr,"safe_mutex: Got error: %d when doing a safe_mutex_wait at %s, line %d\n", error, file, line); - fflush(stderr); - abort(); - } - if (mp->count++) - { - fprintf(stderr, - "safe_mutex: Count was %d in thread %lx when locking mutex at %s, line %d\n", - mp->count-1, my_thread_id(), file, line); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - - -int safe_cond_timedwait(pthread_cond_t *cond, safe_mutex_t *mp, - struct timespec *abstime, - const char *file, uint line) -{ - int error; - pthread_mutex_lock(&mp->global); - if (mp->count != 1 || !pthread_equal(pthread_self(),mp->thread)) - { - fprintf(stderr,"safe_mutex: Trying to cond_wait at %s, line %d on a not hold mutex\n",file,line); - fflush(stderr); - abort(); - } - mp->count--; /* Mutex will be released */ - pthread_mutex_unlock(&mp->global); - error=pthread_cond_timedwait(cond,&mp->mutex,abstime); -#ifdef EXTRA_DEBUG - if (error && (error != EINTR && error != ETIMEDOUT)) - { - fprintf(stderr,"safe_mutex: Got error: %d when doing a safe_mutex_timedwait at %s, line %d\n", error, file, line); - } -#endif - pthread_mutex_lock(&mp->global); - if (mp->count++) - { - fprintf(stderr, - "safe_mutex: Count was %d in thread %lx when locking mutex at %s, line %d (error: %d)\n", - mp->count-1, my_thread_id(), file, line, error); - fflush(stderr); - abort(); - } - mp->thread=pthread_self(); - mp->file= (char*) file; - mp->line=line; - pthread_mutex_unlock(&mp->global); - return error; -} - -int safe_mutex_destroy(safe_mutex_t *mp, const char *file, uint line) -{ - int error=0; - if (mp->count != 0) - { - fprintf(stderr,"safe_mutex: Trying to destroy a mutex that was locked at %s, line %d at %s, line %d\n", - mp->file,mp->line, file, line); - fflush(stderr); - abort(); - } -#ifdef _WIN32 - pthread_mutex_destroy(&mp->global); - pthread_mutex_destroy(&mp->mutex); -#else - if (pthread_mutex_destroy(&mp->global)) - error=1; - if (pthread_mutex_destroy(&mp->mutex)) - error=1; -#endif - return error; -} - -#endif /* THREAD && SAFE_MUTEX */ diff --git a/libmariadb/typelib.c b/libmariadb/typelib.c deleted file mode 100644 index 7e1fb623..00000000 --- a/libmariadb/typelib.c +++ /dev/null @@ -1,106 +0,0 @@ -/* Copyright (C) 2000 MySQL AB & MySQL Finland AB & TCX DataKonsult AB - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License as published by the Free Software Foundation; either - version 2 of the License, or (at your option) any later version. - - This library is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public - License along with this library; if not, write to the Free - Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, - MA 02111-1307, USA */ - -/* Functions to handle typelib */ - -#include "mysys_priv.h" -#include -#include - -/*************************************************************************** -** Search after a fieldtype. Endspace in x is not compared. -** If part, uniq field is found and full_name == 0 then x is expanded -** to full field. -** full_name has the following bit values: -** If & 1 accept only whole names -** If & 2 don't expand if half field -** If & 4 allow #number# as type -****************************************************************************/ - -int find_type(my_string x, TYPELIB *typelib, uint full_name) -{ - int find,pos,findpos= 0; - reg1 my_string i; - reg2 const char *j; - DBUG_ENTER("find_type"); - DBUG_PRINT("enter",("x: '%s' lib: %lx",x,typelib)); - - if (!typelib->count) - { - DBUG_PRINT("exit",("no count")); - DBUG_RETURN(0); - } - LINT_INIT(findpos); - find=0; - for (pos=0 ; (j=typelib->type_names[pos]) ; pos++) - { - for (i=x ; *i && toupper(*i) == toupper(*j) ; i++, j++) ; - if (! *j) - { - while (*i == ' ') - i++; /* skipp_end_space */ - if (! *i) - DBUG_RETURN(pos+1); - } - if (! *i && (!*j || !(full_name & 1))) - { - find++; - findpos=pos; - } - } - if (find == 0 && (full_name & 4) && x[0] == '#' && strend(x)[-1] == '#' && - (findpos=atoi(x+1)-1) >= 0 && (uint) findpos < typelib->count) - find=1; - else if (find == 0 || ! x[0]) - { - DBUG_PRINT("exit",("Couldn't find type")); - DBUG_RETURN(0); - } - else if (find != 1 || (full_name & 1)) - { - DBUG_PRINT("exit",("Too many possybilities")); - DBUG_RETURN(-1); - } - if (!(full_name & 2)) - (void) strmov(x,typelib->type_names[findpos]); - DBUG_RETURN(findpos+1); -} /* find_type */ - - - /* Get name of type nr 'nr' */ - /* Warning first type is 1, 0 = empty field */ - -void make_type(register my_string to, register uint nr, register TYPELIB *typelib) -{ - DBUG_ENTER("make_type"); - if (!nr) - to[0]=0; - else - (void) strmov(to,get_type(typelib,nr-1)); - DBUG_VOID_RETURN; -} /* make_type */ - - - /* Get type */ - /* Warning first type is 0 */ - -const char *get_type(TYPELIB *typelib, uint nr) -{ - if (nr < (uint) typelib->count && typelib->type_names) - return(typelib->type_names[nr]); - return "?"; -} diff --git a/mariadb_config/mariadb_config.c.in b/mariadb_config/mariadb_config.c.in index b4aa74c6..227cfa56 100644 --- a/mariadb_config/mariadb_config.c.in +++ b/mariadb_config/mariadb_config.c.in @@ -1,11 +1,14 @@ -#include -#include +#include +#include #include #include +static char *mariadb_progname; + #define INCLUDE "-I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -I@PREFIX_INSTALL_DIR@/@INCLUDE_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@/mysql" #define LIBS "-L@PREFIX_INSTALL_DIR@/@LIB_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@ -lmariadb" \ "@extra_dynamic_LDFLAGS@" +#define LIBS_SYS "@extra_dynamic_LDFLAGS@" #define CFLAGS INCLUDE " @CMAKE_C_FLAGS@" #define VERSION "@MYSQL_CLIENT_VERSION@" #define PLUGIN_DIR "@PREFIX_INSTALL_DIR@/@SUFFIX_INSTALL_DIR@/@PLUGIN_INSTALL_DIR@" @@ -19,6 +22,7 @@ static struct option long_options[]= {"include", no_argument, 0, 'c'}, {"libs", no_argument, 0, 'd'}, {"libs_r", no_argument, 0, 'e'}, + {"libs_sys", no_argument, 0, 'y'}, {"version", no_argument, 0, 'f'}, {"socket", no_argument, 0, 'g'}, {"port", no_argument, 0, 'h'}, @@ -33,6 +37,7 @@ static char *values[]= INCLUDE, LIBS, LIBS, + LIBS_SYS, VERSION, SOCKET, PORT, @@ -44,7 +49,7 @@ void usage(void) int i=0; puts("Copyright 2011-2015 MariaDB Corporation AB"); puts("Get compiler flags for using the MariaDB Connector/C."); - printf("Usage: %s [OPTIONS]\n", my_progname); + printf("Usage: %s [OPTIONS]\n", mariadb_progname); while (long_options[i].name) { if (values[i]) @@ -57,7 +62,7 @@ void usage(void) int main(int argc, char **argv) { int c; - my_progname= argv[0]; + mariadb_progname= argv[0]; if (argc <= 1) { @@ -96,6 +101,9 @@ int main(int argc, char **argv) case 'p': puts(PLUGINDIR); break; + case 'y': + puts(LIBS_SYS); + break; default: exit(0); } diff --git a/plugins/auth/auth_gssapi_client.c b/plugins/auth/auth_gssapi_client.c index d0ed3795..4e0b57b6 100644 --- a/plugins/auth/auth_gssapi_client.c +++ b/plugins/auth/auth_gssapi_client.c @@ -33,9 +33,9 @@ POSSIBILITY OF SUCH DAMAGE. */ #include #include -#include +#include #include -#include +#include #include #include #include diff --git a/plugins/auth/dialog.c b/plugins/auth/dialog.c index 4ace14fc..1d51086c 100644 --- a/plugins/auth/dialog.c +++ b/plugins/auth/dialog.c @@ -20,7 +20,7 @@ #define _GNU_SOURCE 1 #endif -#include +#include #include #include #include diff --git a/plugins/auth/gssapi_client.c b/plugins/auth/gssapi_client.c index a05ea158..8b264c51 100644 --- a/plugins/auth/gssapi_client.c +++ b/plugins/auth/gssapi_client.c @@ -30,7 +30,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include #include -#include +#include #include #include "gssapi_errmsg.h" diff --git a/plugins/auth/gssapi_errmsg.c b/plugins/auth/gssapi_errmsg.c index 8ea4cab5..6731fbe1 100644 --- a/plugins/auth/gssapi_errmsg.c +++ b/plugins/auth/gssapi_errmsg.c @@ -38,8 +38,8 @@ void gssapi_errmsg(OM_uint32 major, OM_uint32 minor, char *buf, size_t size) char *p= buf; char *end= buf + size - 1; int types[] = {GSS_C_GSS_CODE,GSS_C_MECH_CODE}; - - for(int i= 0; i < 2;i++) + int i; + for(i= 0; i < 2;i++) { message_context= 0; status_code= types[i] == GSS_C_GSS_CODE?major:minor; diff --git a/plugins/auth/mariadb_cleartext.c b/plugins/auth/mariadb_cleartext.c index c0ff220a..abe41fbd 100644 --- a/plugins/auth/mariadb_cleartext.c +++ b/plugins/auth/mariadb_cleartext.c @@ -16,7 +16,7 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include +#include #include #include #include diff --git a/plugins/auth/my_auth.c b/plugins/auth/my_auth.c index 08505685..dbac8cc0 100644 --- a/plugins/auth/my_auth.c +++ b/plugins/auth/my_auth.c @@ -1,7 +1,7 @@ -#include -#include -#include -#include +#include +#include +#include +#include #include #include @@ -102,9 +102,9 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, size_t conn_attr_len= (mysql->options.extension) ? mysql->options.extension->connect_attrs_len : 0; - buff= my_alloca(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); + buff= malloc(USERNAME_LENGTH+1 + data_len+1 + NAME_LEN+1 + 2 + NAME_LEN+1 + 9 + conn_attr_len); - end= strmake(buff, mysql->user, USERNAME_LENGTH) + 1; + end= strncpy(buff, mysql->user, USERNAME_LENGTH) + strlen(buff) + 1; if (!data_len) *end++= 0; @@ -128,7 +128,7 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, memcpy(end, data, data_len); end+= data_len; } - end= strmake(end, mpvio->db ? mpvio->db : "", NAME_LEN) + 1; + end= strncpy(end, mpvio->db ? mpvio->db : "", NAME_LEN) + strlen(end) + 1; if (mysql->server_capabilities & CLIENT_PROTOCOL_41) { @@ -137,15 +137,15 @@ static int send_change_user_packet(MCPVIO_EXT *mpvio, } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) - end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + end= strncpy(end, mpvio->plugin->name, NAME_LEN) + strlen(end) + 1; end= ma_send_connect_attr(mysql, end); - res= simple_command(mysql, COM_CHANGE_USER, + res= ma_simple_command(mysql, COM_CHANGE_USER, buff, (ulong)(end-buff), 1, NULL); error: - my_afree(buff); + free(buff); return res; } @@ -161,7 +161,7 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, mysql->options.extension->connect_attrs_len : 0; /* see end= buff+32 below, fixed size of the packet is 32 bytes */ - buff= my_alloca(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); + buff= malloc(33 + USERNAME_LENGTH + data_len + NAME_LEN + NAME_LEN + conn_attr_len + 9); mysql->client_flag|= mysql->options.client_flag; mysql->client_flag|= CLIENT_CAPABILITIES; @@ -211,7 +211,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, int4store(buff,mysql->client_flag); int4store(buff+4, net->max_packet_size); buff[8]= (char) mysql->charset->nr; - bzero(buff+9, 32-9); + memset(buff + 9, 0, 32-9); + if (!(mysql->server_capabilities & CLIENT_MYSQL)) + { + mysql->client_flag |= MARIADB_CLIENT_SUPPORTED_FLAGS; + int4store(buff + 28, mysql->client_flag >> 32); + } end= buff+32; } else @@ -253,19 +258,14 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, } #endif /* HAVE_SSL */ - DBUG_PRINT("info",("Server version = '%s' capabilites: %lu status: %u client_flag: %lu", - mysql->server_version, mysql->server_capabilities, - mysql->server_status, mysql->client_flag)); - /* This needs to be changed as it's not useful with big packets */ if (mysql->user[0]) - strmake(end, mysql->user, USERNAME_LENGTH); + strncpy(end, mysql->user, USERNAME_LENGTH); else read_user_name(end); /* We have to handle different version of handshake here */ - DBUG_PRINT("info",("user: %s",end)); - end= strend(end) + 1; + end= strchr(end, '\0') + 1; if (data_len) { if (mysql->server_capabilities & CLIENT_SECURE_CONNECTION) @@ -287,12 +287,12 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, /* Add database if needed */ if (mpvio->db && (mysql->server_capabilities & CLIENT_CONNECT_WITH_DB)) { - end= strmake(end, mpvio->db, NAME_LEN) + 1; - mysql->db= my_strdup(mpvio->db, MYF(MY_WME)); + end= strncpy(end, mpvio->db, NAME_LEN) + strlen(end) + 1; + mysql->db= strdup(mpvio->db); } if (mysql->server_capabilities & CLIENT_PLUGIN_AUTH) - end= strmake(end, mpvio->plugin->name, NAME_LEN) + 1; + end= strncpy(end, mpvio->plugin->name, NAME_LEN) + strlen(end) + 1; end= ma_send_connect_attr(mysql, end); @@ -305,11 +305,11 @@ static int send_client_reply_packet(MCPVIO_EXT *mpvio, errno); goto error; } - my_afree(buff); + free(buff); return 0; error: - my_afree(buff); + free(buff); return 1; } @@ -419,7 +419,7 @@ static int client_mpvio_write_packet(struct st_plugin_vio *mpv, void mpvio_info(MARIADB_PVIO *pvio, MYSQL_PLUGIN_VIO_INFO *info) { - bzero(info, sizeof(*info)); + memset(info, 0, sizeof(*info)); switch (pvio->type) { case PVIO_TYPE_SOCKET: info->protocol= MYSQL_VIO_TCP; diff --git a/plugins/auth/old_password.c b/plugins/auth/old_password.c index 7836cec1..5eb5f630 100644 --- a/plugins/auth/old_password.c +++ b/plugins/auth/old_password.c @@ -16,12 +16,12 @@ or write to the Free Software Foundation, Inc., 51 Franklin St., Fifth Floor, Boston, MA 02110, USA *************************************************************************************/ -#include +#include #include #include #include #include -#include +#include /* function prototypes */ diff --git a/plugins/auth/sspi_client.c b/plugins/auth/sspi_client.c index 41461297..6308b31d 100644 --- a/plugins/auth/sspi_client.c +++ b/plugins/auth/sspi_client.c @@ -35,7 +35,7 @@ POSSIBILITY OF SUCH DAMAGE. #include #include -#include +#include #include "sspi_common.h" diff --git a/plugins/connection/aurora.c b/plugins/connection/aurora.c index 32fbfe31..9b2c0058 100644 --- a/plugins/connection/aurora.c +++ b/plugins/connection/aurora.c @@ -22,14 +22,14 @@ /* MariaDB Connection plugin for Aurora failover */ -#include -#include -#include +#include +#include +#include #include #include #include #include -#include +#include #ifndef WIN32 #include @@ -172,8 +172,8 @@ my_bool aurora_parse_url(const char *url, AURORA *aurora) if (!url || url[0] == 0) return 1; - bzero(aurora->instance, (AURORA_MAX_INSTANCES + 1) * sizeof(char *)); - bzero(&aurora->port, (AURORA_MAX_INSTANCES + 1) * sizeof(int)); + memset(aurora->instance, 0, (AURORA_MAX_INSTANCES + 1) * sizeof(char *)); + memset(&aurora->port, 0, (AURORA_MAX_INSTANCES + 1) * sizeof(int)); if (aurora->url) free(aurora->url); diff --git a/plugins/connection/replication.c b/plugins/connection/replication.c index 6bb74cef..e0369527 100644 --- a/plugins/connection/replication.c +++ b/plugins/connection/replication.c @@ -22,13 +22,13 @@ /* MariaDB Connection plugin for load balancing */ -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include #ifndef WIN32 #include @@ -108,8 +108,8 @@ my_bool repl_parse_url(const char *url, REPL_DATA *data) if (!url || url[0] == 0) return 1; - bzero(slaves, 64 * sizeof(char *)); - bzero(&port, 64 * sizeof(int)); + memset(slaves, 0, 64 * sizeof(char *)); + memset(&port, 0, 64 * sizeof(int)); memset(data->host, 0, 2 * sizeof(char *)); memset(data->port, 0, 2 * sizeof(int)); diff --git a/plugins/io/remote_io.c b/plugins/io/remote_io.c index 411aa3c5..4604c12e 100644 --- a/plugins/io/remote_io.c +++ b/plugins/io/remote_io.c @@ -43,8 +43,8 @@ smb:// */ -#include -#include +#include +#include #include #include #include diff --git a/plugins/pvio/pvio_npipe.c b/plugins/pvio/pvio_npipe.c index 623f6ba9..af849532 100644 --- a/plugins/pvio/pvio_npipe.c +++ b/plugins/pvio/pvio_npipe.c @@ -22,13 +22,13 @@ #ifdef _WIN32 -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include /* Function prototypes */ my_bool pvio_npipe_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); @@ -223,7 +223,7 @@ my_bool pvio_npipe_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); return 1; } - bzero(cpipe, sizeof(struct st_pvio_npipe)); + memset(cpipe, 0, sizeof(struct st_pvio_npipe)); pvio->data= (void *)cpipe; cpipe->pipe= INVALID_HANDLE_VALUE; pvio->mysql= cinfo->mysql; diff --git a/plugins/pvio/pvio_shmem.c b/plugins/pvio/pvio_shmem.c index 218c88f2..a8546d87 100644 --- a/plugins/pvio/pvio_shmem.c +++ b/plugins/pvio/pvio_shmem.c @@ -21,13 +21,13 @@ #ifdef _WIN32 -#include -#include -#include +#include +#include +#include #include #include #include -#include +#include #define SHM_DEFAULT_NAME "MYSQL" #define PVIO_SHM_BUFFER_SIZE 16000 + 4 diff --git a/plugins/pvio/pvio_socket.c b/plugins/pvio/pvio_socket.c index 841acfcb..7eac1af3 100644 --- a/plugins/pvio/pvio_socket.c +++ b/plugins/pvio/pvio_socket.c @@ -24,16 +24,17 @@ default and compiled into Connector/C. */ -#include -#include -#include +#include +#include +#include #include #include -#include -#include +#ifdef HAVE_NONBLOCK +#include +#include +#endif #include #include -#include #ifndef _WIN32 #ifdef HAVE_SYS_UN_H #include @@ -64,9 +65,11 @@ my_bool pvio_socket_set_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type, int timeout); int pvio_socket_get_timeout(MARIADB_PVIO *pvio, enum enum_pvio_timeout type); size_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); +#ifdef HAVE_NONBLOCK size_t pvio_socket_async_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length); -size_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); size_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); +#endif +size_t pvio_socket_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t length); int pvio_socket_wait_io_or_timeout(MARIADB_PVIO *pvio, my_bool is_read, int timeout); my_bool pvio_socket_blocking(MARIADB_PVIO *pvio, my_bool value, my_bool *old_value); my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo); @@ -88,9 +91,17 @@ struct st_ma_pvio_methods pvio_socket_methods= { pvio_socket_set_timeout, pvio_socket_get_timeout, pvio_socket_read, +#ifdef HAVE_NONBLOCK pvio_socket_async_read, +#else + NULL, +#endif pvio_socket_write, +#ifdef HAVE_NONBLOCK pvio_socket_async_write, +#else + NULL, +#endif pvio_socket_wait_io_or_timeout, pvio_socket_blocking, pvio_socket_connect, @@ -275,6 +286,7 @@ size_t pvio_socket_read(MARIADB_PVIO *pvio, uchar *buffer, size_t length) } /* }}} */ +#ifdef HAVE_NONBLOCK /* {{{ pvio_socket_async_read */ /* read from socket @@ -372,7 +384,7 @@ size_t pvio_socket_async_write(MARIADB_PVIO *pvio, const uchar *buffer, size_t l return r; } /* }}} */ - +#endif /* {{{ pvio_socket_write */ /* @@ -666,6 +678,7 @@ static int pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, const struct sockaddr *name, uint namelen) { +#ifdef HAVE_NONBLOCK MYSQL *mysql= pvio->mysql; if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->active) @@ -676,6 +689,7 @@ pvio_socket_connect_sync_or_async(MARIADB_PVIO *pvio, pvio_socket_blocking(pvio, 0, 0); return my_connect_async(pvio, name, namelen, pvio->timeout[PVIO_CONNECT_TIMEOUT]); } +#endif return pvio_socket_internal_connect(pvio, name, namelen); } @@ -687,8 +701,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) if (!pvio || !cinfo) return 1; - if (!(csock= (struct st_pvio_socket *)my_malloc(sizeof(struct st_pvio_socket), - MYF(MY_WME | MY_ZEROFILL)))) + if (!(csock= (struct st_pvio_socket *)calloc(1, sizeof(struct st_pvio_socket)))) { PVIO_SET_ERROR(cinfo->mysql, CR_OUT_OF_MEMORY, unknown_sqlstate, 0, ""); return 1; @@ -708,9 +721,9 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) PVIO_SET_ERROR(cinfo->mysql, CR_SOCKET_CREATE_ERROR, unknown_sqlstate, 0, errno); goto error; } - bzero((char*) &UNIXaddr,sizeof(UNIXaddr)); + memset((char*) &UNIXaddr, 0, sizeof(UNIXaddr)); UNIXaddr.sun_family = AF_UNIX; - strmov(UNIXaddr.sun_path, cinfo->unix_socket); + strcpy(UNIXaddr.sun_path, cinfo->unix_socket); if (pvio_socket_connect_sync_or_async(pvio, (struct sockaddr *) &UNIXaddr, sizeof(UNIXaddr))) { @@ -733,11 +746,11 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) int gai_rc; int rc= 0; - bzero(&server_port, NI_MAXSERV); - my_snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); + memset(&server_port, 0, NI_MAXSERV); + snprintf(server_port, NI_MAXSERV, "%d", cinfo->port); /* set hints for getaddrinfo */ - bzero(&hints, sizeof(hints)); + memset(&hints, 0, sizeof(hints)); hints.ai_protocol= IPPROTO_TCP; /* TCP connections only */ hints.ai_family= AF_UNSPEC; /* includes: IPv4, IPv6 or hostname */ hints.ai_socktype= SOCK_STREAM; @@ -793,10 +806,12 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) rc= pvio_socket_connect_sync_or_async(pvio, save_res->ai_addr, (uint)save_res->ai_addrlen); if (!rc) { +#ifdef HAVE_NONBLOCK MYSQL *mysql= pvio->mysql; if (mysql->options.extension && mysql->options.extension->async_context && mysql->options.extension->async_context->active) break; +#endif if (pvio_socket_blocking(pvio, 0, 0) == SOCKET_ERROR) { closesocket(csock->socket); @@ -838,7 +853,7 @@ my_bool pvio_socket_connect(MARIADB_PVIO *pvio, MA_PVIO_CINFO *cinfo) error: if (pvio->data) { - my_free((gptr)pvio->data); + free((gptr)pvio->data); pvio->data= NULL; } return 1; @@ -862,7 +877,7 @@ my_bool pvio_socket_close(MARIADB_PVIO *pvio) r= closesocket(csock->socket); csock->socket= -1; } - my_free((gptr)pvio->data); + free((gptr)pvio->data); pvio->data= NULL; } return r; diff --git a/plugins/trace/trace_example.c b/plugins/trace/trace_example.c index b53428e4..4993fbb2 100644 --- a/plugins/trace/trace_example.c +++ b/plugins/trace/trace_example.c @@ -20,7 +20,7 @@ #define _GNU_SOURCE 1 #endif -#include +#include #include #include #include diff --git a/unittest/libmariadb/CMakeLists.txt b/unittest/libmariadb/CMakeLists.txt index 92334361..c7f4c0c5 100644 --- a/unittest/libmariadb/CMakeLists.txt +++ b/unittest/libmariadb/CMakeLists.txt @@ -21,51 +21,61 @@ INCLUDE_DIRECTORIES(${CMAKE_SOURCE_DIR}/include ${CMAKE_SOURCE_DIR}/unittest/mytap) ADD_DEFINITIONS(-DLIBMARIADB) -SET(API_TESTS "async" "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" - "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "dyncol") +SET(API_TESTS "basic-t" "fetch" "charset" "logs" "cursor" "errors" "view" "ps" "ps_bugs" + "sp" "result" "connection" "misc" "ps_new" "sqlite3" "thread" "features-10_2" ) +IF(WITH_DYNCOL) + SET(API_TESTS ${API_TESTS} "dyncol") +ENDIF() + +IF(WITH_NONBLCK) + SET(API_TESTS ${API_TESTS} "async") +ENDIF() #exclude following tests from ctests, since we need to run them maually with different credentials SET(MANUAL_TESTS "t_aurora") # Get finger print from server certificate -IF(WITH_SSL AND OPENSSL_FOUND) - - #create certificates - IF(EXISTS "${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem") - MESSAGE(STATUS "certificates already exist") - ELSE() - MESSAGE(STATUS "creating certificates") - IF(WIN32) - EXECUTE_PROCESS(COMMAND create_certs.bat - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs - OUTPUT_FILE x.1 ERROR_FILE x.2) +IF(WITH_SSL) + IF(OPENSSL_FOUND) + #create certificates + IF(EXISTS "${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs/server-cert.pem") + MESSAGE(STATUS "certificates already exist") ELSE() - EXECUTE_PROCESS(COMMAND ./create_certs.sh - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) + MESSAGE(STATUS "creating certificates") + IF(WIN32) + EXECUTE_PROCESS(COMMAND create_certs.bat + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs + OUTPUT_FILE x.1 ERROR_FILE x.2) + ELSE() + EXECUTE_PROCESS(COMMAND ./create_certs.sh + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs) + ENDIF() ENDIF() + + EXECUTE_PROCESS(COMMAND openssl x509 -in server-cert.pem -sha1 -fingerprint -noout + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs + OUTPUT_VARIABLE FINGER_PRINT) + STRING(REPLACE "SHA1 Fingerprint=" "" FINGER_PRINT "${FINGER_PRINT}") + STRING(REPLACE "\n" "" FINGER_PRINT "${FINGER_PRINT}") + STRING(REPLACE ":" "" SSL_CERT_FINGER_PRINT "${FINGER_PRINT}") + ENDIF() - - EXECUTE_PROCESS(COMMAND openssl x509 -in server-cert.pem -sha1 -fingerprint -noout - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/unittest/libmariadb/certs - OUTPUT_VARIABLE FINGER_PRINT) - STRING(REPLACE "SHA1 Fingerprint=" "" FINGER_PRINT "${FINGER_PRINT}") - STRING(REPLACE "\n" "" FINGER_PRINT "${FINGER_PRINT}") - STRING(REPLACE ":" "" SSL_CERT_FINGER_PRINT "${FINGER_PRINT}") - -ENDIF() CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/unittest/libmariadb/ssl.c.in ${CMAKE_SOURCE_DIR}/unittest/libmariadb/ssl.c) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/unittest/libmariadb/fingerprint.list.in ${CMAKE_SOURCE_DIR}/unittest/libmariadb/fingerprint.list) -SET(API_TESTS ${API_TESTS} "ssl") + SET(API_TESTS ${API_TESTS} "ssl") +ENDIF() + +ADD_LIBRARY(ma_getopt ma_getopt.c) FOREACH(API_TEST ${API_TESTS}) - ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) - TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) + TARGET_LINK_LIBRARIES(${API_TEST} mytap ma_getopt libmariadb) ADD_TEST(${API_TEST} ${EXECUTABLE_OUTPUT_PATH}/${API_TEST}) SET_TESTS_PROPERTIES(${API_TEST} PROPERTIES TIMEOUT 120) ENDFOREACH(API_TEST) FOREACH(API_TEST ${MANUAL_TESTS}) - ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c ${CMAKE_SOURCE_DIR}/libmariadb/getopt.c) - TARGET_LINK_LIBRARIES(${API_TEST} mytap mariadbclient) + ADD_EXECUTABLE(${API_TEST} ${API_TEST}.c) + TARGET_LINK_LIBRARIES(${API_TEST} mytap ma_getopt libmariadb) ENDFOREACH() diff --git a/unittest/libmariadb/basic-t.c b/unittest/libmariadb/basic-t.c index ff4fc547..9a385ffe 100644 --- a/unittest/libmariadb/basic-t.c +++ b/unittest/libmariadb/basic-t.c @@ -705,6 +705,9 @@ static int test_reconnect_maxpackage(MYSQL *my) SKIP_CONNECTION_HANDLER; mysql= mysql_init(NULL); + SKIP_CONNECTION_HANDLER; + mysql= mysql_init(NULL); + FAIL_IF(!mysql_real_connect(mysql, hostname, username, password, schema, port, socketname, CLIENT_MULTI_STATEMENTS | CLIENT_MULTI_RESULTS), mysql_error(mysql)); diff --git a/unittest/libmariadb/certs/create_certs.sh b/unittest/libmariadb/certs/create_certs.sh deleted file mode 100755 index 47ea98e8..00000000 --- a/unittest/libmariadb/certs/create_certs.sh +++ /dev/null @@ -1,15 +0,0 @@ -openssl req -x509 -newkey rsa:1024 \ --keyout server-key-enc.pem -out server-cert.pem \ --subj '/DC=com/DC=example/CN=server' -passout pass:qwerty - -openssl rsa -in server-key-enc.pem -out server-key.pem \ --passin pass:qwerty -passout pass: - -openssl req -x509 -newkey rsa:1024 \ --keyout client-key-enc.pem -out client-cert.pem \ --subj '/DC=com/DC=example/CN=client' -passout pass:qwerty - -openssl rsa -in client-key-enc.pem -out client-key.pem \ --passin pass:qwerty -passout pass: - -cat server-cert.pem client-cert.pem > ca-cert.pem diff --git a/unittest/libmariadb/certs/dummy.pem b/unittest/libmariadb/certs/dummy.pem deleted file mode 100644 index 1fc34aa1..00000000 --- a/unittest/libmariadb/certs/dummy.pem +++ /dev/null @@ -1,21 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIDXTCCAkWgAwIBAgIJAL4tmDe5DR0sMA0GCSqGSIb3DQEBBQUAMEUxCzAJBgNV -BAYTAkFVMRMwEQYDVQQIDApTb21lLVN0YXRlMSEwHwYDVQQKDBhJbnRlcm5ldCBX -aWRnaXRzIFB0eSBMdGQwHhcNMTUwMzEwMjAyMDI4WhcNMTYwMzA5MjAyMDI4WjBF -MQswCQYDVQQGEwJBVTETMBEGA1UECAwKU29tZS1TdGF0ZTEhMB8GA1UECgwYSW50 -ZXJuZXQgV2lkZ2l0cyBQdHkgTHRkMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIB -CgKCAQEApV9UfWmeXYdexOEn+adOm6FdJUhKMrjTiycwETmDXRVpY4wl+LNGsANp -ohSRovDjFiFO+Ti0bUhpf552oE23wYw+P6f0UY0KkV/PgSght1Ezfffe0BaEjI0X -tA5zdNmxzL3OUWJVcg+I4UE3rbYFHUgymu72P0IRXjmJv1tToNxUxbTBLxU/KAlq -Uy49upB3q3/IPOdP9UzAZDHnRv1gjwUzNgumfcc5d5lSsGpwLDYCQs4I539fCkBD -MfU2BN/qpmPhb/nm5ZUdFUFYGN+XxVPVpJLmeWVRwMSQR2LN5CkqnK9e2Q/QaJ53 -G3AAng+fpfEGPpjQdFWuhFjQozOD0wIDAQABo1AwTjAdBgNVHQ4EFgQUyg6WfzL2 -JhhjKm1Ex28s4Y3vNGQwHwYDVR0jBBgwFoAUyg6WfzL2JhhjKm1Ex28s4Y3vNGQw -DAYDVR0TBAUwAwEB/zANBgkqhkiG9w0BAQUFAAOCAQEAIrj/bHiRf8UJIfv8hyZ1 -dXEqvqjxUMXtJ/QhhCQs42p9pHv+mPTkeXh0K18Oj6k/Vp4J1/0mp/kqiQUHt9yO -/3pJPc+JordTjlVLgb95cfBIs4yiPT9biGaA7j0Dh9EcDBOCT4v56Z9BLqGMfBUK -YeZ7ZecWmZCZOYk/X+CPB30GxLy5Wm9D50qEUXXBPZ9Bie6FYaQYOFlQlqxYuLX0 -NVqLDvX6zz6FMsgqoyDJ1BMuMsjPDUUUrwGY+R3YqiqkPRbDkr8zvzpqiYvjTZi0 -LTJO7GRfwzfhkeEPL/hl/TYdB1GZHixMrAKx1HGKHAa0sgWTWxQGYhfclH8DI7AR -Tw== ------END CERTIFICATE----- diff --git a/unittest/libmariadb/charset.c b/unittest/libmariadb/charset.c index 0226bc18..8a11f09e 100644 --- a/unittest/libmariadb/charset.c +++ b/unittest/libmariadb/charset.c @@ -658,12 +658,11 @@ static int test_bug_54100(MYSQL *mysql) /* We need this internal function for the test */ -CHARSET_INFO * mysql_find_charset_name(const char *name); static int test_utf16_utf32_noboms(MYSQL *mysql) { char *csname[]= {"utf16", "utf16le", "utf32", "utf8"}; - CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; + MARIADB_CHARSET_INFO *csinfo[sizeof(csname)/sizeof(char*)]; const int UTF8= sizeof(csname)/sizeof(char*) - 1; @@ -713,6 +712,7 @@ static int test_utf16_utf32_noboms(MYSQL *mysql) rc= mariadb_convert_string(in_string[UTF8], &in_len, csinfo[UTF8], buffer, &out_len, csinfo[i], &error); FAIL_IF(rc==-1, "Conversion failed"); + diag("rc=%d oct_len: %d", rc, in_oct_len[i]); FAIL_IF(rc != in_oct_len[i], "Incorrect number of written bytes"); if (memcmp(buffer, in_string[i], rc) != 0) diff --git a/unittest/libmariadb/connection.c b/unittest/libmariadb/connection.c index fe1f220b..a4e36341 100644 --- a/unittest/libmariadb/connection.c +++ b/unittest/libmariadb/connection.c @@ -37,16 +37,20 @@ static int test_conc66(MYSQL *my) if (!(fp= fopen("./my.cnf", "w"))) return FAIL; + fprintf(fp, "[notmygroup]\n"); + fprintf(fp, "user=foo\n"); fprintf(fp, "[conc-66]\n"); fprintf(fp, "user=conc66\n"); + fprintf(fp, "port=3306\n"); + fprintf(fp, "enable-local-infile\n"); fprintf(fp, "password='test\\\";#test'\n"); fclose(fp); rc= mysql_options(mysql, MYSQL_READ_DEFAULT_GROUP, "conc-66"); check_mysql_rc(rc, mysql); - rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); - check_mysql_rc(rc, mysql); +// rc= mysql_options(mysql, MYSQL_READ_DEFAULT_FILE, "./my.cnf"); +// check_mysql_rc(rc, mysql); sprintf(query, "GRANT ALL ON %s.* TO 'conc66'@'%s' IDENTIFIED BY 'test\";#test'", schema, hostname); rc= mysql_query(my, query); diff --git a/unittest/libmariadb/dyncol.c b/unittest/libmariadb/dyncol.c index 6d39fea3..20e6d0c4 100644 --- a/unittest/libmariadb/dyncol.c +++ b/unittest/libmariadb/dyncol.c @@ -16,7 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc., */ #include "my_test.h" -#include "ma_dyncol.h" +#include "mariadb_dyncol.h" static int create_dyncol_named(MYSQL *mysql) { @@ -39,7 +39,7 @@ static int create_dyncol_named(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; diag("%s", keys3[i].str); } @@ -132,7 +132,7 @@ static int create_dyncol_num(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; } FAIL_IF(mariadb_dyncol_create_many_num(&dyncol, column_count, keys1, vals, 1) <0, "Error (keys1)"); @@ -176,7 +176,7 @@ static int mdev_x1(MYSQL *mysql) vals[i].type= DYN_COL_STRING; vals[i].x.string.value.str= strval[i]; vals[i].x.string.value.length= strlen(strval[i]); - vals[i].x.string.charset= (CHARSET_INFO *)mysql->charset; + vals[i].x.string.charset= (MARIADB_CHARSET_INFO *)mysql->charset; } mariadb_dyncol_init(&dynstr); diff --git a/unittest/libmariadb/features-10_2.c b/unittest/libmariadb/features-10_2.c new file mode 100644 index 00000000..39007346 --- /dev/null +++ b/unittest/libmariadb/features-10_2.c @@ -0,0 +1,171 @@ +/* +*/ + +#include "my_test.h" + +my_bool have_com_multi= 1; + +static int com_multi_1(MYSQL *mysql) +{ + int rc; + MYSQL_RES *res; + enum mariadb_com_multi status; + + /* TEST a simple query before COM_MULTI */ + + rc= mysql_query(mysql, "select 1"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "1 simple query no result"); + + mysql_free_result(res); + + /* TEST COM_MULTI */ + + status= MARIADB_COM_MULTI_BEGIN; + if (mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status)) + { + diag("COM_MULT not supported"); + have_com_multi= 0; + return SKIP; + } + + rc= mysql_query(mysql, "select 1"); + + rc= mysql_query(mysql, "select 2"); + + status= MARIADB_COM_MULTI_END; + rc= mysql_options(mysql, MARIADB_OPT_COM_MULTI, &status); + check_mysql_rc(rc, mysql); + /* 1 SELECT result */ + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "1 of 2 simple query in batch no result"); + FAIL_UNLESS(res->field_count == 1 && res->row_count == 1 && + strcmp(res->fields[0].name, "1") == 0, + "1 of 2 simple query in batch wrong result"); + mysql_free_result(res); + /* 2 SELECT result */ + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == 0, "no second result in the batch"); + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "2 of 2 simple query in batch no result"); + FAIL_UNLESS(res->field_count == 1 && res->row_count == 1 && + strcmp(res->fields[0].name, "2") == 0, + "1 of 2 simple query in batch wrong result"); + mysql_free_result(res); + rc= mysql_next_result(mysql); + FAIL_UNLESS(rc == -1, "more then 2 results"); + + /* TEST a simple query after COM_MULTI */ + + rc= mysql_query(mysql, "select 1"); + check_mysql_rc(rc, mysql); + res= mysql_store_result(mysql); + FAIL_UNLESS(res, "2 simple query no result"); + mysql_free_result(res); + + /* question: how will result sets look like ? */ + diag("error: %s", mysql_error(mysql)); + + return OK; +} + +static int com_multi_ps1(MYSQL *mysql) +{ + MYSQL_STMT *stmt= mysql_stmt_init(mysql); + int rc; + + if (!have_com_multi) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + + rc= mysql_stmt_prepare(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1); + check_stmt_rc(rc, stmt); + + rc= mysql_stmt_execute(stmt); + check_stmt_rc(rc, stmt); + diag("affected_rows: %d", mysql_stmt_affected_rows(stmt)); + diag("stmt_id: %d", stmt->stmt_id); + mysql_stmt_close(stmt); + + stmt= mysql_stmt_init(mysql); + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 values (2, 'execute_direct')", -1); + check_stmt_rc(rc, stmt); + + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "expected affected_rows= 1"); + FAIL_IF(stmt->stmt_id < 1, "expected statement id > 0"); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + + return OK; +} + +static int com_multi_ps2(MYSQL *mysql) +{ + MYSQL_STMT *stmt; + MYSQL_BIND bind[3]; + int intval= 3, rc; + int i; + char *varval= "com_multi_ps2"; + + + if (!have_com_multi) + return SKIP; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + rc= mysql_query(mysql, "CREATE TABLE t1 (a int, b varchar(20))"); + + memset(&bind, 0, sizeof(MYSQL_BIND) * 3); + bind[0].buffer_type= MYSQL_TYPE_SHORT; + bind[0].buffer= &intval; + bind[1].buffer_type= MYSQL_TYPE_STRING; + bind[1].buffer= varval; + bind[1].buffer_length= strlen(varval); + bind[2].buffer_type= MAX_NO_FIELD_TYPES; + + for (i=0; i < 2; i++) + { + stmt= mysql_stmt_init(mysql); + rc= mysql_stmt_bind_param(stmt, bind); + check_stmt_rc(rc, stmt); + + rc= mariadb_stmt_execute_direct(stmt, "INSERT INTO t1 VALUES (1,'foo')", -1); + check_stmt_rc(rc, stmt); + FAIL_IF(mysql_stmt_affected_rows(stmt) != 1, "expected affected_rows= 1"); + FAIL_IF(stmt->stmt_id < 1, "expected statement id > 0"); + + rc= mysql_stmt_close(stmt); + check_mysql_rc(rc, mysql); + } + + return OK; +} + +struct my_tests_st my_tests[] = { + {"com_multi_1", com_multi_1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"com_multi_ps1", com_multi_ps1, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {"com_multi_ps2", com_multi_ps2, TEST_CONNECTION_NEW, 0, NULL, NULL}, + {NULL, NULL, 0, 0, NULL, NULL} +}; + + +int main(int argc, char **argv) +{ + + mysql_library_init(0,0,NULL); + + if (argc > 1) + get_options(argc, argv); + + get_envvars(); + + run_tests(my_tests); + + mysql_server_end(); + return(exit_status()); +} diff --git a/libmariadb/getopt.c b/unittest/libmariadb/getopt.c similarity index 99% rename from libmariadb/getopt.c rename to unittest/libmariadb/getopt.c index cbec6678..411f4ba7 100644 --- a/libmariadb/getopt.c +++ b/unittest/libmariadb/getopt.c @@ -46,8 +46,8 @@ Cambridge, MA 02139, USA. */ #endif #endif -#include /* Changes for mysys */ -#include +#include /* Changes for mysys */ +#include /* Comment out all this code if we are using the GNU C Library, and are not actually compiling the library itself. This code is part of the GNU C @@ -82,7 +82,7 @@ Cambridge, MA 02139, USA. */ GNU application programs can use a third alternative mode in which they can distinguish the relative order of options and other arguments. */ -#include "getopt.h" +#include "ma_getopt.h" /* For communication from `getopt' to the caller. When `getopt' finds an option that takes an argument, @@ -658,12 +658,8 @@ _getopt_internal (int argc, char *const *argv, const char *optstring, const stru } } -#ifdef __EMX__ -int getopt (int argc, char **argv, __const__ char *optstring) -#else int getopt (int argc, char *const *argv, const char *optstring) -#endif { return _getopt_internal (argc, argv, optstring, (const struct option *) 0, diff --git a/unittest/libmariadb/ma_getopt.c b/unittest/libmariadb/ma_getopt.c new file mode 100644 index 00000000..411f4ba7 --- /dev/null +++ b/unittest/libmariadb/ma_getopt.c @@ -0,0 +1,742 @@ +/* Getopt for GNU. + NOTE: getopt is now part of the C library, so if you don't know what + "Keep this file name-space clean" means, talk to roland@gnu.ai.mit.edu + before changing it! + + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94 + Free Software Foundation, Inc. + +Changes by monty: +- Added include of string.h when nessessary. +- Removed two warnings from gcc. + +This file is part of the GNU C Library. Its master source is NOT part of +the C library, however. The master source lives in /gd/gnu/lib. + +The GNU C Library is free software; you can redistribute it and/or +modify it under the terms of the GNU Library General Public License as +published by the Free Software Foundation; either version 2 of the +License, or (at your option) any later version. + +The GNU C Library is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +Library General Public License for more details. + +You should have received a copy of the GNU Library General Public +License along with the GNU C Library; see the file COPYING.LIB. If +not, write to the Free Software Foundation, Inc., 675 Mass Ave, +Cambridge, MA 02139, USA. */ + +/* This tells Alpha OSF/1 not to define a getopt prototype in . + Ditto for AIX 3.2 and . */ +#ifndef _NO_PROTO +#define _NO_PROTO +#endif + +#ifdef HAVE_CONFIG_H +#include +#endif + +#if (!defined (__STDC__) || !__STDC__) && !defined(MSDOS) && !defined(OS2) +/* This is a separate conditional since some stdc systems + reject `defined (const)'. */ +#ifndef const +#define const +#endif +#endif + +#include /* Changes for mysys */ +#include + +/* Comment out all this code if we are using the GNU C Library, and are not + actually compiling the library itself. This code is part of the GNU C + Library, but also included in many other GNU distributions. Compiling + and linking in this code is a waste when using the GNU C library + (especially if it is a shared library). Rather than having every GNU + program understand `configure --with-gnu-libc' and omit the object files, + it is simpler to just do this in the source for each such file. */ + +#if defined (_LIBC) || !defined (__GNU_LIBRARY__) + + +/* This needs to come after some library #include + to get __GNU_LIBRARY__ defined. */ +#ifdef __GNU_LIBRARY__ +/* Don't include stdlib.h for non-GNU C libraries because some of them + contain conflicting prototypes for getopt. */ +#include +#endif /* GNU C library. */ + +/* This version of `getopt' appears to the caller like standard Unix `getopt' + but it behaves differently for the user, since it allows the user + to intersperse the options with the other arguments. + + As `getopt' works, it permutes the elements of ARGV so that, + when it is done, all the options precede everything else. Thus + all application programs are extended to handle flexible argument order. + + Setting the environment variable POSIXLY_CORRECT disables permutation. + Then the behavior is completely standard. + + GNU application programs can use a third alternative mode in which + they can distinguish the relative order of options and other arguments. */ + +#include "ma_getopt.h" + +/* For communication from `getopt' to the caller. + When `getopt' finds an option that takes an argument, + the argument value is returned here. + Also, when `ordering' is RETURN_IN_ORDER, + each non-option ARGV-element is returned here. */ + +char *optarg = NULL; + +/* Index in ARGV of the next element to be scanned. + This is used for communication to and from the caller + and for communication between successive calls to `getopt'. + + On entry to `getopt', zero means this is the first call; initialize. + + When `getopt' returns EOF, this is the index of the first of the + non-option elements that the caller should itself scan. + + Otherwise, `optind' communicates from one call to the next + how much of ARGV has been scanned so far. */ + +/* XXX 1003.2 says this must be 1 before any call. */ +int optind = 1; + +/* The next char to be scanned in the option-element + in which the last option character we returned was found. + This allows us to pick up the scan where we left off. + + If this is zero, or a null string, it means resume the scan + by advancing to the next ARGV-element. */ + +static char *nextchar; + +/* Callers store zero here to inhibit the error message + for unrecognized options. */ + +int opterr = 1; + +/* Set to an option character which was unrecognized. + This must be initialized on some systems to avoid linking in the + system's own getopt implementation. */ + +int optopt = '?'; + +/* Describe how to deal with options that follow non-option ARGV-elements. + + If the caller did not specify anything, + the default is REQUIRE_ORDER if the environment variable + POSIXLY_CORRECT is defined, PERMUTE otherwise. + + REQUIRE_ORDER means don't recognize them as options; + stop option processing when the first non-option is seen. + This is what Unix does. + This mode of operation is selected by either setting the environment + variable POSIXLY_CORRECT, or using `+' as the first character + of the list of option characters. + + PERMUTE is the default. We permute the contents of ARGV as we scan, + so that eventually all the non-options are at the end. This allows options + to be given in any order, even with programs that were not written to + expect this. + + RETURN_IN_ORDER is an option available to programs that were written + to expect options and other ARGV-elements in any order and that care about + the ordering of the two. We describe each non-option ARGV-element + as if it were the argument of an option with character code 1. + Using `-' as the first character of the list of option characters + selects this mode of operation. + + The special argument `--' forces an end of option-scanning regardless + of the value of `ordering'. In the case of RETURN_IN_ORDER, only + `--' can cause `getopt' to return EOF with `optind' != ARGC. */ + +static enum +{ + REQUIRE_ORDER, PERMUTE, RETURN_IN_ORDER +} ordering; + +/* Value of POSIXLY_CORRECT environment variable. */ +static char *posixly_correct; + +#ifdef __GNU_LIBRARY__ +/* We want to avoid inclusion of string.h with non-GNU libraries + because there are many ways it can cause trouble. + On some systems, it contains special magic macros that don't work + in GCC. */ +#include +#define my_index strchr +#else + +/* Avoid depending on library functions or files + whose names are inconsistent. */ + +static char * +my_index (const char *str, int chr) +{ + while (*str) + { + if (*str == chr) + return (char *) str; + str++; + } + return 0; +} + +/* If using GCC, we can safely declare strlen this way. + If not using GCC, it is ok not to declare it. */ +#ifdef __GNUC__ +/* Note that Motorola Delta 68k R3V7 comes with GCC but not stddef.h. + That was relevant to code that was here before. */ +#if !defined (__STDC__) || !__STDC__ +/* gcc with -traditional declares the built-in strlen to return int, + and has done so at least since version 2.4.5. -- rms. */ +extern int strlen (const char *); +#endif /* not __STDC__ */ +#endif /* __GNUC__ */ + +#endif /* not __GNU_LIBRARY__ */ + +/* Handle permutation of arguments. */ + +/* Describe the part of ARGV that contains non-options that have + been skipped. `first_nonopt' is the index in ARGV of the first of them; + `last_nonopt' is the index after the last of them. */ + +static int first_nonopt; +static int last_nonopt; + +/* Exchange two adjacent subsequences of ARGV. + One subsequence is elements [first_nonopt,last_nonopt) + which contains all the non-options that have been skipped so far. + The other is elements [last_nonopt,optind), which contains all + the options processed since those non-options were skipped. + + `first_nonopt' and `last_nonopt' are relocated so that they describe + the new indices of the non-options in ARGV after they are moved. */ + +static void +exchange (char **argv) +{ + int bottom = first_nonopt; + int middle = last_nonopt; + int top = optind; + char *tem; + + /* Exchange the shorter segment with the far end of the longer segment. + That puts the shorter segment into the right place. + It leaves the longer segment in the right place overall, + but it consists of two parts that need to be swapped next. */ + + while (top > middle && middle > bottom) + { + if (top - middle > middle - bottom) + { + /* Bottom segment is the short one. */ + int len = middle - bottom; + register int i; + + /* Swap it with the top part of the top segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[top - (middle - bottom) + i]; + argv[top - (middle - bottom) + i] = tem; + } + /* Exclude the moved bottom segment from further swapping. */ + top -= len; + } + else + { + /* Top segment is the short one. */ + int len = top - middle; + register int i; + + /* Swap it with the bottom part of the bottom segment. */ + for (i = 0; i < len; i++) + { + tem = argv[bottom + i]; + argv[bottom + i] = argv[middle + i]; + argv[middle + i] = tem; + } + /* Exclude the moved top segment from further swapping. */ + bottom += len; + } + } + + /* Update records for the slots the non-options now occupy. */ + + first_nonopt += (optind - last_nonopt); + last_nonopt = optind; +} + +/* Initialize the internal data when the first call is made. */ + +static const char * +_getopt_initialize (const char *optstring) +{ + /* Start processing options with ARGV-element 1 (since ARGV-element 0 + is the program name); the sequence of previously skipped + non-option ARGV-elements is empty. */ + + first_nonopt = last_nonopt = optind = 1; + + nextchar = NULL; + + posixly_correct = getenv ("POSIXLY_CORRECT"); + + /* Determine how to handle the ordering of options and nonoptions. */ + + if (optstring[0] == '-') + { + ordering = RETURN_IN_ORDER; + ++optstring; + } + else if (optstring[0] == '+') + { + ordering = REQUIRE_ORDER; + ++optstring; + } + else if (posixly_correct != NULL) + ordering = REQUIRE_ORDER; + else + ordering = PERMUTE; + + return optstring; +} + +/* Scan elements of ARGV (whose length is ARGC) for option characters + given in OPTSTRING. + + If an element of ARGV starts with '-', and is not exactly "-" or "--", + then it is an option element. The characters of this element + (aside from the initial '-') are option characters. If `getopt' + is called repeatedly, it returns successively each of the option characters + from each of the option elements. + + If `getopt' finds another option character, it returns that character, + updating `optind' and `nextchar' so that the next call to `getopt' can + resume the scan with the following option character or ARGV-element. + + If there are no more option characters, `getopt' returns `EOF'. + Then `optind' is the index in ARGV of the first ARGV-element + that is not an option. (The ARGV-elements have been permuted + so that those that are not options now come last.) + + OPTSTRING is a string containing the legitimate option characters. + If an option character is seen that is not listed in OPTSTRING, + return '?' after printing an error message. If you set `opterr' to + zero, the error message is suppressed but we still return '?'. + + If a char in OPTSTRING is followed by a colon, that means it wants an arg, + so the following text in the same ARGV-element, or the text of the following + ARGV-element, is returned in `optarg'. Two colons mean an option that + wants an optional arg; if there is text in the current ARGV-element, + it is returned in `optarg', otherwise `optarg' is set to zero. + + If OPTSTRING starts with `-' or `+', it requests different methods of + handling the non-option ARGV-elements. + See the comments about RETURN_IN_ORDER and REQUIRE_ORDER, above. + + Long-named options begin with `--' instead of `-'. + Their names may be abbreviated as long as the abbreviation is unique + or is an exact match for some defined option. If they have an + argument, it follows the option name in the same ARGV-element, separated + from the option name by a `=', or else the in next ARGV-element. + When `getopt' finds a long-named option, it returns 0 if that option's + `flag' field is nonzero, the value of the option's `val' field + if the `flag' field is zero. + + The elements of ARGV aren't really const, because we permute them. + But we pretend they're const in the prototype to be compatible + with other systems. + + LONGOPTS is a vector of `struct option' terminated by an + element containing a name which is zero. + + LONGIND returns the index in LONGOPT of the long-named option found. + It is only valid when a long-named option has been found by the most + recent call. + + If LONG_ONLY is nonzero, '-' as well as '--' can introduce + long-named options. */ + +int +_getopt_internal (int argc, char *const *argv, const char *optstring, const struct option *longopts, int *longind, int long_only) +{ + optarg = NULL; + + if (optind == 0) + optstring = _getopt_initialize (optstring); + + if (nextchar == NULL || *nextchar == '\0') + { + /* Advance to the next ARGV-element. */ + + if (ordering == PERMUTE) + { + /* If we have just processed some options following some non-options, + exchange them so that the options come first. */ + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (last_nonopt != optind) + first_nonopt = optind; + + /* Skip any additional non-options + and extend the range of non-options previously skipped. */ + + while (optind < argc + && (argv[optind][0] != '-' || argv[optind][1] == '\0')) + optind++; + last_nonopt = optind; + } + + /* The special ARGV-element `--' means premature end of options. + Skip it like a null option, + then exchange with previous non-options as if it were an option, + then skip everything else like a non-option. */ + + if (optind != argc && !strcmp (argv[optind], "--")) + { + optind++; + + if (first_nonopt != last_nonopt && last_nonopt != optind) + exchange ((char **) argv); + else if (first_nonopt == last_nonopt) + first_nonopt = optind; + last_nonopt = argc; + + optind = argc; + } + + /* If we have done all the ARGV-elements, stop the scan + and back over any non-options that we skipped and permuted. */ + + if (optind == argc) + { + /* Set the next-arg-index to point at the non-options + that we previously skipped, so the caller will digest them. */ + if (first_nonopt != last_nonopt) + optind = first_nonopt; + return EOF; + } + + /* If we have come to a non-option and did not permute it, + either stop the scan or describe it to the caller and pass it by. */ + + if ((argv[optind][0] != '-' || argv[optind][1] == '\0')) + { + if (ordering == REQUIRE_ORDER) + return EOF; + optarg = argv[optind++]; + return 1; + } + + /* We have found another option-ARGV-element. + Skip the initial punctuation. */ + + nextchar = (argv[optind] + 1 + + (longopts != NULL && argv[optind][1] == '-')); + } + + /* Decode the current option-ARGV-element. */ + + /* Check whether the ARGV-element is a long option. + + If long_only and the ARGV-element has the form "-f", where f is + a valid short option, don't consider it an abbreviated form of + a long option that starts with f. Otherwise there would be no + way to give the -f short option. + + On the other hand, if there's a long option "fubar" and + the ARGV-element is "-fu", do consider that an abbreviation of + the long option, just like "--fu", and not "-f" with arg "u". + + This distinction seems to be the most useful approach. */ + + if (longopts != NULL + && (argv[optind][1] == '-' + || (long_only && (argv[optind][2] || !my_index (optstring, argv[optind][1]))))) + { + char *nameend; + const struct option *p; + const struct option *pfound = NULL; + int exact = 0; + int ambig = 0; + int indfound=0; /* Keep gcc happy */ + int option_index; + + for (nameend = nextchar; *nameend && *nameend != '='; nameend++) + /* Do nothing. */ ; + + /* Test all long options for either exact match + or abbreviated matches. */ + for (p = longopts, option_index = 0; p->name; p++, option_index++) + if (!strncmp (p->name, nextchar, nameend - nextchar)) + { + if ((size_t) (nameend - nextchar) == (size_t) strlen (p->name)) + { + /* Exact match found. */ + pfound = p; + indfound = option_index; + exact = 1; + break; + } + else if (pfound == NULL) + { + /* First nonexact match found. */ + pfound = p; + indfound = option_index; + } + else + /* Second or later nonexact match found. */ + ambig = 1; + } + + if (ambig && !exact) + { + if (opterr) + fprintf (stderr, "%s: option `%s' is ambiguous\n", + argv[0], argv[optind]); + nextchar += strlen (nextchar); + optind++; + return '?'; + } + + if (pfound != NULL) + { + option_index = indfound; + optind++; + if (*nameend) + { + /* Don't test has_arg with >, because some C compilers don't + allow it to be used on enums. */ + if (pfound->has_arg) + optarg = nameend + 1; + else + { + if (opterr) + { + if (argv[optind - 1][1] == '-') + /* --option */ + fprintf (stderr, + "%s: option `--%s' doesn't allow an argument\n", + argv[0], pfound->name); + else + /* +option or -option */ + fprintf (stderr, + "%s: option `%c%s' doesn't allow an argument\n", + argv[0], argv[optind - 1][0], pfound->name); + } + nextchar += strlen (nextchar); + return '?'; + } + } + else if (pfound->has_arg == 1) + { + if (optind < argc) + optarg = argv[optind++]; + else + { + if (opterr) + fprintf (stderr, "%s: option `%s' requires an argument\n", + argv[0], argv[optind - 1]); + nextchar += strlen (nextchar); + return optstring[0] == ':' ? ':' : '?'; + } + } + nextchar += strlen (nextchar); + if (longind != NULL) + *longind = option_index; + if (pfound->flag) + { + *(pfound->flag) = pfound->val; + return 0; + } + return pfound->val; + } + + /* Can't find it as a long option. If this is not getopt_long_only, + or the option starts with '--' or is not a valid short + option, then it's an error. + Otherwise interpret it as a short option. */ + if (!long_only || argv[optind][1] == '-' + || my_index (optstring, *nextchar) == NULL) + { + if (opterr) + { + if (argv[optind][1] == '-') + /* --option */ + fprintf (stderr, "%s: unrecognized option `--%s'\n", + argv[0], nextchar); + else + /* +option or -option */ + fprintf (stderr, "%s: unrecognized option `%c%s'\n", + argv[0], argv[optind][0], nextchar); + } + nextchar = (char *) ""; + optind++; + return '?'; + } + } + + /* Look at and handle the next short option-character. */ + + { + char c = *nextchar++; + char *temp = my_index (optstring, c); + + /* Increment `optind' when we start to process its last character. */ + if (*nextchar == '\0') + ++optind; + + if (temp == NULL || c == ':') + { + if (opterr) + { + if (posixly_correct) + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: illegal option -- %c\n", argv[0], c); + else + fprintf (stderr, "%s: invalid option -- %c\n", argv[0], c); + } + optopt = c; + return '?'; + } + if (temp[1] == ':') + { + if (temp[2] == ':') + { + /* This is an option that accepts an argument optionally. */ + if (*nextchar != '\0') + { + optarg = nextchar; + optind++; + } + else + optarg = NULL; + nextchar = NULL; + } + else + { + /* This is an option that requires an argument. */ + if (*nextchar != '\0') + { + optarg = nextchar; + /* If we end this ARGV-element by taking the rest as an arg, + we must advance to the next element now. */ + optind++; + } + else if (optind == argc) + { + if (opterr) + { + /* 1003.2 specifies the format of this message. */ + fprintf (stderr, "%s: option requires an argument -- %c\n", + argv[0], c); + } + optopt = c; + if (optstring[0] == ':') + c = ':'; + else + c = '?'; + } + else + /* We already incremented `optind' once; + increment it again when taking next ARGV-elt as argument. */ + optarg = argv[optind++]; + nextchar = NULL; + } + } + return c; + } +} + +int +getopt (int argc, char *const *argv, const char *optstring) +{ + return _getopt_internal (argc, argv, optstring, + (const struct option *) 0, + (int *) 0, + 0); +} + +#endif /* _LIBC or not __GNU_LIBRARY__. */ + +#ifdef TEST + +/* Compile with -DTEST to make an executable for use in testing + the above definition of `getopt'. */ + +int +main (argc, argv) + int argc; + char **argv; +{ + int c; + int digit_optind = 0; + + while (1) + { + int this_option_optind = optind ? optind : 1; + + c = getopt (argc, argv, "abc:d:0123456789"); + if (c == EOF) + break; + + switch (c) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + if (digit_optind != 0 && digit_optind != this_option_optind) + printf ("digits occur in two different argv-elements.\n"); + digit_optind = this_option_optind; + printf ("option %c\n", c); + break; + + case 'a': + printf ("option a\n"); + break; + + case 'b': + printf ("option b\n"); + break; + + case 'c': + printf ("option c with value `%s'\n", optarg); + break; + + case '?': + break; + + default: + printf ("?? getopt returned character code 0%o ??\n", c); + } + } + + if (optind < argc) + { + printf ("non-option ARGV-elements: "); + while (optind < argc) + printf ("%s ", argv[optind++]); + printf ("\n"); + } + + exit (0); +} + +#endif /* TEST */ diff --git a/include/getopt.h b/unittest/libmariadb/ma_getopt.h similarity index 100% rename from include/getopt.h rename to unittest/libmariadb/ma_getopt.h diff --git a/unittest/libmariadb/misc.c b/unittest/libmariadb/misc.c index dd156fe8..56153a5e 100644 --- a/unittest/libmariadb/misc.c +++ b/unittest/libmariadb/misc.c @@ -1030,7 +1030,7 @@ static int test_get_info(MYSQL *mysql) char *cval; int rc; MY_CHARSET_INFO cs; - CHARSET_INFO *ci; + MARIADB_CHARSET_INFO *ci; char **errors; rc= mariadb_get_infov(mysql, MARIADB_MAX_ALLOWED_PACKET, &sval); @@ -1045,7 +1045,7 @@ static int test_get_info(MYSQL *mysql) rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_SERVER_VERSION_ID, &sval); FAIL_IF(rc, "mysql_get_info failed"); diag("server_version_id: %d", sval); - rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_CHARSET_INFO, &cs); + rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_MARIADB_CHARSET_INFO, &cs); FAIL_IF(rc, "mysql_get_info failed"); diag("charset name: %s", cs.csname); rc= mariadb_get_infov(mysql, MARIADB_CONNECTION_PVIO_TYPE, &ival); @@ -1085,7 +1085,35 @@ static int test_get_info(MYSQL *mysql) return OK; } +static int test_zerofill(MYSQL *mysql) +{ + int rc; + MYSQL_ROW row; + MYSQL_RES *res; + + rc= mysql_query(mysql, "DROP TABLE IF EXISTS t1"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "CREATE TABLE t1 (a int(10) zerofill)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "INSERT INTO t1 VALUES (1)"); + check_mysql_rc(rc, mysql); + + rc= mysql_query(mysql, "SELECT a FROM t1"); + check_mysql_rc(rc, mysql); + + if (res= mysql_store_result(mysql)) + { + row= mysql_fetch_row(res); + diag("zerofill: %s", row[0]); + mysql_free_result(res); + } + return OK; +} + struct my_tests_st my_tests[] = { + {"test_zerofill", test_zerofill, TEST_CONNECTION_DEFAULT, 0, NULL, NULL}, #ifdef HAVE_REMOTEIO {"test_remote1", test_remote1, TEST_CONNECTION_NEW, 0, NULL, NULL}, {"test_remote2", test_remote2, TEST_CONNECTION_NEW, 0, NULL, NULL}, diff --git a/unittest/libmariadb/my_test.h b/unittest/libmariadb/my_test.h index 329aa545..0c7cf366 100644 --- a/unittest/libmariadb/my_test.h +++ b/unittest/libmariadb/my_test.h @@ -21,13 +21,13 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include -#include +#include +#include #include #include -#include +#include "ma_getopt.h" #include -#include +#include #ifndef WIN32 #include @@ -165,7 +165,7 @@ int do_verify_prepare_field(MYSQL_RES *result, const char *file, int line) { MYSQL_FIELD *field; -/* CHARSET_INFO *cs; */ +/* MARIADB_CHARSET_INFO *cs; */ FAIL_IF(!(field= mysql_fetch_field_direct(result, no)), "FAILED to get result"); /* cs= mysql_find_charset_nr(field->charsetnr); @@ -189,6 +189,8 @@ int do_verify_prepare_field(MYSQL_RES *result, FAIL_UNLESS(strcmp(field->table, table) == 0, "field->table differs"); if (org_table) FAIL_UNLESS(strcmp(field->org_table, org_table) == 0, "field->org_table differs"); + if (strcmp(field->db,db)) + diag("%s / %s", field->db, db); FAIL_UNLESS(strcmp(field->db, db) == 0, "field->db differs"); /* Character set should be taken into account for multibyte encodings, such @@ -411,7 +413,6 @@ MYSQL *test_connect(struct my_tests_st *test) { mysql_close(mysql); return(NULL); } - return(mysql); } diff --git a/unittest/libmariadb/ps.c b/unittest/libmariadb/ps.c index 3eb74bb9..6385fe35 100644 --- a/unittest/libmariadb/ps.c +++ b/unittest/libmariadb/ps.c @@ -830,6 +830,7 @@ static int test_prepare_alter(MYSQL *mysql) FAIL_IF(!(mysql_real_connect(mysql_new, hostname, username, password, schema, port, socketname, 0)), "mysql_real_connect failed"); rc= mysql_query(mysql_new, "ALTER TABLE test_prep_alter change id id_new varchar(20)"); + diag("Error: %d %s", mysql_errno(mysql_new), mysql_error(mysql_new)); check_mysql_rc(rc, mysql_new); mysql_close(mysql_new); diff --git a/unittest/libmariadb/ssl.c.in b/unittest/libmariadb/ssl.c.in index d32fdbb6..b6fed016 100644 --- a/unittest/libmariadb/ssl.c.in +++ b/unittest/libmariadb/ssl.c.in @@ -18,7 +18,7 @@ *************************************************************************************/ #include "my_test.h" -#include +#include static int skip_ssl= 1; @@ -788,7 +788,6 @@ static int test_ssl_version(MYSQL *mysql) mariadb_get_infov(my, MARIADB_SSL_LIBRARY, &library); diag("library: %s", library); - mysql_close(my); return OK; diff --git a/unittest/libmariadb/thread.c b/unittest/libmariadb/thread.c index 9761e363..0c658e75 100644 --- a/unittest/libmariadb/thread.c +++ b/unittest/libmariadb/thread.c @@ -2,6 +2,7 @@ */ #include "my_test.h" +#include static int basic_connect(MYSQL *mysql) { diff --git a/unittest/mytap/tap.c b/unittest/mytap/tap.c index 5cdbfeb4..89bd2471 100644 --- a/unittest/mytap/tap.c +++ b/unittest/mytap/tap.c @@ -19,7 +19,7 @@ #include "tap.h" -#include "my_global.h" +#include "ma_global.h" #include #include @@ -30,7 +30,7 @@ /* Visual Studio 2003 does not know vsnprintf but knows _vsnprintf. We don't put this #define in config-win.h because we prefer - my_vsnprintf everywhere instead, except when linking with libmysys + ma_vsnprintf everywhere instead, except when linking with libmysys is not desirable - the case here. */ #if defined(_MSC_VER) && ( _MSC_VER == 1310 ) diff --git a/unittest/mytap/tap.h b/unittest/mytap/tap.h index d8f617c8..2b4545cb 100644 --- a/unittest/mytap/tap.h +++ b/unittest/mytap/tap.h @@ -20,7 +20,7 @@ #ifndef TAP_H #define TAP_H -#include "my_global.h" +#include "ma_global.h" /* @defgroup MyTAP MySQL support for performing unit tests according to diff --git a/win/packaging/CMakeLists.txt b/win/packaging/CMakeLists.txt index 6decef34..768ac69d 100644 --- a/win/packaging/CMakeLists.txt +++ b/win/packaging/CMakeLists.txt @@ -31,17 +31,17 @@ FOREACH(plugin ${PLUGINS}) SET(TARGET ${${plugin}_PLUGIN_TARGET}) # Get dependencies SET(DYNAMIC_TARGETS ${DYNAMIC_TARGETS} ${TARGET}) - + GET_PROPERTY(FILE TARGET ${TARGET} PROPERTY LOCATION) + #MESSAGE(STATUS "Location for ${TARGET}: ${DIRECTORY}") # build file list - SET(FILE ${${plugin}_PLUGIN_SOURCE}) - GET_FILENAME_COMPONENT(FILE ${FILE} DIRECTORY) - STRING(REPLACE ${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} FILE ${FILE}) - SET(FILE ${FILE}/RelWithDebInfo/${TARGET}.dll) + STRING(REPLACE "$(Configuration)" "RelWithDebInfo" FILE ${FILE}) SET(MARIADB_PLUGINS "${MARIADB_PLUGINS} \n") ENDIF() ENDFOREACH() -FOREACH(src ${MARIADB_CLIENT_INCLUDES}) +SET(ALL_INCLUDES ${MARIADB_CLIENT_INCLUDES} ${MARIADB_ADDITIONAL_INCLUDES}) +FOREACH(src ${ALL_INCLUDES}) + STRING(REPLACE "${CMAKE_SOURCE_DIR}/include/" "" src ${src}) STRING(REPLACE "-" "_" src_id ${src}) STRING(REPLACE "mysql/" "" src_id ${src_id}) STRING(REPLACE "mysql/" "" src_name ${src}) @@ -90,7 +90,7 @@ ADD_CUSTOM_TARGET(WIXOBJ SET_TARGET_PROPERTIES(${MSI_PACKAGE} PROPERTIES EXCLUDE_FROM_ALL OFF) SET_TARGET_PROPERTIES(${WIXOBJ} PROPERTIES EXCLUDE_FROM_ALL OFF) ADD_DEPENDENCIES(${MSI_PACKAGE} WIXOBJ) -ADD_DEPENDENCIES(WIXOBJ libmariadb mariadbclient mariadb_client_plugin_info ${DYNAMIC_TARGETS}) +ADD_DEPENDENCIES(WIXOBJ libmariadb mariadbclient ${DYNAMIC_TARGETS}) CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/win/packaging/mariadb-connector-c.xml.in ${CMAKE_BINARY_DIR}/win/packaging/mariadb-connector-c.xml) diff --git a/win/packaging/mariadb-connector-c.xml.in b/win/packaging/mariadb-connector-c.xml.in index 38e648e1..a918e0c9 100644 --- a/win/packaging/mariadb-connector-c.xml.in +++ b/win/packaging/mariadb-connector-c.xml.in @@ -58,8 +58,10 @@ +