2003-11-03 13:01:59 +01:00
|
|
|
/* Copyright (C) 2000-2003 MySQL AB
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2006-12-23 20:17:15 +01:00
|
|
|
the Free Software Foundation; version 2 of the License.
|
2001-12-06 13:10:51 +01:00
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
2000-07-31 21:29:14 +02:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2001-12-06 13:10:51 +01:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2003-08-28 05:08:17 +02:00
|
|
|
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 ~/
|
2005-07-18 14:33:18 +02:00
|
|
|
--defaults-group-suffix ; Also read groups with concat(group, suffix)
|
|
|
|
--print-defaults ; Print the modified command line and exit
|
2000-07-31 21:29:14 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "mysys_priv.h"
|
|
|
|
#include "m_string.h"
|
|
|
|
#include "m_ctype.h"
|
2003-03-10 12:31:49 +01:00
|
|
|
#include <my_dir.h>
|
2004-11-12 18:58:24 +01:00
|
|
|
#ifdef __WIN__
|
|
|
|
#include <winbase.h>
|
|
|
|
#endif
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
const char *my_defaults_file=0;
|
|
|
|
const char *my_defaults_group_suffix=0;
|
|
|
|
char *my_defaults_extra_file=0;
|
2000-10-06 20:15:03 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
/* Which directories are searched for options (and in which order) */
|
|
|
|
|
2007-11-07 23:23:50 +01:00
|
|
|
#define MAX_DEFAULT_DIRS 6
|
2008-06-25 03:25:23 +02:00
|
|
|
#define DEFAULT_DIRS_SIZE (MAX_DEFAULT_DIRS + 1) /* Terminate with NULL */
|
|
|
|
static const char **default_directories = NULL;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
#ifdef __WIN__
|
2004-11-05 17:59:19 +01:00
|
|
|
static const char *f_extensions[]= { ".ini", ".cnf", 0 };
|
2005-05-15 23:54:02 +02:00
|
|
|
#define NEWLINE "\r\n"
|
2004-11-11 15:20:39 +01:00
|
|
|
#else
|
|
|
|
static const char *f_extensions[]= { ".cnf", 0 };
|
2005-05-15 23:54:02 +02:00
|
|
|
#define NEWLINE "\n"
|
2000-07-31 21:29:14 +02:00
|
|
|
#endif
|
|
|
|
|
2005-07-18 14:33:18 +02:00
|
|
|
static int handle_default_option(void *in_ctx, const char *group_name,
|
|
|
|
const char *option);
|
|
|
|
|
2004-08-30 16:17:50 +02:00
|
|
|
/*
|
|
|
|
This structure defines the context that we pass to callback
|
|
|
|
function 'handle_default_option' used in search_default_file
|
|
|
|
to process each option. This context is used if search_default_file
|
|
|
|
was called from load_defaults.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct handle_option_ctx
|
|
|
|
{
|
|
|
|
MEM_ROOT *alloc;
|
|
|
|
DYNAMIC_ARRAY *args;
|
|
|
|
TYPELIB *group;
|
|
|
|
};
|
|
|
|
|
|
|
|
static int search_default_file(Process_option_func func, void *func_ctx,
|
2004-11-12 18:58:24 +01:00
|
|
|
const char *dir, const char *config_file);
|
2004-11-12 20:24:16 +01:00
|
|
|
static int search_default_file_with_ext(Process_option_func func,
|
|
|
|
void *func_ctx,
|
2004-11-11 15:59:36 +01:00
|
|
|
const char *dir, const char *ext,
|
2005-03-29 11:55:11 +02:00
|
|
|
const char *config_file, int recursion_level);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
Create the list of default directories.
|
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
@param alloc MEM_ROOT where the list of directories is stored
|
|
|
|
|
2007-11-07 23:23:50 +01:00
|
|
|
@details
|
2008-06-25 03:25:23 +02:00
|
|
|
The directories searched, in order, are:
|
|
|
|
- Windows: GetSystemWindowsDirectory()
|
|
|
|
- Windows: GetWindowsDirectory()
|
|
|
|
- Windows: C:/
|
|
|
|
- Windows: Directory above where the executable is located
|
|
|
|
- Netware: sys:/etc/
|
2008-06-27 22:53:27 +02:00
|
|
|
- Unix: /etc/
|
|
|
|
- Unix: /etc/mysql/
|
2008-06-25 03:25:23 +02:00
|
|
|
- Unix: --sysconfdir=<path> (compile-time option)
|
|
|
|
- ALL: getenv(DEFAULT_HOME_ENV)
|
|
|
|
- ALL: --defaults-extra-file=<path> (run-time option)
|
|
|
|
- Unix: ~/
|
|
|
|
|
2007-11-07 23:23:50 +01:00
|
|
|
On all systems, if a directory is already in the list, it will be moved
|
|
|
|
to the end of the list. This avoids reading defaults files multiple times,
|
|
|
|
while ensuring the correct precedence.
|
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
@retval NULL Failure (out of memory, probably)
|
|
|
|
@retval other Pointer to NULL-terminated array of default directories
|
2007-11-07 23:23:50 +01:00
|
|
|
*/
|
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
static const char **init_default_directories(MEM_ROOT *alloc);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-05-14 15:47:55 +02:00
|
|
|
static char *remove_end_comment(char *ptr);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2003-08-28 05:08:17 +02:00
|
|
|
|
2004-08-30 16:17:50 +02:00
|
|
|
/*
|
|
|
|
Process config files in default directories.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2005-02-18 12:58:30 +01:00
|
|
|
my_search_option_files()
|
2004-08-30 16:17:50 +02:00
|
|
|
conf_file Basename for configuration file to search for.
|
|
|
|
If this is a path, then only this file is read.
|
|
|
|
argc Pointer to argc of original program
|
|
|
|
argv Pointer to argv of original program
|
|
|
|
args_used Pointer to variable for storing the number of
|
|
|
|
arguments used.
|
|
|
|
func Pointer to the function to process options
|
|
|
|
func_ctx It's context. Usually it is the structure to
|
|
|
|
store additional options.
|
|
|
|
DESCRIPTION
|
2005-07-18 14:33:18 +02:00
|
|
|
Process the default options from argc & argv
|
|
|
|
Read through each found config file looks and calls 'func' to process
|
|
|
|
each option.
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
--defaults-group-suffix is only processed if we are called from
|
|
|
|
load_defaults().
|
2004-08-30 16:17:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 given cinf_file doesn't exist
|
2008-10-27 10:57:59 +01:00
|
|
|
2 out of memory
|
2005-07-18 14:33:18 +02:00
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
The global variable 'my_defaults_group_suffix' is updated with value for
|
2005-07-18 14:33:18 +02:00
|
|
|
--defaults_group_suffix
|
2004-08-30 16:17:50 +02:00
|
|
|
*/
|
|
|
|
|
2005-02-18 12:58:30 +01:00
|
|
|
int my_search_option_files(const char *conf_file, int *argc, char ***argv,
|
2005-07-18 14:33:18 +02:00
|
|
|
uint *args_used, Process_option_func func,
|
2009-02-27 10:26:06 +01:00
|
|
|
void *func_ctx, const char **default_directories)
|
2004-08-30 16:17:50 +02:00
|
|
|
{
|
2005-05-02 19:19:37 +02:00
|
|
|
const char **dirs, *forced_default_file, *forced_extra_defaults;
|
2004-08-30 16:17:50 +02:00
|
|
|
int error= 0;
|
2005-02-18 12:58:30 +01:00
|
|
|
DBUG_ENTER("my_search_option_files");
|
2004-08-30 16:17:50 +02:00
|
|
|
|
|
|
|
/* Check if we want to force the use a specific default file */
|
2005-07-18 14:33:18 +02:00
|
|
|
*args_used+= get_defaults_options(*argc - *args_used, *argv + *args_used,
|
|
|
|
(char **) &forced_default_file,
|
|
|
|
(char **) &forced_extra_defaults,
|
2006-12-14 23:51:37 +01:00
|
|
|
(char **) &my_defaults_group_suffix);
|
2005-01-11 20:28:56 +01:00
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
if (! my_defaults_group_suffix)
|
|
|
|
my_defaults_group_suffix= getenv(STRINGIFY_ARG(DEFAULT_GROUP_SUFFIX_ENV));
|
2005-09-09 09:51:43 +02:00
|
|
|
|
|
|
|
if (forced_extra_defaults)
|
2006-12-14 23:51:37 +01:00
|
|
|
my_defaults_extra_file= (char *) forced_extra_defaults;
|
2005-07-18 14:33:18 +02:00
|
|
|
|
2005-09-30 09:54:53 +02:00
|
|
|
if (forced_default_file)
|
2006-12-14 23:51:37 +01:00
|
|
|
my_defaults_file= forced_default_file;
|
2005-09-30 09:54:53 +02:00
|
|
|
|
2005-07-18 14:33:18 +02:00
|
|
|
/*
|
|
|
|
We can only handle 'defaults-group-suffix' if we are called from
|
|
|
|
load_defaults() as otherwise we can't know the type of 'func_ctx'
|
|
|
|
*/
|
2004-08-30 16:17:50 +02:00
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
if (my_defaults_group_suffix && func == handle_default_option)
|
2005-07-18 14:33:18 +02:00
|
|
|
{
|
|
|
|
/* Handle --defaults-group-suffix= */
|
|
|
|
uint i;
|
|
|
|
const char **extra_groups;
|
2009-02-10 23:47:54 +01:00
|
|
|
const size_t instance_len= strlen(my_defaults_group_suffix);
|
2005-07-18 14:33:18 +02:00
|
|
|
struct handle_option_ctx *ctx= (struct handle_option_ctx*) func_ctx;
|
|
|
|
char *ptr;
|
|
|
|
TYPELIB *group= ctx->group;
|
|
|
|
|
|
|
|
if (!(extra_groups=
|
|
|
|
(const char**)alloc_root(ctx->alloc,
|
|
|
|
(2*group->count+1)*sizeof(char*))))
|
2008-10-27 10:57:59 +01:00
|
|
|
DBUG_RETURN(2);
|
2005-07-18 14:33:18 +02:00
|
|
|
|
|
|
|
for (i= 0; i < group->count; i++)
|
|
|
|
{
|
2009-02-10 23:47:54 +01:00
|
|
|
size_t len;
|
2005-07-18 14:33:18 +02:00
|
|
|
extra_groups[i]= group->type_names[i]; /** copy group */
|
|
|
|
|
|
|
|
len= strlen(extra_groups[i]);
|
2009-02-10 23:47:54 +01:00
|
|
|
if (!(ptr= alloc_root(ctx->alloc, (uint) (len+instance_len+1))))
|
2009-03-17 21:29:24 +01:00
|
|
|
DBUG_RETURN(2);
|
2005-07-18 14:33:18 +02:00
|
|
|
|
|
|
|
extra_groups[i+group->count]= ptr;
|
|
|
|
|
|
|
|
/** Construct new group */
|
|
|
|
memcpy(ptr, extra_groups[i], len);
|
2006-12-14 23:51:37 +01:00
|
|
|
memcpy(ptr+len, my_defaults_group_suffix, instance_len+1);
|
2005-07-18 14:33:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
group->count*= 2;
|
|
|
|
group->type_names= extra_groups;
|
|
|
|
group->type_names[group->count]= 0;
|
|
|
|
}
|
|
|
|
|
2004-08-30 16:17:50 +02:00
|
|
|
if (forced_default_file)
|
|
|
|
{
|
2004-11-12 18:58:24 +01:00
|
|
|
if ((error= search_default_file_with_ext(func, func_ctx, "", "",
|
2005-03-29 14:15:22 +02:00
|
|
|
forced_default_file, 0)) < 0)
|
2004-08-30 16:17:50 +02:00
|
|
|
goto err;
|
|
|
|
if (error > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not open required defaults file: %s\n",
|
|
|
|
forced_default_file);
|
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (dirname_length(conf_file))
|
|
|
|
{
|
2004-11-12 18:58:24 +01:00
|
|
|
if ((error= search_default_file(func, func_ctx, NullS, conf_file)) < 0)
|
2004-08-30 16:17:50 +02:00
|
|
|
goto err;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for (dirs= default_directories ; *dirs; dirs++)
|
|
|
|
{
|
|
|
|
if (**dirs)
|
|
|
|
{
|
2004-11-12 18:58:24 +01:00
|
|
|
if (search_default_file(func, func_ctx, *dirs, conf_file) < 0)
|
2004-08-30 16:17:50 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2006-12-14 23:51:37 +01:00
|
|
|
else if (my_defaults_extra_file)
|
2004-08-30 16:17:50 +02:00
|
|
|
{
|
2005-05-12 14:23:16 +02:00
|
|
|
if ((error= search_default_file_with_ext(func, func_ctx, "", "",
|
2006-12-14 23:51:37 +01:00
|
|
|
my_defaults_extra_file, 0)) < 0)
|
2004-08-30 16:17:50 +02:00
|
|
|
goto err; /* Fatal error */
|
2005-05-06 13:51:58 +02:00
|
|
|
if (error > 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "Could not open required defaults file: %s\n",
|
2006-12-14 23:51:37 +01:00
|
|
|
my_defaults_extra_file);
|
2005-05-06 13:51:58 +02:00
|
|
|
goto err;
|
|
|
|
}
|
2004-08-30 16:17:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-27 10:57:59 +01:00
|
|
|
DBUG_RETURN(0);
|
2004-08-30 16:17:50 +02:00
|
|
|
|
|
|
|
err:
|
|
|
|
fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
|
2008-10-27 10:57:59 +01:00
|
|
|
DBUG_RETURN(1);
|
2004-08-30 16:17:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
The option handler for load_defaults.
|
|
|
|
|
|
|
|
SYNOPSIS
|
2004-11-12 18:58:24 +01:00
|
|
|
handle_deault_option()
|
|
|
|
in_ctx Handler context. In this case it is a
|
2004-08-30 16:17:50 +02:00
|
|
|
handle_option_ctx structure.
|
2004-11-12 18:58:24 +01:00
|
|
|
group_name The name of the group the option belongs to.
|
|
|
|
option The very option to be processed. It is already
|
2006-05-18 16:57:50 +02:00
|
|
|
prepared to be used in argv (has -- prefix). If it
|
|
|
|
is NULL, we are handling a new group (section).
|
2004-08-30 16:17:50 +02:00
|
|
|
|
2004-09-05 22:32:21 +02:00
|
|
|
DESCRIPTION
|
2004-11-12 18:58:24 +01:00
|
|
|
This handler checks whether a group is one of the listed and adds an option
|
|
|
|
to the array if yes. Some other handler can record, for instance, all
|
|
|
|
groups and their options, not knowing in advance the names and amount of
|
|
|
|
groups.
|
2004-09-05 22:32:21 +02:00
|
|
|
|
2004-08-30 16:17:50 +02:00
|
|
|
RETURN
|
|
|
|
0 - ok
|
|
|
|
1 - error occured
|
|
|
|
*/
|
|
|
|
|
|
|
|
static int handle_default_option(void *in_ctx, const char *group_name,
|
2004-11-12 18:58:24 +01:00
|
|
|
const char *option)
|
2004-08-30 16:17:50 +02:00
|
|
|
{
|
|
|
|
char *tmp;
|
2004-11-12 18:58:24 +01:00
|
|
|
struct handle_option_ctx *ctx= (struct handle_option_ctx *) in_ctx;
|
|
|
|
|
2006-05-18 16:57:50 +02:00
|
|
|
if (!option)
|
|
|
|
return 0;
|
|
|
|
|
2004-11-12 18:58:24 +01:00
|
|
|
if (find_type((char *)group_name, ctx->group, 3))
|
2004-08-30 16:17:50 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (!(tmp= alloc_root(ctx->alloc, strlen(option) + 1)))
|
2004-08-30 16:17:50 +02:00
|
|
|
return 1;
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
if (insert_dynamic(ctx->args, (uchar*) &tmp))
|
2004-08-30 16:17:50 +02:00
|
|
|
return 1;
|
|
|
|
strmov(tmp, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-01-03 16:21:54 +01:00
|
|
|
/*
|
2005-07-18 14:33:18 +02:00
|
|
|
Gets options from the command line
|
2005-01-03 16:21:54 +01:00
|
|
|
|
|
|
|
SYNOPSIS
|
2005-07-18 14:33:18 +02:00
|
|
|
get_defaults_options()
|
2005-01-03 16:21:54 +01:00
|
|
|
argc Pointer to argc of original program
|
|
|
|
argv Pointer to argv of original program
|
|
|
|
defaults --defaults-file option
|
|
|
|
extra_defaults --defaults-extra-file option
|
|
|
|
|
|
|
|
RETURN
|
2005-07-18 14:33:18 +02:00
|
|
|
# Number of arguments used from *argv
|
|
|
|
defaults and extra_defaults will be set to option of the appropriate
|
|
|
|
items of argv array, or to NULL if there are no such options
|
2005-01-03 16:21:54 +01:00
|
|
|
*/
|
|
|
|
|
2005-07-18 14:33:18 +02:00
|
|
|
int get_defaults_options(int argc, char **argv,
|
|
|
|
char **defaults,
|
|
|
|
char **extra_defaults,
|
|
|
|
char **group_suffix)
|
2005-01-03 16:21:54 +01:00
|
|
|
{
|
2005-07-18 14:33:18 +02:00
|
|
|
int org_argc= argc, prev_argc= 0;
|
|
|
|
*defaults= *extra_defaults= *group_suffix= 0;
|
|
|
|
|
|
|
|
while (argc >= 2 && argc != prev_argc)
|
2005-01-03 16:21:54 +01:00
|
|
|
{
|
2005-07-18 14:33:18 +02:00
|
|
|
/* Skip program name or previously handled argument */
|
|
|
|
argv++;
|
|
|
|
prev_argc= argc; /* To check if we found */
|
|
|
|
if (!*defaults && is_prefix(*argv,"--defaults-file="))
|
|
|
|
{
|
|
|
|
*defaults= *argv + sizeof("--defaults-file=")-1;
|
|
|
|
argc--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!*extra_defaults && is_prefix(*argv,"--defaults-extra-file="))
|
|
|
|
{
|
|
|
|
*extra_defaults= *argv + sizeof("--defaults-extra-file=")-1;
|
|
|
|
argc--;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!*group_suffix && is_prefix(*argv, "--defaults-group-suffix="))
|
|
|
|
{
|
|
|
|
*group_suffix= *argv + sizeof("--defaults-group-suffix=")-1;
|
|
|
|
argc--;
|
|
|
|
continue;
|
|
|
|
}
|
2005-01-03 16:21:54 +01:00
|
|
|
}
|
2005-07-18 14:33:18 +02:00
|
|
|
return org_argc - argc;
|
2005-01-03 16:21:54 +01:00
|
|
|
}
|
|
|
|
|
2009-02-27 10:26:06 +01:00
|
|
|
/*
|
|
|
|
Wrapper around my_load_defaults() for interface compatibility.
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
load_defaults()
|
|
|
|
conf_file Basename for configuration file to search for.
|
|
|
|
If this is a path, then only this file is read.
|
|
|
|
groups Which [group] entrys to read.
|
|
|
|
Points to an null terminated array of pointers
|
|
|
|
argc Pointer to argc of original program
|
|
|
|
argv Pointer to argv of original program
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
|
|
|
|
This function is NOT thread-safe as it uses a global pointer internally.
|
|
|
|
See also notes for my_load_defaults().
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 ok
|
|
|
|
1 The given conf_file didn't exists
|
|
|
|
*/
|
|
|
|
int load_defaults(const char *conf_file, const char **groups,
|
|
|
|
int *argc, char ***argv)
|
|
|
|
{
|
|
|
|
return my_load_defaults(conf_file, groups, argc, argv, &default_directories);
|
|
|
|
}
|
2005-01-03 16:21:54 +01:00
|
|
|
|
2003-08-28 05:08:17 +02:00
|
|
|
/*
|
|
|
|
Read options from configurations files
|
|
|
|
|
|
|
|
SYNOPSIS
|
2009-02-27 10:26:06 +01:00
|
|
|
my_load_defaults()
|
2003-08-28 05:08:17 +02:00
|
|
|
conf_file Basename for configuration file to search for.
|
|
|
|
If this is a path, then only this file is read.
|
|
|
|
groups Which [group] entrys to read.
|
|
|
|
Points to an null terminated array of pointers
|
|
|
|
argc Pointer to argc of original program
|
|
|
|
argv Pointer to argv of original program
|
2009-02-27 10:26:06 +01:00
|
|
|
default_directories Pointer to a location where a pointer to the list
|
|
|
|
of default directories will be stored
|
2003-08-28 05:08:17 +02:00
|
|
|
|
|
|
|
IMPLEMENTATION
|
|
|
|
|
|
|
|
Read options from configuration files and put them BEFORE the arguments
|
|
|
|
that are already in argc and argv. This way the calling program can
|
|
|
|
easily command line options override options in configuration files
|
|
|
|
|
|
|
|
NOTES
|
|
|
|
In case of fatal error, the function will print a warning and do
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
To free used memory one should call free_defaults() with the argument
|
|
|
|
that was put in *argv
|
|
|
|
|
|
|
|
RETURN
|
2009-02-27 10:26:06 +01:00
|
|
|
- If successful, 0 is returned. If 'default_directories' is not NULL,
|
|
|
|
a pointer to the array of default directory paths is stored to a location
|
|
|
|
it points to. That stored value must be passed to my_search_option_files()
|
|
|
|
later.
|
|
|
|
|
|
|
|
- 1 is returned if the given conf_file didn't exist. In this case, the
|
|
|
|
value pointed to by default_directories is undefined.
|
2003-08-28 05:08:17 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
2009-02-27 10:26:06 +01:00
|
|
|
int my_load_defaults(const char *conf_file, const char **groups,
|
|
|
|
int *argc, char ***argv, const char ***default_directories)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
DYNAMIC_ARRAY args;
|
|
|
|
TYPELIB group;
|
2005-07-06 19:49:43 +02:00
|
|
|
my_bool found_print_defaults= 0;
|
|
|
|
uint args_used= 0;
|
2003-08-27 18:22:14 +02:00
|
|
|
int error= 0;
|
2000-07-31 21:29:14 +02:00
|
|
|
MEM_ROOT alloc;
|
|
|
|
char *ptr,**res;
|
2004-08-30 16:17:50 +02:00
|
|
|
struct handle_option_ctx ctx;
|
2009-02-27 10:26:06 +01:00
|
|
|
const char **dirs;
|
2000-07-31 21:29:14 +02:00
|
|
|
DBUG_ENTER("load_defaults");
|
|
|
|
|
2002-07-23 17:31:22 +02:00
|
|
|
init_alloc_root(&alloc,512,0);
|
2009-02-27 10:26:06 +01:00
|
|
|
if ((dirs= init_default_directories(&alloc)) == NULL)
|
2008-06-25 03:25:23 +02:00
|
|
|
goto err;
|
2005-07-18 14:33:18 +02:00
|
|
|
/*
|
|
|
|
Check if the user doesn't want any default option processing
|
|
|
|
--no-defaults is always the first option
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
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];
|
2002-01-31 03:36:58 +01:00
|
|
|
res[i-1]=0; /* End pointer */
|
2000-07-31 21:29:14 +02:00
|
|
|
(*argc)--;
|
|
|
|
*argv=res;
|
|
|
|
*(MEM_ROOT*) ptr= alloc; /* Save alloc root for free */
|
2009-02-27 10:26:06 +01:00
|
|
|
if (default_directories)
|
|
|
|
*default_directories= dirs;
|
2003-08-28 05:08:17 +02:00
|
|
|
DBUG_RETURN(0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
group.count=0;
|
|
|
|
group.name= "defaults";
|
|
|
|
group.type_names= groups;
|
2004-08-30 16:17:50 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
for (; *groups ; groups++)
|
|
|
|
group.count++;
|
|
|
|
|
2002-04-28 23:22:37 +02:00
|
|
|
if (my_init_dynamic_array(&args, sizeof(char*),*argc, 32))
|
2000-07-31 21:29:14 +02:00
|
|
|
goto err;
|
2004-08-30 16:17:50 +02:00
|
|
|
|
|
|
|
ctx.alloc= &alloc;
|
|
|
|
ctx.args= &args;
|
|
|
|
ctx.group= &group;
|
2005-03-29 11:55:11 +02:00
|
|
|
|
2005-02-18 12:58:30 +01:00
|
|
|
error= my_search_option_files(conf_file, argc, argv, &args_used,
|
2009-02-27 10:26:06 +01:00
|
|
|
handle_default_option, (void *) &ctx,
|
|
|
|
dirs);
|
2003-08-28 05:08:17 +02:00
|
|
|
/*
|
|
|
|
Here error contains <> 0 only if we have a fully specified conf_file
|
|
|
|
or a forced default file
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
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 */
|
2003-11-03 13:01:59 +01:00
|
|
|
res[0]= argv[0][0]; /* Name MUST be set, even by embedded library */
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
memcpy((uchar*) (res+1), args.buffer, args.elements*sizeof(char*));
|
2005-07-18 14:33:18 +02:00
|
|
|
/* Skip --defaults-xxx options */
|
2000-10-06 20:15:03 +02:00
|
|
|
(*argc)-= args_used;
|
|
|
|
(*argv)+= args_used;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-07-18 14:33:18 +02:00
|
|
|
/*
|
|
|
|
Check if we wan't to see the new argument list
|
|
|
|
This options must always be the last of the default options
|
|
|
|
*/
|
2000-07-31 21:29:14 +02:00
|
|
|
if (*argc >= 2 && !strcmp(argv[0][1],"--print-defaults"))
|
|
|
|
{
|
|
|
|
found_print_defaults=1;
|
2004-02-02 17:25:39 +01:00
|
|
|
--*argc; ++*argv; /* skip argument */
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
2003-04-16 11:49:46 +02:00
|
|
|
if (*argc)
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
memcpy((uchar*) (res+1+args.elements), (char*) ((*argv)+1),
|
2003-04-16 11:49:46 +02:00
|
|
|
(*argc-1)*sizeof(char*));
|
2000-07-31 21:29:14 +02:00
|
|
|
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("");
|
2003-08-28 05:08:17 +02:00
|
|
|
exit(0);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2009-02-27 10:26:06 +01:00
|
|
|
|
|
|
|
if (error == 0 && default_directories)
|
|
|
|
*default_directories= dirs;
|
|
|
|
|
2003-08-28 05:08:17 +02:00
|
|
|
DBUG_RETURN(error);
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
err:
|
2003-08-28 05:08:17 +02:00
|
|
|
fprintf(stderr,"Fatal error in defaults handling. Program aborted\n");
|
2000-07-31 21:29:14 +02:00
|
|
|
exit(1);
|
2003-11-21 00:53:01 +01:00
|
|
|
return 0; /* Keep compiler happy */
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void free_defaults(char **argv)
|
|
|
|
{
|
|
|
|
MEM_ROOT ptr;
|
|
|
|
memcpy_fixed((char*) &ptr,(char *) argv - sizeof(ptr), sizeof(ptr));
|
2000-09-12 02:02:33 +02:00
|
|
|
free_root(&ptr,MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-11-12 18:58:24 +01:00
|
|
|
static int search_default_file(Process_option_func opt_handler,
|
|
|
|
void *handler_ctx,
|
2004-11-11 15:59:36 +01:00
|
|
|
const char *dir,
|
2004-11-12 18:58:24 +01:00
|
|
|
const char *config_file)
|
2004-11-11 15:59:36 +01:00
|
|
|
{
|
|
|
|
char **ext;
|
2005-04-28 21:11:48 +02:00
|
|
|
const char *empty_list[]= { "", 0 };
|
|
|
|
my_bool have_ext= fn_ext(config_file)[0] != 0;
|
|
|
|
const char **exts_to_use= have_ext ? empty_list : f_extensions;
|
2004-11-11 15:59:36 +01:00
|
|
|
|
2006-11-20 21:42:06 +01:00
|
|
|
for (ext= (char**) exts_to_use; *ext; ext++)
|
2004-11-11 15:59:36 +01:00
|
|
|
{
|
|
|
|
int error;
|
2004-11-12 18:58:24 +01:00
|
|
|
if ((error= search_default_file_with_ext(opt_handler, handler_ctx,
|
|
|
|
dir, *ext,
|
2005-03-29 11:55:11 +02:00
|
|
|
config_file, 0)) < 0)
|
2004-11-11 15:59:36 +01:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-04-29 16:03:34 +02:00
|
|
|
/*
|
|
|
|
Skip over keyword and get argument after keyword
|
|
|
|
|
|
|
|
SYNOPSIS
|
|
|
|
get_argument()
|
|
|
|
keyword Include directive keyword
|
|
|
|
kwlen Length of keyword
|
|
|
|
ptr Pointer to the keword in the line under process
|
|
|
|
line line number
|
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 error
|
|
|
|
# Returns pointer to the argument after the keyword.
|
|
|
|
*/
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
static char *get_argument(const char *keyword, size_t kwlen,
|
2005-04-29 16:03:34 +02:00
|
|
|
char *ptr, char *name, uint line)
|
|
|
|
{
|
|
|
|
char *end;
|
|
|
|
|
|
|
|
/* Skip over "include / includedir keyword" and following whitespace */
|
|
|
|
|
|
|
|
for (ptr+= kwlen - 1;
|
|
|
|
my_isspace(&my_charset_latin1, ptr[0]);
|
|
|
|
ptr++)
|
|
|
|
{}
|
|
|
|
|
|
|
|
/*
|
|
|
|
Trim trailing whitespace from directory name
|
|
|
|
The -1 below is for the newline added by fgets()
|
|
|
|
Note that my_isspace() is true for \r and \n
|
|
|
|
*/
|
|
|
|
for (end= ptr + strlen(ptr) - 1;
|
|
|
|
my_isspace(&my_charset_latin1, *(end - 1));
|
|
|
|
end--)
|
|
|
|
{}
|
|
|
|
end[0]= 0; /* Cut off end space */
|
|
|
|
|
|
|
|
/* Print error msg if there is nothing after !include* directive */
|
|
|
|
if (end <= ptr)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"error: Wrong '!%s' directive in config file: %s at line %d\n",
|
|
|
|
keyword, name, line);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-08-27 18:22:14 +02:00
|
|
|
/*
|
2003-08-28 05:08:17 +02:00
|
|
|
Open a configuration file (if exists) and read given options from it
|
2005-03-25 02:13:30 +01:00
|
|
|
|
2003-08-28 05:08:17 +02:00
|
|
|
SYNOPSIS
|
2004-11-11 15:59:36 +01:00
|
|
|
search_default_file_with_ext()
|
2004-08-30 16:17:50 +02:00
|
|
|
opt_handler Option handler function. It is used to process
|
|
|
|
every separate option.
|
|
|
|
handler_ctx Pointer to the structure to store actual
|
|
|
|
parameters of the function.
|
2003-08-28 05:08:17 +02:00
|
|
|
dir directory to read
|
|
|
|
ext Extension for configuration file
|
2005-03-25 02:13:30 +01:00
|
|
|
config_file Name of configuration file
|
2003-08-28 05:08:17 +02:00
|
|
|
group groups to read
|
2005-03-25 02:13:30 +01:00
|
|
|
recursion_level the level of recursion, got while processing
|
|
|
|
"!include" or "!includedir"
|
2003-08-28 05:08:17 +02:00
|
|
|
|
|
|
|
RETURN
|
|
|
|
0 Success
|
|
|
|
-1 Fatal error, abort
|
|
|
|
1 File not found (Warning)
|
2003-08-27 18:22:14 +02:00
|
|
|
*/
|
|
|
|
|
2004-11-12 18:58:24 +01:00
|
|
|
static int search_default_file_with_ext(Process_option_func opt_handler,
|
|
|
|
void *handler_ctx,
|
|
|
|
const char *dir,
|
|
|
|
const char *ext,
|
2005-03-29 11:55:11 +02:00
|
|
|
const char *config_file,
|
|
|
|
int recursion_level)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-03-29 11:55:11 +02:00
|
|
|
char name[FN_REFLEN + 10], buff[4096], curr_gr[4096], *ptr, *end, **tmp_ext;
|
2005-03-29 14:15:22 +02:00
|
|
|
char *value, option[4096], tmp[FN_REFLEN];
|
2005-03-25 02:13:30 +01:00
|
|
|
static const char includedir_keyword[]= "includedir";
|
|
|
|
static const char include_keyword[]= "include";
|
|
|
|
const int max_recursion_level= 10;
|
2000-07-31 21:29:14 +02:00
|
|
|
FILE *fp;
|
|
|
|
uint line=0;
|
2004-08-30 16:17:50 +02:00
|
|
|
my_bool found_group=0;
|
2005-03-25 02:13:30 +01:00
|
|
|
uint i;
|
|
|
|
MY_DIR *search_dir;
|
|
|
|
FILEINFO *search_file;
|
2000-07-31 21:29:14 +02:00
|
|
|
|
|
|
|
if ((dir ? strlen(dir) : 0 )+strlen(config_file) >= FN_REFLEN-3)
|
|
|
|
return 0; /* Ignore wrong paths */
|
|
|
|
if (dir)
|
|
|
|
{
|
2001-10-08 03:58:07 +02:00
|
|
|
end=convert_dirname(name, dir, NullS);
|
2000-07-31 21:29:14 +02:00
|
|
|
if (dir[0] == FN_HOMELIB) /* Add . to filenames in home */
|
2001-10-08 03:58:07 +02:00
|
|
|
*end++='.';
|
|
|
|
strxmov(end,config_file,ext,NullS);
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
strmov(name,config_file);
|
|
|
|
}
|
2003-03-10 12:31:49 +01:00
|
|
|
fn_format(name,name,"","",4);
|
2006-04-15 17:49:00 +02:00
|
|
|
#if !defined(__WIN__) && !defined(__NETWARE__)
|
2003-03-10 12:31:49 +01:00
|
|
|
{
|
|
|
|
MY_STAT stat_info;
|
2003-03-10 13:16:59 +01:00
|
|
|
if (!my_stat(name,&stat_info,MYF(0)))
|
2003-08-28 05:08:17 +02:00
|
|
|
return 1;
|
2003-04-28 11:31:19 +02:00
|
|
|
/*
|
|
|
|
Ignore world-writable regular files.
|
|
|
|
This is mainly done to protect us to not read a file created by
|
|
|
|
the mysqld server, but the check is still valid in most context.
|
|
|
|
*/
|
|
|
|
if ((stat_info.st_mode & S_IWOTH) &&
|
|
|
|
(stat_info.st_mode & S_IFMT) == S_IFREG)
|
2003-03-10 13:16:59 +01:00
|
|
|
{
|
2005-04-06 16:22:21 +02:00
|
|
|
fprintf(stderr, "Warning: World-writable config file '%s' is ignored\n",
|
2003-03-10 13:16:59 +01:00
|
|
|
name);
|
2003-03-10 12:31:49 +01:00
|
|
|
return 0;
|
2003-03-10 13:16:59 +01:00
|
|
|
}
|
2003-03-10 12:31:49 +01:00
|
|
|
}
|
|
|
|
#endif
|
2005-04-06 16:22:21 +02:00
|
|
|
if (!(fp= my_fopen(name, O_RDONLY, MYF(0))))
|
2005-05-06 13:51:58 +02:00
|
|
|
return 1; /* Ignore wrong files */
|
2000-07-31 21:29:14 +02:00
|
|
|
|
2005-03-25 02:13:30 +01:00
|
|
|
while (fgets(buff, sizeof(buff) - 1, fp))
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
|
|
|
line++;
|
|
|
|
/* Ignore comment and empty lines */
|
2005-03-25 02:13:30 +01:00
|
|
|
for (ptr= buff; my_isspace(&my_charset_latin1, *ptr); ptr++)
|
|
|
|
{}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
if (*ptr == '#' || *ptr == ';' || !*ptr)
|
|
|
|
continue;
|
2005-03-25 02:13:30 +01:00
|
|
|
|
|
|
|
/* Configuration File Directives */
|
2005-04-26 22:24:59 +02:00
|
|
|
if ((*ptr == '!'))
|
2005-03-25 02:13:30 +01:00
|
|
|
{
|
2005-04-26 22:24:59 +02:00
|
|
|
if (recursion_level >= max_recursion_level)
|
|
|
|
{
|
|
|
|
for (end= ptr + strlen(ptr) - 1;
|
|
|
|
my_isspace(&my_charset_latin1, *(end - 1));
|
|
|
|
end--)
|
|
|
|
{}
|
|
|
|
end[0]= 0;
|
|
|
|
fprintf(stderr,
|
|
|
|
"Warning: skipping '%s' directive as maximum include"
|
|
|
|
"recursion level was reached in file %s at line %d\n",
|
|
|
|
ptr, name, line);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2005-03-25 02:13:30 +01:00
|
|
|
/* skip over `!' and following whitespace */
|
|
|
|
for (++ptr; my_isspace(&my_charset_latin1, ptr[0]); ptr++)
|
|
|
|
{}
|
|
|
|
|
2005-04-26 22:24:59 +02:00
|
|
|
if ((!strncmp(ptr, includedir_keyword,
|
|
|
|
sizeof(includedir_keyword) - 1)) &&
|
|
|
|
my_isspace(&my_charset_latin1, ptr[sizeof(includedir_keyword) - 1]))
|
2005-03-25 02:13:30 +01:00
|
|
|
{
|
2005-04-29 16:03:34 +02:00
|
|
|
if (!(ptr= get_argument(includedir_keyword,
|
|
|
|
sizeof(includedir_keyword),
|
|
|
|
ptr, name, line)))
|
|
|
|
goto err;
|
2005-03-25 02:13:30 +01:00
|
|
|
|
|
|
|
if (!(search_dir= my_dir(ptr, MYF(MY_WME))))
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
for (i= 0; i < (uint) search_dir->number_off_files; i++)
|
|
|
|
{
|
|
|
|
search_file= search_dir->dir_entry + i;
|
|
|
|
ext= fn_ext(search_file->name);
|
|
|
|
|
2005-04-13 23:39:24 +02:00
|
|
|
/* check extension */
|
2006-11-20 21:42:06 +01:00
|
|
|
for (tmp_ext= (char**) f_extensions; *tmp_ext; tmp_ext++)
|
2005-03-25 02:13:30 +01:00
|
|
|
{
|
|
|
|
if (!strcmp(ext, *tmp_ext))
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (*tmp_ext)
|
|
|
|
{
|
|
|
|
fn_format(tmp, search_file->name, ptr, "",
|
|
|
|
MY_UNPACK_FILENAME | MY_SAFE_PATH);
|
|
|
|
|
2005-03-29 14:15:22 +02:00
|
|
|
search_default_file_with_ext(opt_handler, handler_ctx, "", "", tmp,
|
2005-03-25 02:13:30 +01:00
|
|
|
recursion_level + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
my_dirend(search_dir);
|
|
|
|
}
|
2005-04-26 22:24:59 +02:00
|
|
|
else if ((!strncmp(ptr, include_keyword, sizeof(include_keyword) - 1)) &&
|
|
|
|
my_isspace(&my_charset_latin1, ptr[sizeof(include_keyword)-1]))
|
2005-03-25 02:13:30 +01:00
|
|
|
{
|
2005-04-29 16:03:34 +02:00
|
|
|
if (!(ptr= get_argument(include_keyword,
|
|
|
|
sizeof(include_keyword), ptr,
|
|
|
|
name, line)))
|
|
|
|
goto err;
|
2005-03-25 02:13:30 +01:00
|
|
|
|
2005-03-29 14:15:22 +02:00
|
|
|
search_default_file_with_ext(opt_handler, handler_ctx, "", "", ptr,
|
2005-03-25 02:13:30 +01:00
|
|
|
recursion_level + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
/* Remove end space */
|
|
|
|
for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
|
2000-07-31 21:29:14 +02:00
|
|
|
end[0]=0;
|
2004-08-30 16:17:50 +02:00
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
strmake(curr_gr, ptr, min((size_t) (end-ptr)+1, sizeof(curr_gr)-1));
|
2006-05-18 16:57:50 +02:00
|
|
|
|
|
|
|
/* signal that a new group is found */
|
|
|
|
opt_handler(handler_ctx, curr_gr, NULL);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!found_group)
|
|
|
|
{
|
|
|
|
fprintf(stderr,
|
|
|
|
"error: Found option without preceding group in config file: %s at line: %d\n",
|
|
|
|
name,line);
|
|
|
|
goto err;
|
|
|
|
}
|
2004-08-30 16:17:50 +02:00
|
|
|
|
|
|
|
|
2003-05-14 15:47:55 +02:00
|
|
|
end= remove_end_comment(ptr);
|
|
|
|
if ((value= strchr(ptr, '=')))
|
|
|
|
end= value; /* Option without argument */
|
2003-03-16 09:30:10 +01:00
|
|
|
for ( ; my_isspace(&my_charset_latin1,end[-1]) ; end--) ;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (!value)
|
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
strmake(strmov(option,"--"),ptr, (size_t) (end-ptr));
|
2004-08-30 16:17:50 +02:00
|
|
|
if (opt_handler(handler_ctx, curr_gr, option))
|
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Remove pre- and end space */
|
|
|
|
char *value_end;
|
2003-03-16 09:30:10 +01:00
|
|
|
for (value++ ; my_isspace(&my_charset_latin1,*value); value++) ;
|
2000-07-31 21:29:14 +02:00
|
|
|
value_end=strend(value);
|
2003-09-23 16:06:44 +02:00
|
|
|
/*
|
|
|
|
We don't have to test for value_end >= value as we know there is
|
|
|
|
an '=' before
|
|
|
|
*/
|
2003-03-16 09:30:10 +01:00
|
|
|
for ( ; my_isspace(&my_charset_latin1,value_end[-1]) ; value_end--) ;
|
2000-07-31 21:29:14 +02:00
|
|
|
if (value_end < value) /* Empty string */
|
|
|
|
value_end=value;
|
2003-09-23 16:06:44 +02:00
|
|
|
|
|
|
|
/* remove quotes around argument */
|
2006-05-11 14:13:14 +02:00
|
|
|
if ((*value == '\"' || *value == '\'') && /* First char is quote */
|
|
|
|
(value + 1 < value_end ) && /* String is longer than 1 */
|
|
|
|
*value == value_end[-1] ) /* First char is equal to last char */
|
2003-09-23 16:06:44 +02:00
|
|
|
{
|
|
|
|
value++;
|
|
|
|
value_end--;
|
|
|
|
}
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
ptr=strnmov(strmov(option,"--"),ptr,(size_t) (end-ptr));
|
2000-07-31 21:29:14 +02:00
|
|
|
*ptr++= '=';
|
2003-09-23 16:06:44 +02:00
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
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;
|
2003-09-17 20:08:40 +02:00
|
|
|
case '\"':
|
|
|
|
*ptr++= '\"';
|
|
|
|
break;
|
|
|
|
case '\'':
|
|
|
|
*ptr++= '\'';
|
|
|
|
break;
|
2000-07-31 21:29:14 +02:00
|
|
|
case '\\':
|
|
|
|
*ptr++= '\\';
|
|
|
|
break;
|
|
|
|
default: /* Unknown; Keep '\' */
|
|
|
|
*ptr++= '\\';
|
|
|
|
*ptr++= *value;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
*ptr++= *value;
|
|
|
|
}
|
|
|
|
*ptr=0;
|
2004-08-30 16:17:50 +02:00
|
|
|
if (opt_handler(handler_ctx, curr_gr, option))
|
|
|
|
goto err;
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
my_fclose(fp,MYF(0));
|
|
|
|
return(0);
|
|
|
|
|
|
|
|
err:
|
|
|
|
my_fclose(fp,MYF(0));
|
2003-08-28 05:08:17 +02:00
|
|
|
return -1; /* Fatal error */
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-14 15:47:55 +02:00
|
|
|
static char *remove_end_comment(char *ptr)
|
|
|
|
{
|
2004-03-20 22:50:04 +01:00
|
|
|
char quote= 0; /* we are inside quote marks */
|
|
|
|
char escape= 0; /* symbol is protected by escape chagacter */
|
2003-05-14 15:47:55 +02:00
|
|
|
|
|
|
|
for (; *ptr; ptr++)
|
|
|
|
{
|
2004-03-20 22:50:04 +01:00
|
|
|
if ((*ptr == '\'' || *ptr == '\"') && !escape)
|
2003-05-14 15:47:55 +02:00
|
|
|
{
|
|
|
|
if (!quote)
|
|
|
|
quote= *ptr;
|
|
|
|
else if (quote == *ptr)
|
|
|
|
quote= 0;
|
|
|
|
}
|
2004-03-25 22:29:45 +01:00
|
|
|
/* We are not inside a string */
|
2004-01-23 14:31:16 +01:00
|
|
|
if (!quote && *ptr == '#')
|
2003-05-14 15:47:55 +02:00
|
|
|
{
|
|
|
|
*ptr= 0;
|
|
|
|
return ptr;
|
|
|
|
}
|
2004-03-20 22:50:04 +01:00
|
|
|
escape= (quote && *ptr == '\\' && !escape);
|
2003-05-14 15:47:55 +02:00
|
|
|
}
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
2004-05-25 21:00:14 +02:00
|
|
|
#include <help_start.h>
|
2003-05-14 15:47:55 +02:00
|
|
|
|
2005-04-28 21:11:48 +02:00
|
|
|
void my_print_default_files(const char *conf_file)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2005-04-28 21:11:48 +02:00
|
|
|
const char *empty_list[]= { "", 0 };
|
2004-11-11 15:59:36 +01:00
|
|
|
my_bool have_ext= fn_ext(conf_file)[0] != 0;
|
2005-04-28 21:11:48 +02:00
|
|
|
const char **exts_to_use= have_ext ? empty_list : f_extensions;
|
2004-11-05 17:59:19 +01:00
|
|
|
char name[FN_REFLEN], **ext;
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
puts("\nDefault options are read from the following files in the given order:");
|
|
|
|
|
|
|
|
if (dirname_length(conf_file))
|
|
|
|
fputs(conf_file,stdout);
|
|
|
|
else
|
|
|
|
{
|
2009-02-27 10:26:06 +01:00
|
|
|
const char **dirs;
|
2008-06-25 03:25:23 +02:00
|
|
|
MEM_ROOT alloc;
|
|
|
|
init_alloc_root(&alloc,512,0);
|
|
|
|
|
2009-02-27 10:26:06 +01:00
|
|
|
if ((dirs= init_default_directories(&alloc)) == NULL)
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
fputs("Internal error initializing default directories list", stdout);
|
|
|
|
}
|
|
|
|
else
|
2000-07-31 21:29:14 +02:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
for ( ; *dirs; dirs++)
|
2004-11-05 17:59:19 +01:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
for (ext= (char**) exts_to_use; *ext; ext++)
|
|
|
|
{
|
|
|
|
const char *pos;
|
|
|
|
char *end;
|
|
|
|
if (**dirs)
|
|
|
|
pos= *dirs;
|
|
|
|
else if (my_defaults_extra_file)
|
|
|
|
pos= my_defaults_extra_file;
|
|
|
|
else
|
|
|
|
continue;
|
|
|
|
end= convert_dirname(name, pos, NullS);
|
|
|
|
if (name[0] == FN_HOMELIB) /* Add . to filenames in home */
|
|
|
|
*end++= '.';
|
|
|
|
strxmov(end, conf_file, *ext, " ", NullS);
|
|
|
|
fputs(name, stdout);
|
|
|
|
}
|
2004-11-05 17:59:19 +01:00
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2008-06-25 03:25:23 +02:00
|
|
|
|
|
|
|
free_root(&alloc, MYF(0));
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2007-04-28 01:27:54 +02:00
|
|
|
puts("");
|
2005-04-28 21:11:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_defaults(const char *conf_file, const char **groups)
|
|
|
|
{
|
2005-06-07 16:52:50 +02:00
|
|
|
const char **groups_save= groups;
|
2005-04-28 21:11:48 +02:00
|
|
|
my_print_default_files(conf_file);
|
|
|
|
|
2000-07-31 21:29:14 +02:00
|
|
|
fputs("The following groups are read:",stdout);
|
|
|
|
for ( ; *groups ; groups++)
|
|
|
|
{
|
|
|
|
fputc(' ',stdout);
|
|
|
|
fputs(*groups,stdout);
|
|
|
|
}
|
2005-06-07 16:52:50 +02:00
|
|
|
|
2006-12-14 23:51:37 +01:00
|
|
|
if (my_defaults_group_suffix)
|
2005-06-07 16:52:50 +02:00
|
|
|
{
|
|
|
|
groups= groups_save;
|
|
|
|
for ( ; *groups ; groups++)
|
|
|
|
{
|
|
|
|
fputc(' ',stdout);
|
|
|
|
fputs(*groups,stdout);
|
2006-12-14 23:51:37 +01:00
|
|
|
fputs(my_defaults_group_suffix,stdout);
|
2005-06-07 16:52:50 +02:00
|
|
|
}
|
|
|
|
}
|
2000-07-31 21:29:14 +02:00
|
|
|
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\
|
2000-10-10 23:06:37 +02:00
|
|
|
--defaults-file=# Only read default options from the given file #\n\
|
|
|
|
--defaults-extra-file=# Read this file after the global files are read");
|
2000-07-31 21:29:14 +02:00
|
|
|
}
|
2004-05-25 21:00:14 +02:00
|
|
|
|
|
|
|
#include <help_end.h>
|
2005-01-04 19:13:47 +01:00
|
|
|
|
2005-04-28 21:11:48 +02:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
static int add_directory(MEM_ROOT *alloc, const char *dir, const char **dirs)
|
|
|
|
{
|
|
|
|
char buf[FN_REFLEN];
|
2009-02-13 17:41:47 +01:00
|
|
|
size_t len;
|
2008-06-25 03:25:23 +02:00
|
|
|
char *p;
|
|
|
|
my_bool err __attribute__((unused));
|
|
|
|
|
2008-07-17 00:58:45 +02:00
|
|
|
len= normalize_dirname(buf, dir);
|
2008-06-25 03:25:23 +02:00
|
|
|
if (!(p= strmake_root(alloc, buf, len)))
|
|
|
|
return 1; /* Failure */
|
|
|
|
/* Should never fail if DEFAULT_DIRS_SIZE is correct size */
|
|
|
|
err= array_append_string_unique(p, dirs, DEFAULT_DIRS_SIZE);
|
|
|
|
DBUG_ASSERT(err == FALSE);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2007-11-07 23:23:50 +01:00
|
|
|
|
|
|
|
|
2005-07-06 19:49:43 +02:00
|
|
|
#ifdef __WIN__
|
|
|
|
/*
|
|
|
|
This wrapper for GetSystemWindowsDirectory() will dynamically bind to the
|
|
|
|
function if it is available, emulate it on NT4 Terminal Server by stripping
|
|
|
|
the \SYSTEM32 from the end of the results of GetSystemDirectory(), or just
|
|
|
|
return GetSystemDirectory().
|
|
|
|
*/
|
|
|
|
|
|
|
|
typedef UINT (WINAPI *GET_SYSTEM_WINDOWS_DIRECTORY)(LPSTR, UINT);
|
|
|
|
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
static size_t my_get_system_windows_directory(char *buffer, size_t size)
|
2005-07-06 19:49:43 +02:00
|
|
|
{
|
WL#3817: Simplify string / memory area types and make things more consistent (first part)
The following type conversions was done:
- Changed byte to uchar
- Changed gptr to uchar*
- Change my_string to char *
- Change my_size_t to size_t
- Change size_s to size_t
Removed declaration of byte, gptr, my_string, my_size_t and size_s.
Following function parameter changes was done:
- All string functions in mysys/strings was changed to use size_t
instead of uint for string lengths.
- All read()/write() functions changed to use size_t (including vio).
- All protocoll functions changed to use size_t instead of uint
- Functions that used a pointer to a string length was changed to use size_t*
- Changed malloc(), free() and related functions from using gptr to use void *
as this requires fewer casts in the code and is more in line with how the
standard functions work.
- Added extra length argument to dirname_part() to return the length of the
created string.
- Changed (at least) following functions to take uchar* as argument:
- db_dump()
- my_net_write()
- net_write_command()
- net_store_data()
- DBUG_DUMP()
- decimal2bin() & bin2decimal()
- Changed my_compress() and my_uncompress() to use size_t. Changed one
argument to my_uncompress() from a pointer to a value as we only return
one value (makes function easier to use).
- Changed type of 'pack_data' argument to packfrm() to avoid casts.
- Changed in readfrm() and writefrom(), ha_discover and handler::discover()
the type for argument 'frmdata' to uchar** to avoid casts.
- Changed most Field functions to use uchar* instead of char* (reduced a lot of
casts).
- Changed field->val_xxx(xxx, new_ptr) to take const pointers.
Other changes:
- Removed a lot of not needed casts
- Added a few new cast required by other changes
- Added some cast to my_multi_malloc() arguments for safety (as string lengths
needs to be uint, not size_t).
- Fixed all calls to hash-get-key functions to use size_t*. (Needed to be done
explicitely as this conflict was often hided by casting the function to
hash_get_key).
- Changed some buffers to memory regions to uchar* to avoid casts.
- Changed some string lengths from uint to size_t.
- Changed field->ptr to be uchar* instead of char*. This allowed us to
get rid of a lot of casts.
- Some changes from true -> TRUE, false -> FALSE, unsigned char -> uchar
- Include zlib.h in some files as we needed declaration of crc32()
- Changed MY_FILE_ERROR to be (size_t) -1.
- Changed many variables to hold the result of my_read() / my_write() to be
size_t. This was needed to properly detect errors (which are
returned as (size_t) -1).
- Removed some very old VMS code
- Changed packfrm()/unpackfrm() to not be depending on uint size
(portability fix)
- Removed windows specific code to restore cursor position as this
causes slowdown on windows and we should not mix read() and pread()
calls anyway as this is not thread safe. Updated function comment to
reflect this. Changed function that depended on original behavior of
my_pwrite() to itself restore the cursor position (one such case).
- Added some missing checking of return value of malloc().
- Changed definition of MOD_PAD_CHAR_TO_FULL_LENGTH to avoid 'long' overflow.
- Changed type of table_def::m_size from my_size_t to ulong to reflect that
m_size is the number of elements in the array, not a string/memory
length.
- Moved THD::max_row_length() to table.cc (as it's not depending on THD).
Inlined max_row_length_blob() into this function.
- More function comments
- Fixed some compiler warnings when compiled without partitions.
- Removed setting of LEX_STRING() arguments in declaration (portability fix).
- Some trivial indentation/variable name changes.
- Some trivial code simplifications:
- Replaced some calls to alloc_root + memcpy to use
strmake_root()/strdup_root().
- Changed some calls from memdup() to strmake() (Safety fix)
- Simpler loops in client-simple.c
2007-05-10 11:59:39 +02:00
|
|
|
size_t count;
|
2005-07-06 19:49:43 +02:00
|
|
|
GET_SYSTEM_WINDOWS_DIRECTORY
|
|
|
|
func_ptr= (GET_SYSTEM_WINDOWS_DIRECTORY)
|
|
|
|
GetProcAddress(GetModuleHandle("kernel32.dll"),
|
|
|
|
"GetSystemWindowsDirectoryA");
|
|
|
|
|
|
|
|
if (func_ptr)
|
2009-02-13 17:41:47 +01:00
|
|
|
return func_ptr(buffer, (uint) size);
|
2005-07-06 19:49:43 +02:00
|
|
|
|
2005-07-28 15:10:14 +02:00
|
|
|
/*
|
|
|
|
Windows NT 4.0 Terminal Server Edition:
|
|
|
|
To retrieve the shared Windows directory, call GetSystemDirectory and
|
|
|
|
trim the "System32" element from the end of the returned path.
|
|
|
|
*/
|
2009-02-13 17:41:47 +01:00
|
|
|
count= GetSystemDirectory(buffer, (uint) size);
|
2005-07-28 15:10:14 +02:00
|
|
|
if (count > 8 && stricmp(buffer+(count-8), "\\System32") == 0)
|
|
|
|
{
|
|
|
|
count-= 8;
|
|
|
|
buffer[count] = '\0';
|
2005-07-06 19:49:43 +02:00
|
|
|
}
|
2005-07-28 15:10:14 +02:00
|
|
|
return count;
|
2005-07-06 19:49:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
static const char *my_get_module_parent(char *buf, size_t size)
|
2005-01-04 19:13:47 +01:00
|
|
|
{
|
2008-07-02 16:37:29 +02:00
|
|
|
char *last= NULL;
|
|
|
|
char *end;
|
2008-07-09 12:03:48 +02:00
|
|
|
if (!GetModuleFileName(NULL, buf, (DWORD) size))
|
2008-06-25 03:25:23 +02:00
|
|
|
return NULL;
|
2008-07-02 16:37:29 +02:00
|
|
|
end= strend(buf);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
/*
|
|
|
|
Look for the second-to-last \ in the filename, but hang on
|
|
|
|
to a pointer after the last \ in case we're in the root of
|
|
|
|
a drive.
|
|
|
|
*/
|
|
|
|
for ( ; end > buf; end--)
|
2005-07-06 19:49:43 +02:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
if (*end == FN_LIBCHAR)
|
2005-07-06 19:49:43 +02:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
if (last)
|
2005-07-06 19:49:43 +02:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
/* Keep the last '\' as this works both with D:\ and a directory */
|
|
|
|
end[1]= 0;
|
|
|
|
break;
|
2005-07-06 19:49:43 +02:00
|
|
|
}
|
2008-06-25 03:25:23 +02:00
|
|
|
last= end;
|
2005-07-06 19:49:43 +02:00
|
|
|
}
|
|
|
|
}
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
return buf;
|
2007-11-07 23:23:50 +01:00
|
|
|
}
|
2008-06-25 03:25:23 +02:00
|
|
|
#endif /* __WIN__ */
|
2007-11-07 23:23:50 +01:00
|
|
|
|
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
static const char **init_default_directories(MEM_ROOT *alloc)
|
2007-11-07 23:23:50 +01:00
|
|
|
{
|
2008-06-25 03:25:23 +02:00
|
|
|
const char **dirs;
|
|
|
|
char *env;
|
|
|
|
int errors= 0;
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
dirs= (const char **)alloc_root(alloc, DEFAULT_DIRS_SIZE * sizeof(char *));
|
|
|
|
if (dirs == NULL)
|
|
|
|
return NULL;
|
|
|
|
bzero((char *) dirs, DEFAULT_DIRS_SIZE * sizeof(char *));
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
#ifdef __WIN__
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
{
|
|
|
|
char fname_buffer[FN_REFLEN];
|
|
|
|
if (my_get_system_windows_directory(fname_buffer, sizeof(fname_buffer)))
|
|
|
|
errors += add_directory(alloc, fname_buffer, dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
if (GetWindowsDirectory(fname_buffer, sizeof(fname_buffer)))
|
|
|
|
errors += add_directory(alloc, fname_buffer, dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
errors += add_directory(alloc, "C:/", dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
if (my_get_module_parent(fname_buffer, sizeof(fname_buffer)) != NULL)
|
|
|
|
errors += add_directory(alloc, fname_buffer, dirs);
|
|
|
|
}
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
#elif defined(__NETWARE__)
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
errors += add_directory(alloc, "sys:/etc/", dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
#else
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
errors += add_directory(alloc, "/etc/", dirs);
|
2008-06-27 22:53:27 +02:00
|
|
|
errors += add_directory(alloc, "/etc/mysql/", dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-27 22:53:27 +02:00
|
|
|
#if defined(DEFAULT_SYSCONFDIR)
|
2009-03-19 21:20:15 +01:00
|
|
|
if (DEFAULT_SYSCONFDIR[0])
|
2008-06-25 03:25:23 +02:00
|
|
|
errors += add_directory(alloc, DEFAULT_SYSCONFDIR, dirs);
|
2008-06-27 22:53:27 +02:00
|
|
|
#endif /* DEFAULT_SYSCONFDIR */
|
2008-06-25 03:25:23 +02:00
|
|
|
|
2005-01-04 19:13:47 +01:00
|
|
|
#endif
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV))))
|
|
|
|
errors += add_directory(alloc, env, dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-25 03:25:23 +02:00
|
|
|
/* Placeholder for --defaults-extra-file=<path> */
|
|
|
|
errors += add_directory(alloc, "", dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
|
2008-06-27 22:53:27 +02:00
|
|
|
#if !defined(__WIN__) && !defined(__NETWARE__)
|
2008-06-25 03:25:23 +02:00
|
|
|
errors += add_directory(alloc, "~/", dirs);
|
2007-11-07 23:23:50 +01:00
|
|
|
#endif
|
2008-06-25 03:25:23 +02:00
|
|
|
|
|
|
|
return (errors > 0 ? NULL : dirs);
|
|
|
|
}
|