1
0
mirror of https://github.com/mariadb-corporation/mariadb-connector-c.git synced 2025-08-07 02:42:49 +03:00

Merge remote-tracking branch 'origin/3.1'

This commit is contained in:
Georg Richter
2016-02-16 17:40:03 +01:00
170 changed files with 3942 additions and 14159 deletions

View File

@@ -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")

View File

@@ -6,7 +6,7 @@
#include <getopt.h>
#include <stdio.h>
#include <my_dir.h>
#include <m_string.h>
#include <ma_string.h>
#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);

16
cmake/export.cmake Normal file
View File

@@ -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()

View File

@@ -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)

View File

@@ -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)

View File

@@ -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

View File

@@ -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 <strings.h>
#endif
#if defined(HAVE_STRING_H)
#include <string.h>
#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 <strings.h>
#endif
/* This is needed for the definitions of memcpy... on solaris */
#if defined(HAVE_MEMORY_H) && !defined(__cplusplus)
#include <memory.h>
#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

View File

@@ -21,7 +21,7 @@
#define _ma_common_h
#include <mysql.h>
#include <hash.h>
#include <ma_hash.h>
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;
};

View File

@@ -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"

View File

@@ -23,9 +23,9 @@
#ifdef _WIN32
#include <config-win.h>
#include <ma_config_win.h>
#else
#include <my_config.h>
#include <ma_config.h>
#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 <dbug.h>
#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

View File

@@ -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

View File

@@ -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
}

View File

@@ -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

View File

@@ -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);
};

View File

@@ -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

View File

@@ -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 <string.h>
char *ma_ll2str(long long val,char *dst, int radix);
#include <my_global.h>
#include <m_string.h>
#if !defined(HAVE_STRTOULL) && defined(HAVE_LONG_LONG)
#define USE_UNSIGNED
#define USE_LONGLONG
#include "strto.c"
#endif

View File

@@ -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 <my_pthread.h>
#endif
#ifndef _m_ctype_h
#include <m_ctype.h> /* for CHARSET_INFO */
#ifndef _mariadb_ctype_h
#include <mariadb_ctype.h> /* for MARIADB_CHARSET_INFO */
#endif
#include <stdarg.h>
#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
}

View File

@@ -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
}

View File

@@ -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 <ctype.h>
@@ -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);

View File

@@ -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

View File

@@ -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);

View File

@@ -3,6 +3,9 @@
/* Version numbers for protocol & mysqld */
#ifndef _mariadb_version_h_
#define _mariadb_version_h_
#ifdef _CUSTOMCONFIG_
#include <custom_conf.h>
#else
@@ -26,3 +29,4 @@
#endif
#endif
#endif /* _mariadb_version_h_ */

View File

@@ -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 <signal.h>
#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

View File

@@ -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 <global.h>
#include <my_dir.h> /* This includes types */
#include <my_sys.h>
#include <m_string.h>
#include <errno.h>
#ifdef MSDOS
#include <share.h> /* Neaded for sopen() */
#endif
#if !defined(USE_MY_FUNC) && !defined(THREAD)
#include <my_nosys.h> /* For faster code, after test */
#endif /* USE_MY_FUNC */
#endif /* stdin */
#include <my_list.h>
/* 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 */

View File

@@ -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 <sys/stat.h>
/* 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

View File

@@ -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 <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#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

View File

@@ -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

View File

@@ -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);

View File

@@ -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 */

View File

@@ -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 <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
#ifndef MYSQLND_MM_H
#define MYSQLND_MM_H
#include <stdlib.h>
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
*/

View File

@@ -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);

View File

@@ -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 <georg@mysql.com> |
| Andrey Hristov <andrey@mysql.com> |
| Ulf Wendel <uwendel@mysql.com> |
+----------------------------------------------------------------------+
*/
/* $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
*/

View File

@@ -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

View File

@@ -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 */

View File

