summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authormarty@linux.site <>2005-06-30 12:20:52 +0200
committermarty@linux.site <>2005-06-30 12:20:52 +0200
commite4aedcc2c137ba667e3d429031ce284032e11060 (patch)
treed61554cba3c2aa34bee31d02127690c317681d2a /mysys
parent5e4ce743a351f7d1ee55b534dd689e2d082fa146 (diff)
parent2eea2f52089028e97ab1c3b9e33e68fd8eadb094 (diff)
downloadmariadb-git-e4aedcc2c137ba667e3d429031ce284032e11060.tar.gz
Merge mskold@bk-internal.mysql.com:/home/bk/mysql-5.0-ndb
into linux.site:/home/marty/MySQL/mysql-5.0
Diffstat (limited to 'mysys')
-rw-r--r--mysys/charset.c2
-rw-r--r--mysys/default.c2
-rw-r--r--mysys/default_modify.c162
-rw-r--r--mysys/mf_iocache.c2
-rw-r--r--mysys/mf_keycache.c2
-rw-r--r--mysys/my_access.c12
-rw-r--r--mysys/my_alloc.c2
-rw-r--r--mysys/my_getopt.c10
-rw-r--r--mysys/my_mmap.c2
-rw-r--r--mysys/my_once.c2
-rw-r--r--mysys/string.c2
-rw-r--r--mysys/tree.c3
12 files changed, 132 insertions, 71 deletions
diff --git a/mysys/charset.c b/mysys/charset.c
index 534a6aa998e..cbd9ba16b4c 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -97,7 +97,7 @@ static my_bool init_state_maps(CHARSET_INFO *cs)
/* Special handling of hex and binary strings */
state_map[(uchar)'x']= state_map[(uchar)'X']= (uchar) MY_LEX_IDENT_OR_HEX;
- state_map[(uchar)'b']= state_map[(uchar)'b']= (uchar) MY_LEX_IDENT_OR_BIN;
+ state_map[(uchar)'b']= state_map[(uchar)'B']= (uchar) MY_LEX_IDENT_OR_BIN;
state_map[(uchar)'n']= state_map[(uchar)'N']= (uchar) MY_LEX_IDENT_OR_NCHAR;
return 0;
}
diff --git a/mysys/default.c b/mysys/default.c
index 45b27806dc4..1fa8deaa65c 100644
--- a/mysys/default.c
+++ b/mysys/default.c
@@ -914,7 +914,7 @@ static void init_default_directories()
/* Only add shared system directory if different from default. */
if (GetSystemWindowsDirectory(shared_system_dir,sizeof(shared_system_dir)) &&
strcmp(system_dir, shared_system_dir))
- *ptr++= &shared_system_dir;
+ *ptr++= (char *)&shared_system_dir;
#endif
#elif defined(__NETWARE__)
diff --git a/mysys/default_modify.c b/mysys/default_modify.c
index 721ca596428..ea384f9f27a 100644
--- a/mysys/default_modify.c
+++ b/mysys/default_modify.c
@@ -1,3 +1,40 @@
+/* Copyright (C) 2005 MySQL AB
+
+ 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
+ the Free Software Foundation; either version 2 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU 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 */
+
+#include "my_global.h"
+#include "mysys_priv.h"
+#include "m_string.h"
+#include <my_dir.h>
+
+#define BUFF_SIZE 1024
+/* should be big enough to handle at least one line */
+#define RESERVE 1024
+
+#ifdef __WIN__
+#define NEWLINE "\r\n"
+#define NEWLINE_LEN 2
+#else
+#define NEWLINE "\n"
+#define NEWLINE_LEN 1
+#endif
+
+static char *add_option(char *dst, const char *option_value,
+ const char *option, int remove_option);
+
+
/*
Add/remove option to the option file section.
@@ -15,6 +52,8 @@
into a buffer. Then we look for the option within this section and
change/remove it. In the end we get a buffer with modified version of the
file. Then we write it to the file, truncate it if needed and close it.
+ Note that there is a small time gap, when the file is incomplete,
+ and this theoretically might introduce a problem.
RETURN
0 - ok
@@ -22,24 +61,6 @@
2 - cannot open the file
*/
-#include "my_global.h"
-#include "mysys_priv.h"
-#include "m_string.h"
-#include <my_dir.h>
-
-#define BUFF_SIZE 1024
-
-#ifdef __WIN__
-#define NEWLINE "\r\n"
-#define NEWLINE_LEN 2
-#else
-#define NEWLINE "\n"
-#define NEWLINE_LEN 1
-#endif
-
-static char *add_option(char *dst, const char *option_value,
- const char *option, int remove_option);
-
int modify_defaults_file(const char *file_location, const char *option,
const char *option_value,
const char *section_name, int remove_option)
@@ -47,8 +68,11 @@ int modify_defaults_file(const char *file_location, const char *option,
FILE *cnf_file;
MY_STAT file_stat;
char linebuff[BUFF_SIZE], *src_ptr, *dst_ptr, *file_buffer;
- uint optlen, optval_len, sect_len, nr_newlines= 0;
+ 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 new_opt_len;
+ int reserve_occupied= 0;
DBUG_ENTER("modify_defaults_file");
if (!(cnf_file= my_fopen(file_location, O_RDWR | O_BINARY, MYF(0))))
@@ -56,30 +80,36 @@ int modify_defaults_file(const char *file_location, const char *option,
/* my_fstat doesn't use the flag parameter */
if (my_fstat(fileno(cnf_file), &file_stat, MYF(0)))
- goto err;
+ goto malloc_err;
- optlen= strlen(option);
- optval_len= strlen(option_value);
+ opt_len= (uint) strlen(option);
+ optval_len= (uint) strlen(option_value);
+
+ 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 space to read the contents of the file and some more
for the option we want to add.
*/
- if (!(file_buffer= (char*) my_malloc(sizeof(char) *
- (file_stat.st_size +
- /* option name len */
- optlen +
- /* reserve space for newline */
- NEWLINE_LEN +
- /* reserve for '=' char */
- 1 +
- /* option value len */
- optval_len +
- /* The ending zero plus some safety */
- FN_REFLEN), MYF(MY_WME))))
+ if (!(file_buffer= (char*) my_malloc(buffer_size, MYF(MY_WME))))
goto malloc_err;
- sect_len= strlen(section_name);
+ sect_len= (uint) strlen(section_name);
for (dst_ptr= file_buffer; fgets(linebuff, BUFF_SIZE, cnf_file); )
{
@@ -94,24 +124,50 @@ int modify_defaults_file(const char *file_location, const char *option,
continue;
}
- if (!opt_applied && in_section && !strncmp(src_ptr, option, optlen) &&
- (*(src_ptr + optlen) == '=' ||
- my_isspace(&my_charset_latin1, *(src_ptr + optlen)) ||
- *(src_ptr + optlen) == '\0'))
+ /* correct the option */
+ if (in_section && !strncmp(src_ptr, option, opt_len) &&
+ (*(src_ptr + opt_len) == '=' ||
+ 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)
+ {
+ 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++;
+ }
+ }
+ else
+ opt_applied= 1;
dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
- opt_applied= 1;
}
else
{
/* If going to new group and we have option to apply, do it now */
if (in_section && !opt_applied && *src_ptr == '[')
{
- dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
-
+ dst_ptr= add_option(dst_ptr, option_value, option, remove_option);
+ opt_applied= 1; /* set the flag to do write() later */
}
+
for (; nr_newlines; nr_newlines--)
- dst_ptr= strmov(dst_ptr, NEWLINE);
+ dst_ptr= strmov(dst_ptr, NEWLINE);
dst_ptr= strmov(dst_ptr, linebuff);
}
/* Look for a section */
@@ -120,13 +176,13 @@ int modify_defaults_file(const char *file_location, const char *option,
/* Copy the line to the buffer */
if (!strncmp(++src_ptr, section_name, sect_len))
{
- src_ptr+= sect_len;
- /* Skip over whitespaces. They are allowed after section name */
- for (; my_isspace(&my_charset_latin1, *src_ptr); src_ptr++)
- {}
+ src_ptr+= sect_len;
+ /* Skip over whitespaces. They are allowed after section name */
+ for (; my_isspace(&my_charset_latin1, *src_ptr); src_ptr++)
+ {}
- if (*src_ptr != ']')
- continue; /* Missing closing parenthesis. Assume this was no group */
+ if (*src_ptr != ']')
+ continue; /* Missing closing parenthesis. Assume this was no group */
in_section= TRUE;
}
else
@@ -149,10 +205,10 @@ int modify_defaults_file(const char *file_location, const char *option,
{
/* Don't write the file if there are no changes to be made */
if (my_chsize(fileno(cnf_file), (my_off_t) (dst_ptr - file_buffer), 0,
- MYF(MY_WME)) ||
- my_fseek(cnf_file, 0, MY_SEEK_SET, MYF(0)) ||
- my_fwrite(cnf_file, file_buffer, (uint) (dst_ptr - file_buffer),
- MYF(MY_NABP)))
+ MYF(MY_WME)) ||
+ my_fseek(cnf_file, 0, MY_SEEK_SET, MYF(0)) ||
+ my_fwrite(cnf_file, file_buffer, (uint) (dst_ptr - file_buffer),
+ MYF(MY_NABP)))
goto err;
}
if (my_fclose(cnf_file, MYF(MY_WME)))
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index a55a2d81c2c..b000af19aa0 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -601,7 +601,7 @@ int _my_b_read_r(register IO_CACHE *info, byte *Buffer, uint Count)
info->error= info->share->active->error;
info->read_end= info->share->active->read_end;
info->pos_in_file= info->share->active->pos_in_file;
- len= (info->error == -1 ? -1 : info->read_end-info->buffer);
+ len= (int) (info->error == -1 ? -1 : info->read_end-info->buffer);
}
info->read_pos=info->buffer;
info->seek_not_done=0;
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index feb9c77a5b9..cb2e0c98e8a 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -2191,7 +2191,7 @@ static int flush_cached_blocks(KEY_CACHE *keycache,
{
int error;
int last_errno= 0;
- uint count= end-cache;
+ uint count= (uint) (end-cache);
/* Don't lock the cache during the flush */
keycache_pthread_mutex_unlock(&keycache->cache_lock);
diff --git a/mysys/my_access.c b/mysys/my_access.c
index 28210bdfc7d..c01031827c0 100644
--- a/mysys/my_access.c
+++ b/mysys/my_access.c
@@ -93,18 +93,20 @@ int check_if_legal_filename(const char *path)
path+= dirname_length(path); /* To start of filename */
if (!(end= strchr(path, FN_EXTCHAR)))
end= strend(path);
- if (path == end || (uint) (path - end) > MAX_RESERVED_NAME_LENGTH)
+ if (path == end || (uint) (end - path) > MAX_RESERVED_NAME_LENGTH)
DBUG_RETURN(0); /* Simplify inner loop */
for (reserved_name= reserved_names; *reserved_name; reserved_name++)
{
const char *name= path;
- while (name != end)
+ const char *current_reserved_name= *reserved_name;
+
+ while (name != end && *current_reserved_name)
{
- if (my_toupper(&my_charset_latin1, *path) !=
- my_toupper(&my_charset_latin1, *name))
+ if (*current_reserved_name != my_toupper(&my_charset_latin1, *name))
break;
- if (name++ == end)
+ current_reserved_name++;
+ if (++name == end)
DBUG_RETURN(1); /* Found wrong path */
}
}
diff --git a/mysys/my_alloc.c b/mysys/my_alloc.c
index 4aa31829c59..619d6bd5654 100644
--- a/mysys/my_alloc.c
+++ b/mysys/my_alloc.c
@@ -333,7 +333,7 @@ void set_prealloc_root(MEM_ROOT *root, char *ptr)
char *strdup_root(MEM_ROOT *root,const char *str)
{
- return strmake_root(root, str, strlen(str));
+ return strmake_root(root, str, (uint) strlen(str));
}
char *strmake_root(MEM_ROOT *root,const char *str, uint len)
diff --git a/mysys/my_getopt.c b/mysys/my_getopt.c
index 5e93ad56cb5..68bf65b2abe 100644
--- a/mysys/my_getopt.c
+++ b/mysys/my_getopt.c
@@ -180,7 +180,7 @@ int handle_options(int *argc, char ***argv,
}
opt_str= check_struct_option(cur_arg, key_name);
optend= strcend(opt_str, '=');
- length= optend - opt_str;
+ length= (uint) (optend - opt_str);
if (*optend == '=')
optend++;
else
@@ -323,7 +323,7 @@ int handle_options(int *argc, char ***argv,
return EXIT_NO_ARGUMENT_ALLOWED;
}
value= optp->var_type & GET_ASK_ADDR ?
- (*getopt_get_addr)(key_name, strlen(key_name), optp) : optp->value;
+ (*getopt_get_addr)(key_name, (uint) strlen(key_name), optp) : optp->value;
if (optp->arg_type == NO_ARG)
{
@@ -519,7 +519,7 @@ static char *check_struct_option(char *cur_arg, char *key_name)
*/
if (end - ptr > 1)
{
- uint len= ptr - cur_arg;
+ uint len= (uint) (ptr - cur_arg);
set_if_smaller(len, FN_REFLEN-1);
strmake(key_name, cur_arg, len);
return ++ptr;
@@ -833,7 +833,7 @@ void my_print_help(const struct my_option *options)
if (strlen(optp->name))
{
printf("--%s", optp->name);
- col+= 2 + strlen(optp->name);
+ col+= 2 + (uint) strlen(optp->name);
if ((optp->var_type & GET_TYPE_MASK) == GET_STR ||
(optp->var_type & GET_TYPE_MASK) == GET_STR_ALLOC)
{
@@ -904,7 +904,7 @@ void my_print_variables(const struct my_option *options)
if (value)
{
printf("%s", optp->name);
- length= strlen(optp->name);
+ length= (uint) strlen(optp->name);
for (; length < name_space; length++)
putchar(' ');
switch ((optp->var_type & GET_TYPE_MASK)) {
diff --git a/mysys/my_mmap.c b/mysys/my_mmap.c
index cd84630a761..21bfddae46c 100644
--- a/mysys/my_mmap.c
+++ b/mysys/my_mmap.c
@@ -53,7 +53,7 @@ void *my_mmap(void *addr, size_t len, int prot,
flProtect|=SEC_COMMIT;
hFileMap=CreateFileMapping(hFile, &mmap_security_attributes,
- PAGE_READWRITE, 0, len, NULL);
+ PAGE_READWRITE, 0, (DWORD) len, NULL);
if (hFileMap == 0)
return MAP_FAILED;
diff --git a/mysys/my_once.c b/mysys/my_once.c
index a4201810b03..ab5fcc51c0e 100644
--- a/mysys/my_once.c
+++ b/mysys/my_once.c
@@ -81,7 +81,7 @@ gptr my_once_alloc(unsigned int Size, myf MyFlags)
char *my_once_strdup(const char *src,myf myflags)
{
- uint len=strlen(src)+1;
+ uint len= (uint) strlen(src)+1;
char *dst=my_once_alloc(len, myflags);
if (dst)
memcpy(dst, src, len);
diff --git a/mysys/string.c b/mysys/string.c
index ea747bc9847..dfd42d137dd 100644
--- a/mysys/string.c
+++ b/mysys/string.c
@@ -91,7 +91,7 @@ my_bool dynstr_realloc(DYNAMIC_STRING *str, ulong additional_size)
my_bool dynstr_append(DYNAMIC_STRING *str, const char *append)
{
- return dynstr_append_mem(str,append,strlen(append));
+ return dynstr_append_mem(str,append,(uint) strlen(append));
}
diff --git a/mysys/tree.c b/mysys/tree.c
index bec1ec680f1..1780913961e 100644
--- a/mysys/tree.c
+++ b/mysys/tree.c
@@ -263,6 +263,9 @@ TREE_ELEMENT *tree_insert(TREE *tree, void *key, uint key_size,
if (tree->flag & TREE_NO_DUPS)
return(NULL);
element->count++;
+ /* Avoid a wrap over of the count. */
+ if (! element->count)
+ element->count--;
}
DBUG_EXECUTE("check_tree", test_rb_tree(tree->root););
return element;