mirror of
https://github.com/MariaDB/server.git
synced 2026-01-06 05:22:24 +03:00
Cleanups during review
Changed defaults option --instance to --defaults-group-suffix Changed option handling to allow --defaults-file, --defaults-extra-file and --defaults-group-suffix to be given in any order Changed MYSQL_INSTANCE to MYSQL_GROUP_SUFFIX mysql_print_defaults now understands --defaults-group-suffix Remove usage of my_tempnam() (not safe function) if( -> if ( and while( to while (
This commit is contained in:
@@ -20,8 +20,7 @@
|
||||
#include <my_dir.h>
|
||||
|
||||
#define BUFF_SIZE 1024
|
||||
/* should be big enough to handle at least one line */
|
||||
#define RESERVE 1024
|
||||
#define RESERVE 1024 /* Extend buffer with this extent */
|
||||
|
||||
#ifdef __WIN__
|
||||
#define NEWLINE "\r\n"
|
||||
@@ -70,7 +69,7 @@ int modify_defaults_file(const char *file_location, const char *option,
|
||||
char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer;
|
||||
uint opt_len, optval_len, sect_len, nr_newlines= 0, buffer_size;
|
||||
my_bool in_section= FALSE, opt_applied= 0;
|
||||
uint reserve_extended= 1, old_opt_len= 0;
|
||||
uint reserve_extended;
|
||||
uint new_opt_len;
|
||||
int reserve_occupied= 0;
|
||||
DBUG_ENTER("modify_defaults_file");
|
||||
@@ -88,25 +87,21 @@ int modify_defaults_file(const char *file_location, const char *option,
|
||||
new_opt_len= opt_len + 1 + optval_len + NEWLINE_LEN;
|
||||
|
||||
/* calculate the size of the buffer we need */
|
||||
buffer_size= sizeof(char) * (file_stat.st_size +
|
||||
/* option name len */
|
||||
opt_len +
|
||||
/* reserve for '=' char */
|
||||
1 +
|
||||
/* option value len */
|
||||
optval_len +
|
||||
/* reserve space for newline */
|
||||
NEWLINE_LEN +
|
||||
/* The ending zero */
|
||||
1 +
|
||||
/* reserve some additional space */
|
||||
RESERVE);
|
||||
reserve_extended= (opt_len +
|
||||
1 + /* For '=' char */
|
||||
optval_len + /* Option value len */
|
||||
NEWLINE_LEN + /* Space for newline */
|
||||
RESERVE); /* Some additional space */
|
||||
|
||||
buffer_size= (file_stat.st_size +
|
||||
1); /* The ending zero */
|
||||
|
||||
/*
|
||||
Reserve space to read the contents of the file and some more
|
||||
for the option we want to add.
|
||||
*/
|
||||
if (!(file_buffer= (char*) my_malloc(buffer_size, MYF(MY_WME))))
|
||||
if (!(file_buffer= (char*) my_malloc(buffer_size + reserve_extended,
|
||||
MYF(MY_WME))))
|
||||
goto malloc_err;
|
||||
|
||||
sect_len= (uint) strlen(section_name);
|
||||
@@ -130,31 +125,20 @@ int modify_defaults_file(const char *file_location, const char *option,
|
||||
my_isspace(&my_charset_latin1, *(src_ptr + opt_len)) ||
|
||||
*(src_ptr + opt_len) == '\0'))
|
||||
{
|
||||
/*
|
||||
we should change all options. If opt_applied is set, we are running
|
||||
into reserved memory area. Hence we should check for overruns.
|
||||
*/
|
||||
if (opt_applied)
|
||||
char *old_src_ptr= src_ptr;
|
||||
src_ptr= strend(src_ptr+ opt_len); /* Find the end of the line */
|
||||
|
||||
/* could be negative */
|
||||
reserve_occupied+= (int) new_opt_len - (int) (src_ptr - old_src_ptr);
|
||||
if (reserve_occupied >= (int) reserve_extended)
|
||||
{
|
||||
src_ptr+= opt_len; /* If we correct an option, we know it's name */
|
||||
old_opt_len= opt_len;
|
||||
|
||||
while (*src_ptr++) /* Find the end of the line */
|
||||
old_opt_len++;
|
||||
|
||||
/* could be negative */
|
||||
reserve_occupied+= (int) new_opt_len - (int) old_opt_len;
|
||||
if ((int) reserve_occupied > (int) (RESERVE*reserve_extended))
|
||||
{
|
||||
if (!(file_buffer= (char*) my_realloc(file_buffer, buffer_size +
|
||||
RESERVE*reserve_extended,
|
||||
MYF(MY_WME|MY_FREE_ON_ERROR))))
|
||||
goto malloc_err;
|
||||
reserve_extended++;
|
||||
}
|
||||
reserve_extended= (uint) reserve_occupied + RESERVE;
|
||||
if (!(file_buffer= (char*) my_realloc(file_buffer, buffer_size +
|
||||
reserve_extended,
|
||||
MYF(MY_WME|MY_FREE_ON_ERROR))))
|
||||
goto malloc_err;
|
||||
}
|
||||
else
|
||||
opt_applied= 1;
|
||||
opt_applied= 1;
|
||||
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
|
||||
}
|
||||
else
|
||||
@@ -164,6 +148,7 @@ int modify_defaults_file(const char *file_location, const char *option,
|
||||
{
|
||||
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
|
||||
opt_applied= 1; /* set the flag to do write() later */
|
||||
reserve_occupied= new_opt_len+ opt_len + 1 + NEWLINE_LEN;
|
||||
}
|
||||
|
||||
for (; nr_newlines; nr_newlines--)
|
||||
|
||||
Reference in New Issue
Block a user