@@ -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} $<TARGET_OBJECTS:mariadb_obj> ${EMPTY_FILE} ${EXPORT_LINK})
ADD_LIBRARY(mariadbclient STATIC ${mariadbclient_RC} $<TARGET_OBJECTS:mariadb_obj> ${EMPTY_FILE} mariadbclient.def)
TARGET_LINK_LIBRARIES(mariadbclient ${SYSTEM_LIBS})
ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $<TARGET_OBJECTS:mariadb_obj> ${EMPTY_FILE} ${EXPORT_LINK})
ADD_LIBRARY(libmariadb SHARED ${libmariadb_RC} $<TARGET_OBJECTS:mariadb_obj> ${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})

View File

@@ -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 <my_global.h>
#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);
}

View File

@@ -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 <my_global.h>
#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

View File

@@ -24,28 +24,10 @@
"src-len" to the destination "dst-len" counting downwards.
*/
#include <my_global.h>
#include "m_string.h"
#include <ma_global.h>
#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

View File

@@ -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 <m_ctype.h>
#include <m_string.h>
#include <my_dir.h>
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);
}

File diff suppressed because it is too large Load Diff

View File

@@ -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 <ctype.h>
#include "m_ctype.h"
#include <my_dir.h>
#include <mysql.h>
#include <mariadb/ma_io.h>
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 <winbase.h>
#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");
}

View File

@@ -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

View File

@@ -16,11 +16,11 @@
or write to the Free Software Foundation, Inc.,
51 Franklin St., Fifth Floor, Boston, MA 02110, USA
*************************************************************************************/
#include <my_global.h>
#include <my_sys.h>
#include <ma_global.h>
#include <ma_sys.h>
#include "mysql.h"
#include <m_string.h>
#include <m_ctype.h>
#include <ma_string.h>
#include <mariadb_ctype.h>
#include <stdio.h>
#include <memory.h>

View File

@@ -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 <config.h>
#endif
#include <my_global.h>
#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 <stdio.h>
/* 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 <stdlib.h>
#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 <stdio.h>
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 */

View File

@@ -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 <my_global.h>
#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

View File

@@ -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 <my_global.h>
#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 */
}

View File

@@ -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 <my_global.h>
#include "m_string.h"
char *llstr(longlong value,char *buff)
{
longlong2str(value,buff,-10);
return buff;
}

View File

@@ -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 <my_global.h>
#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

View File

@@ -17,24 +17,23 @@
/* Routines to handle mallocing of results which will be freed the same time */
#include <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
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;
}

View File

@@ -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 <ma_global.h>
#include <ma_sys.h>
#include "ma_string.h"
#include <memory.h>
/*
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;
}
}

View File

@@ -49,13 +49,12 @@
#else
#include <string.h>
#endif
#include <my_global.h>
#include <m_ctype.h>
#include <m_string.h>
#include <ma_global.h>
#include <mariadb_ctype.h>
#include <ma_string.h>
#include <iconv.h>
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;

View File

@@ -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 <my_global.h>
#include <my_sys.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <m_string.h>
#ifdef THREAD
#include <my_pthread.h>
#else
#include <my_no_pthread.h>
#endif
#include <ma_string.h>
#include <ma_pthread.h>
#include "errmsg.h"
#include "ma_errmsg.h"
#include <mysql/client_plugin.h>
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)))

View File

@@ -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 <sinisa@coresinc.com> */
#include <my_global.h>
#include <ma_global.h>
#ifdef HAVE_COMPRESS
#include <my_sys.h>
#include <m_string.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <zlib.h>
/*
@@ -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;

View File

@@ -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 <valgrind/valgrind.h>
@@ -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;
}

224
libmariadb/ma_default.c Normal file
View File

@@ -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 <ma_global.h>
#include <ma_sys.h>
#include "ma_string.h"
#include <ctype.h>
#include "mariadb_ctype.h"
#include <mysql.h>
#include <ma_common.h>
#include <mariadb/ma_io.h>
#ifdef _WIN32
#include <io.h>
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 <unistd.h>
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;
}

View File

@@ -18,9 +18,9 @@
/* Error messages for MySQL clients */
/* error messages for the demon is in share/language/errmsg.sys */
#include <my_global.h>
#include <my_sys.h>
#include "errmsg.h"
#include <ma_global.h>
#include <ma_sys.h>
#include "ma_errmsg.h"
#include <stdarg.h>
#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];
}

