summaryrefslogtreecommitdiff
path: root/mysys/mf_pack.c
diff options
context:
space:
mode:
authormonty@mysql.com/narttu.mysql.fi <>2007-05-10 12:59:39 +0300
committermonty@mysql.com/narttu.mysql.fi <>2007-05-10 12:59:39 +0300
commit088e2395f1833f16c2ea3f7405f604165b4aa2cc (patch)
tree6480cbef09e9dec2fa347b1899963ab3658d692f /mysys/mf_pack.c
parent9078e630c64a313301cd13ce71d0854fbcf2fd0b (diff)
downloadmariadb-git-088e2395f1833f16c2ea3f7405f604165b4aa2cc.tar.gz
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
Diffstat (limited to 'mysys/mf_pack.c')
-rw-r--r--mysys/mf_pack.c184
1 files changed, 50 insertions, 134 deletions
diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c
index 1b83c6fda10..99c0c959d94 100644
--- a/mysys/mf_pack.c
+++ b/mysys/mf_pack.c
@@ -24,17 +24,17 @@
#include <descrip.h>
#endif /* VMS */
-static my_string NEAR_F expand_tilde(my_string *path);
+static char * NEAR_F expand_tilde(char * *path);
/* Pack a dirname ; Changes HOME to ~/ and current dev to ./ */
/* from is a dirname (from dirname() ?) ending with FN_LIBCHAR */
/* to may be == from */
-void pack_dirname(my_string to, const char *from)
+void pack_dirname(char * to, const char *from)
{
int cwd_err;
- uint d_length,length,buff_length;
- my_string start;
+ size_t d_length,length,buff_length;
+ char * start;
char buff[FN_REFLEN];
DBUG_ENTER("pack_dirname");
@@ -50,13 +50,13 @@ void pack_dirname(my_string to, const char *from)
if (!(cwd_err= my_getwd(buff,FN_REFLEN,MYF(0))))
{
- buff_length= (uint) strlen(buff);
- d_length=(uint) (start-to);
+ buff_length= strlen(buff);
+ d_length= (size_t) (start-to);
if ((start == to ||
(buff_length == d_length && !bcmp(buff,start,d_length))) &&
*start != FN_LIBCHAR && *start)
{ /* Put current dir before */
- bchange(to,d_length,buff,buff_length,(uint) strlen(to)+1);
+ bchange(to,d_length,buff,buff_length,strlen(to)+1);
}
}
@@ -65,7 +65,7 @@ void pack_dirname(my_string to, const char *from)
length=0;
if (home_dir)
{
- length= (uint) strlen(home_dir);
+ length= strlen(home_dir);
if (home_dir[length-1] == FN_LIBCHAR)
length--; /* Don't test last '/' */
}
@@ -89,7 +89,7 @@ void pack_dirname(my_string to, const char *from)
}
if (is_prefix(to,buff))
{
- length= (uint) strlen(buff);
+ length= strlen(buff);
if (to[length])
(void) strmov_overlapp(to,to+length); /* Remove everything before */
else
@@ -126,12 +126,12 @@ void pack_dirname(my_string to, const char *from)
# length of new name
*/
-uint cleanup_dirname(register my_string to, const char *from)
+size_t cleanup_dirname(register char *to, const char *from)
{
- reg5 uint length;
- reg2 my_string pos;
- reg3 my_string from_ptr;
- reg4 my_string start;
+ reg5 size_t length;
+ reg2 char * pos;
+ reg3 char * from_ptr;
+ reg4 char * start;
char parent[5], /* for "FN_PARENTDIR" */
buff[FN_REFLEN+1],*end_parentdir;
#ifdef BACKSLASH_MBTAIL
@@ -141,17 +141,17 @@ uint cleanup_dirname(register my_string to, const char *from)
DBUG_PRINT("enter",("from: '%s'",from));
start=buff;
- from_ptr=(my_string) from;
+ from_ptr=(char *) from;
#ifdef FN_DEVCHAR
if ((pos=strrchr(from_ptr,FN_DEVCHAR)) != 0)
{ /* Skip device part */
- length=(uint) (pos-from_ptr)+1;
+ length=(size_t) (pos-from_ptr)+1;
start=strnmov(buff,from_ptr,length); from_ptr+=length;
}
#endif
parent[0]=FN_LIBCHAR;
- length=(uint) (strmov(parent+1,FN_PARENTDIR)-parent);
+ length=(size_t) (strmov(parent+1,FN_PARENTDIR)-parent);
for (pos=start ; (*pos= *from_ptr++) != 0 ; pos++)
{
#ifdef BACKSLASH_MBTAIL
@@ -167,7 +167,7 @@ uint cleanup_dirname(register my_string to, const char *from)
*pos = FN_LIBCHAR;
if (*pos == FN_LIBCHAR)
{
- if ((uint) (pos-start) > length && bcmp(pos-length,parent,length) == 0)
+ if ((size_t) (pos-start) > length && bcmp(pos-length,parent,length) == 0)
{ /* If .../../; skip prev */
pos-=length;
if (pos != start)
@@ -206,7 +206,7 @@ uint cleanup_dirname(register my_string to, const char *from)
}
}
}
- else if ((uint) (pos-start) == length-1 &&
+ else if ((size_t) (pos-start) == length-1 &&
!bcmp(start,parent+1,length-1))
start=pos; /* Starts with "../" */
else if (pos-start > 0 && pos[-1] == FN_LIBCHAR)
@@ -228,7 +228,7 @@ uint cleanup_dirname(register my_string to, const char *from)
}
(void) strmov(to,buff);
DBUG_PRINT("exit",("to: '%s'",to));
- DBUG_RETURN((uint) (pos-buff));
+ DBUG_RETURN((size_t) (pos-buff));
} /* cleanup_dirname */
@@ -251,7 +251,7 @@ void symdirget(char *dir)
if (dir[0] && pos[-1] != FN_DEVCHAR && my_access(dir, F_OK))
{
File file;
- uint length;
+ size_t length;
char temp= *(--pos); /* May be "/" or "\" */
strmov(pos,".sym");
file= my_open(dir, O_RDONLY, MYF(0));
@@ -268,7 +268,7 @@ void symdirget(char *dir)
if (pos == buff || pos[-1] != FN_LIBCHAR)
*pos++=FN_LIBCHAR;
- strmake(dir,buff, (uint) (pos-buff));
+ strmake(dir,buff, (size_t) (pos-buff));
}
my_close(file, MYF(0));
}
@@ -296,14 +296,14 @@ void symdirget(char *dir)
Length of new directory name (= length of to)
*/
-uint unpack_dirname(my_string to, const char *from)
+size_t unpack_dirname(char * to, const char *from)
{
- uint length,h_length;
+ size_t length, h_length;
char buff[FN_REFLEN+1+4],*suffix,*tilde_expansion;
DBUG_ENTER("unpack_dirname");
- (void) intern_filename(buff,from); /* Change to intern name */
- length= (uint) strlen(buff); /* Fix that '/' is last */
+ (void) intern_filename(buff,from); /* Change to intern name */
+ length= strlen(buff); /* Fix that '/' is last */
if (length &&
#ifdef FN_DEVCHAR
buff[length-1] != FN_DEVCHAR &&
@@ -320,8 +320,8 @@ uint unpack_dirname(my_string to, const char *from)
suffix=buff+1; tilde_expansion=expand_tilde(&suffix);
if (tilde_expansion)
{
- length-=(uint) (suffix-buff)-1;
- if (length+(h_length= (uint) strlen(tilde_expansion)) <= FN_REFLEN)
+ length-= (size_t) (suffix-buff)-1;
+ if (length+(h_length= strlen(tilde_expansion)) <= FN_REFLEN)
{
if (tilde_expansion[h_length-1] == FN_LIBCHAR)
h_length--;
@@ -344,7 +344,7 @@ uint unpack_dirname(my_string to, const char *from)
/* Expand tilde to home or user-directory */
/* Path is reset to point at FN_LIBCHAR after ~xxx */
-static my_string NEAR_F expand_tilde(my_string *path)
+static char * NEAR_F expand_tilde(char * *path)
{
if (path[0][0] == FN_LIBCHAR)
return home_dir; /* ~/ expanded to home */
@@ -366,7 +366,7 @@ static my_string NEAR_F expand_tilde(my_string *path)
}
}
#endif
- return (my_string) 0;
+ return (char *) 0;
}
@@ -387,13 +387,13 @@ static my_string NEAR_F expand_tilde(my_string *path)
*/
-uint unpack_filename(my_string to, const char *from)
+size_t unpack_filename(char * to, const char *from)
{
- uint length,n_length;
+ size_t length, n_length, buff_length;
char buff[FN_REFLEN];
DBUG_ENTER("unpack_filename");
- length=dirname_part(buff,from); /* copy & convert dirname */
+ length=dirname_part(buff, from, &buff_length);/* copy & convert dirname */
n_length=unpack_dirname(buff,buff);
if (n_length+strlen(from+length) < FN_REFLEN)
{
@@ -410,10 +410,10 @@ uint unpack_filename(my_string to, const char *from)
/* Used before system command's like open(), create() .. */
/* Returns length of to */
-uint system_filename(my_string to, const char *from)
+size_t system_filename(char * to, const char *from)
{
#ifndef FN_C_BEFORE_DIR
- return (uint) (strmake(to,from,FN_REFLEN-1)-to);
+ return (size_t) (strmake(to,from,FN_REFLEN-1)-to);
#else /* VMS */
/* change 'dev:lib/xxx' to 'dev:[lib]xxx' */
@@ -423,8 +423,9 @@ uint system_filename(my_string to, const char *from)
/* change '/x/y/z to '[x.y]x' */
/* change 'dev:/x' to 'dev:[000000]x' */
- int libchar_found,length;
- my_string to_pos,from_pos,pos;
+ int libchar_found;
+ size_t length;
+ char * to_pos,from_pos,pos;
char buff[FN_REFLEN];
DBUG_ENTER("system_filename");
@@ -434,7 +435,7 @@ uint system_filename(my_string to, const char *from)
if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
{
pos++;
- to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos));
+ to_pos=strnmov(to,from_pos,(size_t) (pos-from_pos));
from_pos=pos;
}
else
@@ -465,115 +466,30 @@ uint system_filename(my_string to, const char *from)
from_pos+strlen(FN_PARENTDIR) == pos)
to_pos=strmov(to_pos,FN_C_PARENT_DIR); /* Found '../' */
else
- to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos));
+ to_pos=strnmov(to_pos,from_pos,(size_t) (pos-from_pos));
from_pos=pos+1;
}
*(to_pos++)=FN_C_AFTER_DIR;
}
- length=(int) (strmov(to_pos,from_pos)-to);
+ length= (size_t) (strmov(to_pos,from_pos)-to);
DBUG_PRINT("exit",("name: '%s'",to));
- DBUG_RETURN((uint) length);
+ DBUG_RETURN(length);
#endif
} /* system_filename */
/* Fix a filename to intern (UNIX format) */
-my_string intern_filename(my_string to, const char *from)
+char *intern_filename(char *to, const char *from)
{
-#ifndef VMS
- {
- uint length;
- char buff[FN_REFLEN];
- if (from == to)
- { /* Dirname may destroy from */
- strmov(buff,from);
- from=buff;
- }
- length=dirname_part(to,from); /* Copy dirname & fix chars */
- (void) strcat(to,from+length);
- return (to);
- }
-#else /* VMS */
-
- /* change 'dev:[lib]xxx' to 'dev:lib/xxx' */
- /* change 'dev:xxx' to 'dev:xxx' */
- /* change 'dev:x/y/[.lib]' to 'dev:x/y/lib/ */
- /* change '[.lib]' to './lib/' */
- /* change '[x.y]' or '[x.][y]' or '[x][.y]' to '/x/y/' */
- /* change '[000000.x] or [x.000000]' to '/x/' */
-
- int par_length,root_length;
- my_string pos,from_pos,to_pos,end_pos;
+ size_t length, to_length;
char buff[FN_REFLEN];
-
- convert_dirname(buff,from,NullS); /* change '<>' to '[]' */
- from_pos=buff;
- if ((pos=strrchr(from_pos,FN_DEVCHAR))) /* Skip device part */
- {
- pos++;
- to_pos=strnmov(to,from_pos,(size_s) (pos-from_pos));
- from_pos=pos;
- }
- else
- to_pos=to;
-
- root_length=strlen(FN_C_ROOT_DIR);
- if ((pos = strchr(from_pos,FN_C_BEFORE_DIR)) &&
- (end_pos = strrchr(pos+1,FN_C_AFTER_DIR)))
- {
- to_pos=strnmov(to_pos,from_pos,(size_s) (pos-from_pos));
- /* Copy all between ':' and '[' */
- from_pos=pos+1;
- if (strinstr(from_pos,FN_C_ROOT_DIR) == 1 &&
- (from_pos[root_length] == FN_C_DIR_SEP ||
- from_pos[root_length] == FN_C_AFTER_DIR))
- {
- from_pos+=root_length+1;
- }
- else if (*from_pos == FN_C_DIR_SEP)
- *(to_pos++) = FN_CURLIB; /* Set ./ first */
- *(to_pos++) = FN_LIBCHAR;
-
- par_length=strlen(FN_C_PARENT_DIR);
- pos=to_pos;
- for (; from_pos <= end_pos ; from_pos++)
- {
- switch (*from_pos) {
- case FN_C_DIR_SEP:
- case FN_C_AFTER_DIR:
- if (pos != to_pos)
- {
- if ((int) (to_pos-pos) == root_length &&
- is_suffix(pos,FN_C_ROOT_DIR))
- to_pos=pos; /* remove root-pos */
- else
- {
- *(to_pos++)=FN_LIBCHAR; /* Find lib */
- pos=to_pos;
- }
- }
- break;
- case FN_C_BEFORE_DIR:
- break;
- case '-': /* *(FN_C_PARENT_DIR): */
- if (to_pos[-1] == FN_LIBCHAR &&
- strncmp(from_pos,FN_C_PARENT_DIR,par_length) == 0)
- { /* Change '-' to '..' */
- to_pos=strmov(to_pos,FN_PARENTDIR);
- *(to_pos++)=FN_LIBCHAR;
- pos=to_pos;
- from_pos+=par_length-1;
- break;
- }
- /* Fall through */
- default:
- *(to_pos++)= *from_pos;
- break;
- }
- }
+ if (from == to)
+ { /* Dirname may destroy from */
+ strmov(buff,from);
+ from=buff;
}
- (void) strmov(to_pos,from_pos);
+ length= dirname_part(to, from, &to_length); /* Copy dirname & fix chars */
+ (void) strmov(to + to_length,from+length);
return (to);
-#endif /* VMS */
} /* intern_filename */