View File

@@ -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 <m_string.h>
#include <m_ctype.h>
#include "hash.h"
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <mariadb_ctype.h>
#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

115
libmariadb/ma_init.c Normal file
View File

@@ -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 <ma_global.h>
#include <ma_sys.h>
#include "mariadb_ctype.h"
#include <ma_string.h>
#include <mariadb_ctype.h>
#ifdef HAVE_GETRUSAGE
#include <sys/resource.h>
/* extern int getrusage(int, struct rusage *); */
#endif
#include <signal.h>
#ifdef _WIN32
#ifdef _MSC_VER
#include <locale.h>
#include <crtdbg.h>
#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

View File

@@ -17,10 +17,9 @@
MA 02111-1307, USA
*/
#include <my_global.h>
#include <my_sys.h>
#include <mysys_err.h>
#include <errmsg.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_errmsg.h>
#include <mysql.h>
#include <mysql/client_plugin.h>
#include <mariadb/ma_io.h>
@@ -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:

View File

@@ -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 <my_list.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_list.h>
/* 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;

75
libmariadb/ma_ll2str.c Normal file
View File

@@ -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 <ma_global.h>
#include "ma_string.h"
#include <ctype.h>
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;
}

View File

@@ -40,11 +40,10 @@
+----------------------------------------------------------------------+
*/
#include "my_global.h"
#include <my_sys.h>
#include <mysys_err.h>
#include <m_string.h>
#include "errmsg.h"
#include "ma_global.h"
#include <ma_sys.h>
#include <ma_string.h>
#include "ma_errmsg.h"
#include "mysql.h"
#include <mariadb/ma_io.h>
#include <string.h>
@@ -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);
}
/* }}} */

View File

@@ -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 <my_global.h>
#include <ma_global.h>
#include <mysql.h>
#include <ma_pvio.h>
#include <my_sys.h>
#include <m_string.h>
#include <ma_sys.h>
#include <ma_string.h>
#include "mysql.h"
#include "mysqld_error.h"
#include "ma_server_error.h"
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
@@ -64,19 +64,6 @@ ulong net_buffer_length= 8192; /* Default length. Enlarged if necessary */
#include <netinet/tcp.h>
#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 */

View File

@@ -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 <my_global.h>
#include <my_sys.h>
#include <m_string.h>
#include <sha1.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <ma_sha1.h>
#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);

View File

@@ -43,18 +43,18 @@
register callback functions for read and write
*/
#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>
#include <mysql/client_plugin.h>
#include <string.h>
#include <ma_common.h>
#include <ma_pvio.h>
#include <mysql_async.h>
#include <my_context.h>
extern pthread_mutex_t THR_LOCK_lock;
#ifdef HAVE_NONBLOCK
#include <mariadb_async.h>
#include <ma_context.h>
#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;
}

326
libmariadb/ma_sha1.c Normal file
View File

@@ -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 <http://www.gnu.org/licenses>
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
*/

View File

@@ -32,20 +32,19 @@
#ifdef HAVE_SSL
#include <my_global.h>
#include <my_sys.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_common.h>
#include <string.h>
//#include <ma_secure.h>
#include <errmsg.h>
#include <ma_errmsg.h>
#include <ma_pvio.h>
#include <ma_ssl.h>
#include <mysql/client_plugin.h>
/*
#include <mysql_async.h>
#include <my_context.h>
*/
#ifdef HAVE_NONBLOCK
#include <mariadb_async.h>
#include <ma_context.h>
#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;

View File

@@ -43,11 +43,10 @@
+----------------------------------------------------------------------+
*/
#include "my_global.h"
#include <my_sys.h>
#include <mysys_err.h>
#include <m_string.h>
#include <m_ctype.h>
#include "ma_global.h"
#include <ma_sys.h>
#include <ma_string.h>
#include <mariadb_ctype.h>
#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;
}
/* }}} */

View File

@@ -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 <m_string.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
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;
}
}

View File

@@ -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 <my_global.h>
#include <ma_global.h>
#include <mysql.h>
#include <stdio.h>

View File

@@ -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 <string.h>
@@ -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

View File

@@ -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 <ma_global.h>
#include <ma_sys.h>
// #include "mysys_err.h"
#include <mariadb_ctype.h>
#include <ma_string.h>
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);
}

View File

@@ -61,25 +61,25 @@
*/
#include <stdio.h>
#include "mysys_priv.h"
#include <my_global.h>
#include <m_string.h>
#include <hash.h>
#include <ma_dyncol.h>
#include <ma_global.h>
#include <ma_sys.h>
#include <ma_string.h>
#include <ma_hash.h>
#include <mariadb_dyncol.h>
#include <mysql.h>
#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, &quote, 1);
rc= dynstr_append_mem(str, from, len);
rc= ma_dynstr_append_mem(str, &quote, 1);
rc= ma_dynstr_append_mem(str, from, len);
if (quote)
rc= dynstr_append_mem(str, &quote, 1);
rc= ma_dynstr_append_mem(str, &quote, 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);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -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 <m_string.h>
/* 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 */

View File

@@ -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 <m_string.h>
/* 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 */

View File

@@ -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 <m_string.h>
#ifdef HAVE_REALPATH
#include <sys/param.h>
#include <sys/stat.h>
#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 */

View File

@@ -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 <m_string.h>
/* 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 */

View File

@@ -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 <m_string.h>
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef VMS
#include <rms.h>
#include <iodef.h>
#include <descrip.h>
#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 */

View File

@@ -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 <m_string.h>
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 */
}

View File

@@ -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 <m_string.h>
/* 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
}

View File

@@ -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 */

View File

@@ -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 <stdarg.h>
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);
}

View File

@@ -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 */
}

View File

@@ -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 <m_string.h>
#include <stdarg.h>
#include <m_ctype.h>
/* 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);
}

View File

@@ -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 <errno.h>
#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 */

View File

@@ -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 <errno.h>
#include <stdio.h>
#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 */

View File

@@ -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 <m_string.h>
#include "mysys_err.h"
#ifdef HAVE_GETWD
#include <sys/param.h>
#endif
#if defined(MSDOS) || defined(_WIN32)
#include <m_ctype.h>
#include <dos.h>
#include <direct.h>
#endif
#if defined(OS2)
#include <direct.h>
#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 */

View File

@@ -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 <m_string.h>
#include <m_ctype.h>
#ifdef HAVE_GETRUSAGE
#include <sys/resource.h>
/* extern int getrusage(int, struct rusage *); */
#endif
#include <signal.h>
#ifdef VMS
#include <my_static.c>
#include <m_ctype.h>
#endif
#ifdef _WIN32
#ifdef _MSC_VER
#include <locale.h>
#include <crtdbg.h>
#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

View File

@@ -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 <m_string.h>
#include <my_dir.h> /* Structs used by my_dir,includes sys/types */
#include "mysys_err.h"
#if defined(HAVE_DIRENT_H)
# include <dirent.h>
# 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 <sys/ndir.h>
# endif
# if defined(HAVE_SYS_DIR_H)
# include <sys/dir.h>
# endif
# if defined(HAVE_NDIR_H)
# include <ndir.h>
# endif
# if defined(MSDOS) || defined(_WIN32)
# include <dos.h>
# ifdef __BORLANDC__
# include <dir.h>
# endif
# endif
#endif
#ifdef VMS
#include <rms.h>
#include <iodef.h>
#include <descrip.h>
#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 */

View File

@@ -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 <m_string.h>
/* 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;
}
/* }}} */

View File

@@ -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);
}

View File

@@ -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 <m_string.h>
/* for thread safe my_inet_ntoa */
#if !defined(MSDOS) && !defined(_WIN32)
#include <netdb.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif
#ifdef HAVE_ARPA_INET_H
#include <arpa/inet.h>
#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);
}

View File

@@ -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 */

Some files were not shown because too many files have changed in this diff Show More