summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2003-12-17 17:35:34 +0200
committerunknown <monty@mysql.com>2003-12-17 17:35:34 +0200
commit9d89a0fdf209037debc6bbdf91d5ea96f37ed7a0 (patch)
tree93924b5aab311e02a0f0931cf91e67cdfad04bdf /mysys
parentf591a8ece51d47d5e203697cea336dd0a2323009 (diff)
parentb59fa7d0f56a32a034806d072d79c4de87b04844 (diff)
downloadmariadb-git-9d89a0fdf209037debc6bbdf91d5ea96f37ed7a0.tar.gz
Merge with 4.0.17
BitKeeper/etc/logging_ok: auto-union Build-tools/Do-compile: Auto merged acinclude.m4: Auto merged configure.in: Auto merged dbug/dbug.c: Auto merged include/config-win.h: Auto merged include/my_base.h: Auto merged include/my_global.h: Auto merged include/my_pthread.h: Auto merged include/my_sys.h: Auto merged include/mysql.h: Auto merged include/mysql_com.h: Auto merged innobase/lock/lock0lock.c: Auto merged innobase/row/row0ins.c: Auto merged innobase/row/row0sel.c: Auto merged innobase/row/row0umod.c: Auto merged innobase/row/row0upd.c: Auto merged myisam/ft_boolean_search.c: Auto merged myisam/mi_check.c: Auto merged myisam/mi_dbug.c: Auto merged myisam/mi_open.c: Auto merged mysql-test/r/auto_increment.result: Auto merged mysql-test/r/bdb.result: Auto merged mysql-test/r/func_op.result: Auto merged Build-tools/Bootstrap: Merge with 4.0 client/mysql.cc: Merge with 4.0 client/mysqldump.c: Merge with 4.0 client/mysqltest.c: Use local version innobase/btr/btr0cur.c: Merge with 4.0 (Heikki should check if we should remove btr_cur_update_sec_rec_in_place() libmysql/libmysql.c: Merge with 4.0 libmysqld/lib_sql.cc: Merge with 4.0 myisam/mi_key.c: Merge with 4.0 myisam/mi_search.c: Merge with 4.0 mysql-test/r/binary.result: Merge with 4.0 mysql-test/r/func_group.result: Merge with 4.0 mysql-test/r/func_str.result: Merge with 4.0 mysql-test/r/func_time.result: Merge with 4.0 mysql-test/r/group_by.result: Merge with 4.0 mysql-test/r/handler.result: Merge with 4.0 mysql-test/r/innodb.result: Merge with 4.0 mysql-test/r/insert.result: Merge with 4.0 mysql-test/r/join_outer.result: Merge with 4.0 mysql-test/r/loaddata.result: Merge with 4.0 mysql-test/r/lowercase_table.result: Merge with 4.0 mysql-test/r/multi_update.result: Merge with 4.0 mysql-test/r/mysqldump.result: Merge with 4.0 mysql-test/r/query_cache.result: Merge with 4.0 mysql-test/r/rpl_max_relay_size.result: Merge with 4.0 mysql-test/r/rpl_rotate_logs.result: Merge with 4.0 mysql-test/r/rpl_trunc_binlog.result: Merge with 4.0 mysql-test/r/select_found.result: Merge with 4.0 mysql-test/r/symlink.result: Merge with 4.0 mysql-test/r/truncate.result: Merge with 4.0 mysql-test/r/type_blob.result: Merge with 4.0 mysql-test/r/type_datetime.result: Merge with 4.0 mysql-test/r/type_decimal.result: Merge with 4.0 mysql-test/r/type_enum.result: Merge with 4.0 mysql-test/r/type_timestamp.result: Merge with 4.0 mysql-test/r/union.result: Merge with 4.0 mysql-test/t/auto_increment.test: Merge with 4.0 mysql-test/t/bdb.test: Merge with 4.0 mysql-test/t/func_group.test: Merge with 4.0 mysql-test/t/func_op.test: Merge with 4.0 mysql-test/t/func_str.test: Merge with 4.0 mysql-test/t/func_time.test: Merge with 4.0 mysql-test/t/group_by.test: Merge with 4.0 mysql-test/t/handler.test: Merge with 4.0 mysql-test/t/innodb.test: Merge with 4.0 mysql-test/t/insert.test: Merge with 4.0 mysql-test/t/join_outer.test: Merge with 4.0 mysql-test/t/limit.test: Merge with 4.0 mysql-test/t/loaddata.test: Merge with 4.0 mysql-test/t/lowercase_table.test: Merge with 4.0 mysql-test/t/multi_update.test: Merge with 4.0 mysql-test/t/mysqldump.test: Merge with 4.0 mysql-test/t/query_cache.test: Merge with 4.0 mysql-test/t/rpl_log_pos.test: Merge with 4.0 mysql-test/t/rpl_max_relay_size.test: Merge with 4.0 mysql-test/t/rpl_rotate_logs.test: Merge with 4.0 mysql-test/t/rpl_trunc_binlog.test: Merge with 4.0 mysql-test/t/select_found.test: Merge with 4.0 mysql-test/t/symlink.test: Merge with 4.0 mysql-test/t/truncate.test: Merge with 4.0 mysql-test/t/type_blob.test: Merge with 4.0 mysql-test/t/type_datetime.test: Merge with 4.0 mysql-test/t/type_decimal.test: Merge with 4.0 mysql-test/t/type_enum.test: Merge with 4.0 mysql-test/t/type_timestamp.test: Merge with 4.0 mysql-test/t/union.test: Merge with 4.0 mysys/charset.c: Merge with 4.0 mysys/my_init.c: Merge with 4.0 mysys/my_symlink.c: Merge with 4.0 mysys/my_thr_init.c: Merge with 4.0 regex/reginit.c: Merge with 4.0 sql/field.cc: Change fix_datetime() to print errors sql/field.h: Merge with 4.0 sql/ha_innodb.cc: Merge with 4.0 sql/item.cc: Merge with 4.0 sql/item.h: Merge with 4.0 sql/item_cmpfunc.cc: Merge with 4.0 sql/item_func.cc: Merge with 4.0 sql/item_func.h: Merge with 4.0 sql/item_strfunc.cc: Merge with 4.0 sql/item_strfunc.h: Merge with 4.0 sql/item_sum.cc: Merge with 4.0 sql/item_sum.h: Merge with 4.0 sql/item_timefunc.cc: Merge with 4.0 sql/lex.h: Merge with 4.0 sql/log.cc: Merge with 4.0 sql/log_event.cc: Merge with 4.0 sql/log_event.h: Merge with 4.0 sql/mysql_priv.h: Merge with 4.0 sql/mysqld.cc: Merge with 4.0 sql/nt_servc.cc: Merge with 4.0 sql/opt_range.cc: Merge with 4.0 sql/records.cc: Merge with 4.0 sql/repl_failsafe.cc: Merge with 4.0 sql/slave.cc: Merge with 4.0 sql/sql_acl.cc: Merge with 4.0 sql/sql_analyse.cc: Merge with 4.0 sql/sql_base.cc: Merge with 4.0 sql/sql_cache.cc: Merge with 4.0 sql/sql_class.h: Merge with 4.0 sql/sql_db.cc: Merge with 4.0 sql/sql_delete.cc: Merge with 4.0 sql/sql_insert.cc: Merge with 4.0 sql/sql_load.cc: Merge with 4.0 sql/sql_parse.cc: Merge with 4.0 sql/sql_rename.cc: Merge with 4.0 sql/sql_select.cc: Merge with 4.0 sql/sql_show.cc: Merge with 4.0 sql/sql_table.cc: Merge with 4.0 sql/sql_update.cc: Merge with 4.0 sql/sql_yacc.yy: Merge with 4.0 sql/table.cc: Merge with 4.0 sql/table.h: Merge with 4.0 sql/time.cc: Merge with 4.0 sql/uniques.cc: Merge with 4.0 strings/ctype-tis620.c: Merge with 4.0 strings/strto.c: Merge with 4.0 support-files/mysql.server.sh: Merge with 4.0 support-files/mysql.spec.sh: Merge with 4.0
Diffstat (limited to 'mysys')
-rw-r--r--mysys/mf_pack.c27
-rw-r--r--mysys/my_init.c20
-rw-r--r--mysys/my_lib.c345
-rw-r--r--mysys/my_symlink.c1
-rw-r--r--mysys/my_symlink2.c12
-rw-r--r--mysys/my_thr_init.c29
6 files changed, 246 insertions, 188 deletions
diff --git a/mysys/mf_pack.c b/mysys/mf_pack.c
index b3aa347006e..e2e811fe89a 100644
--- a/mysys/mf_pack.c
+++ b/mysys/mf_pack.c
@@ -210,13 +210,13 @@ uint cleanup_dirname(register my_string to, const char *from)
} /* cleanup_dirname */
- /*
- On system where you don't have symbolic links, the following
- code will allow you to create a file:
- directory-name.lnk that should contain the real path
- to the directory. This will be used if the directory name
- doesn't exists
- */
+/*
+ On system where you don't have symbolic links, the following
+ code will allow you to create a file:
+ directory-name.sym that should contain the real path
+ to the directory. This will be used if the directory name
+ doesn't exists
+*/
my_bool my_use_symdir=0; /* Set this if you want to use symdirs */
@@ -228,16 +228,17 @@ void symdirget(char *dir)
char *pos=strend(dir);
if (dir[0] && pos[-1] != FN_DEVCHAR && access(dir, F_OK))
{
- FILE *fp;
+ File file;
+ uint length;
char temp= *(--pos); /* May be "/" or "\" */
strmov(pos,".sym");
- fp = my_fopen(dir, O_RDONLY,MYF(0));
+ file= my_open(dir, O_RDONLY, MYF(0));
*pos++=temp; *pos=0; /* Restore old filename */
- if (fp)
+ if (file >= 0)
{
- if (fgets(buff, sizeof(buff)-1, fp))
+ if ((length= my_read(file, buff, sizeof(buff), MYF(0))) > 0)
{
- for (pos=strend(buff);
+ for (pos= buff + length ;
pos > buff && (iscntrl(pos[-1]) || isspace(pos[-1])) ;
pos --);
@@ -247,7 +248,7 @@ void symdirget(char *dir)
strmake(dir,buff, (uint) (pos-buff));
}
- my_fclose(fp,MYF(0));
+ my_close(file, MYF(0));
}
}
}
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 4a7e9194dae..d68af1400c5 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -61,13 +61,22 @@ static ulong atoi_octal(const char *str)
}
- /* Init my_sys functions and my_sys variabels */
+/*
+ Init my_sys functions and my_sys variabels
+
+ SYNOPSIS
+ my_init()
-void my_init(void)
+ RETURN
+ 0 ok
+ 1 Couldn't initialize environment
+*/
+
+my_bool my_init(void)
{
my_string str;
if (my_init_done)
- return;
+ return 0;
my_init_done=1;
#if defined(THREAD) && defined(SAFE_MUTEX)
safe_mutex_global_init(); /* Must be called early */
@@ -77,7 +86,8 @@ void my_init(void)
#if defined(HAVE_PTHREAD_INIT)
pthread_init(); /* Must be called before DBUG_ENTER */
#endif
- my_thread_global_init();
+ if (my_thread_global_init())
+ return 1;
#if !defined( __WIN__) && !defined(OS2) && !defined(__NETWARE__)
sigfillset(&my_signals); /* signals blocked by mf_brkhant */
#endif
@@ -109,7 +119,7 @@ void my_init(void)
#ifdef __WIN__
win32_init_tcp_ip();
#endif
- DBUG_VOID_RETURN;
+ DBUG_RETURN(0);
}
} /* my_init */
diff --git a/mysys/my_lib.c b/mysys/my_lib.c
index 035bafd07b9..055e00d2efc 100644
--- a/mysys/my_lib.c
+++ b/mysys/my_lib.c
@@ -62,8 +62,15 @@
#define READDIR(A,B,C) (!(C=readdir(A)))
#endif
+/*
+ We are assuming that directory we are reading is either has less than
+ 100 files and so can be read in one initial chunk or has more than 1000
+ files and so big increment are suitable.
+*/
+#define ENTRIES_START_SIZE (8192/sizeof(FILEINFO))
+#define ENTRIES_INCREMENT (65536/sizeof(FILEINFO))
+#define NAMES_START_SIZE 32768
-#define STARTSIZE ONCE_ALLOC_INIT*8 /* some mallocmargin */
static int comp_names(struct fileinfo *a,struct fileinfo *b);
@@ -74,7 +81,13 @@ void my_dirend(MY_DIR *buffer)
{
DBUG_ENTER("my_dirend");
if (buffer)
+ {
+ delete_dynamic((DYNAMIC_ARRAY*)((char*)buffer +
+ ALIGN_SIZE(sizeof(MY_DIR))));
+ free_root((MEM_ROOT*)((char*)buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY))), MYF(0));
my_free((gptr) buffer,MYF(0));
+ }
DBUG_VOID_RETURN;
} /* my_dirend */
@@ -91,14 +104,14 @@ static int comp_names(struct fileinfo *a, struct fileinfo *b)
MY_DIR *my_dir(const char *path, myf MyFlags)
{
+ char *buffer;
+ MY_DIR *result= 0;
+ FILEINFO finfo;
+ DYNAMIC_ARRAY *dir_entries_storage;
+ MEM_ROOT *names_storage;
DIR *dirp;
struct dirent *dp;
- struct fileinfo *fnames;
- char *buffer, *obuffer, *tempptr;
- uint fcnt,i,size,firstfcnt, maxfcnt,length;
char tmp_path[FN_REFLEN+1],*tmp_file;
- my_ptrdiff_t diff;
- bool eof;
#ifdef THREAD
char dirent_tmp[sizeof(struct dirent)+_POSIX_PATH_MAX+1];
#endif
@@ -110,74 +123,72 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
#endif
dirp = opendir(directory_file_name(tmp_path,(my_string) path));
- size = STARTSIZE;
#if defined(__amiga__)
if ((dirp->dd_fd) < 0) /* Directory doesn't exists */
goto error;
#endif
- if (dirp == NULL || ! (buffer = (char *) my_malloc(size, MyFlags)))
+ if (dirp == NULL ||
+ ! (buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
+ sizeof(MEM_ROOT), MyFlags)))
+ goto error;
+
+ dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
+ names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
+
+ if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
+ ENTRIES_START_SIZE, ENTRIES_INCREMENT))
+ {
+ my_free((gptr) buffer,MYF(0));
goto error;
+ }
+ init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
+
+ /* MY_DIR structure is allocated and completly initialized at this point */
+ result= (MY_DIR*)buffer;
- fcnt = 0;
tmp_file=strend(tmp_path);
- firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
- (sizeof(struct fileinfo) + FN_LEN);
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr = (char *) (fnames + maxfcnt);
#ifdef THREAD
dp= (struct dirent*) dirent_tmp;
#else
dp=0;
#endif
- eof=0;
- for (;;)
+
+ while (!(READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
{
- while (fcnt < maxfcnt &&
- !(eof= READDIR(dirp,(struct dirent*) dirent_tmp,dp)))
+ if (!(finfo.name= strdup_root(names_storage, dp->d_name)))
+ goto error;
+
+ if (MyFlags & MY_WANT_STAT)
{
- bzero((gptr) (fnames+fcnt),sizeof(fnames[0])); /* for purify */
- fnames[fcnt].name = tempptr;
- tempptr = strmov(tempptr,dp->d_name) + 1;
- if (MyFlags & MY_WANT_STAT)
- {
- VOID(strmov(tmp_file,dp->d_name));
- VOID(my_stat(tmp_path, &fnames[fcnt].mystat, MyFlags));
- }
- ++fcnt;
+ if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
+ sizeof(MY_STAT))))
+ goto error;
+
+ bzero(finfo.mystat, sizeof(MY_STAT));
+ VOID(strmov(tmp_file,dp->d_name));
+ VOID(my_stat(tmp_path, finfo.mystat, MyFlags));
}
- if (eof)
- break;
- size += STARTSIZE; obuffer = buffer;
- if (!(buffer = (char *) my_realloc((gptr) buffer, size,
- MyFlags | MY_FREE_ON_ERROR)))
- goto error; /* No memory */
- length= (uint) (sizeof(struct fileinfo ) * firstfcnt);
- diff= PTR_BYTE_DIFF(buffer , obuffer) + (int) length;
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr= ADD_TO_PTR(tempptr,diff,char*);
- for (i = 0; i < maxfcnt; i++)
- fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
-
- /* move filenames upp a bit */
- maxfcnt += firstfcnt;
- bmove_upp(tempptr,tempptr-length,
- (uint) (tempptr- (char*) (fnames+maxfcnt)));
+ else
+ finfo.mystat= NULL;
+
+ if (push_dynamic(dir_entries_storage, (gptr)&finfo))
+ goto error;
}
(void) closedir(dirp);
- {
- MY_DIR * s = (MY_DIR *) buffer;
- s->number_off_files = (uint) fcnt;
- s->dir_entry = fnames;
- }
- if (!(MyFlags & MY_DONT_SORT))
- qsort((void *) fnames, (size_s) fcnt, sizeof(struct fileinfo),
- (qsort_cmp) comp_names);
#if defined(THREAD) && !defined(HAVE_READDIR_R)
pthread_mutex_unlock(&THR_LOCK_open);
#endif
- DBUG_RETURN((MY_DIR *) buffer);
+ result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
+ result->number_off_files= dir_entries_storage->elements;
+
+ if (!(MyFlags & MY_DONT_SORT))
+ qsort((void *) result->dir_entry, result->number_off_files,
+ sizeof(FILEINFO), (qsort_cmp) comp_names);
+ DBUG_RETURN(result);
error:
#if defined(THREAD) && !defined(HAVE_READDIR_R)
@@ -186,6 +197,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
my_errno=errno;
if (dirp)
(void) closedir(dirp);
+ my_dirend(result);
if (MyFlags & (MY_FAE | MY_WME))
my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,my_errno);
DBUG_RETURN((MY_DIR *) NULL);
@@ -349,10 +361,11 @@ my_string directory_file_name (my_string dst, const char *src)
MY_DIR *my_dir(const char *path, myf MyFlags)
{
- struct fileinfo *fnames;
- char *buffer, *obuffer, *tempptr;
- int eof,i,fcnt,firstfcnt,length,maxfcnt;
- uint size;
+ char *buffer;
+ MY_DIR *result= 0;
+ FILEINFO finfo;
+ DYNAMIC_ARRAY *dir_entries_storage;
+ MEM_ROOT *names_storage;
#ifdef __BORLANDC__
struct ffblk find;
#else
@@ -360,7 +373,6 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
#endif
ushort mode;
char tmp_path[FN_REFLEN],*tmp_file,attrib;
- my_ptrdiff_t diff;
#ifdef _WIN64
__int64 handle;
#else
@@ -392,85 +404,88 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
goto error;
#endif
- size = STARTSIZE;
- firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
- (sizeof(struct fileinfo) + FN_LEN);
- if ((buffer = (char *) my_malloc(size, MyFlags)) == 0)
+ if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
+ sizeof(MEM_ROOT), MyFlags)))
goto error;
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr = (char *) (fnames + maxfcnt);
- fcnt = 0;
- for (;;)
+ dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
+ names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
+
+ if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
+ ENTRIES_START_SIZE, ENTRIES_INCREMENT))
+ {
+ my_free((gptr) buffer,MYF(0));
+ goto error;
+ }
+ init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
+
+ /* MY_DIR structure is allocated and completly initialized at this point */
+ result= (MY_DIR*)buffer;
+
+ do
{
- do
+#ifdef __BORLANDC__
+ if (!(finfo.name= strdup_root(names_storage, find.ff_name)))
+ goto error;
+#else
+ if (!(finfo.name= strdup_root(names_storage, find.name)))
+ goto error;
+#endif
+ if (MyFlags & MY_WANT_STAT)
{
- fnames[fcnt].name = tempptr;
+ if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
+ sizeof(MY_STAT))))
+ goto error;
+
+ bzero(finfo.mystat, sizeof(MY_STAT));
#ifdef __BORLANDC__
- tempptr = strmov(tempptr,find.ff_name) + 1;
- fnames[fcnt].mystat.st_size=find.ff_fsize;
- fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
+ finfo.mystat->st_size=find.ff_fsize;
mode=MY_S_IREAD; attrib=find.ff_attrib;
#else
- tempptr = strmov(tempptr,find.name) + 1;
- fnames[fcnt].mystat.st_size=find.size;
- fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
+ finfo.mystat->st_size=find.size;
mode=MY_S_IREAD; attrib=find.attrib;
#endif
if (!(attrib & _A_RDONLY))
mode|=MY_S_IWRITE;
if (attrib & _A_SUBDIR)
mode|=MY_S_IFDIR;
- fnames[fcnt].mystat.st_mode=mode;
-#ifdef __BORLANDC__
- fnames[fcnt].mystat.st_mtime=((uint32) find.ff_ftime);
-#else
- fnames[fcnt].mystat.st_mtime=((uint32) find.time_write);
-#endif
- ++fcnt;
+ finfo.mystat->st_mode=mode;
#ifdef __BORLANDC__
- } while ((eof= findnext(&find)) == 0 && fcnt < maxfcnt);
+ finfo.mystat->st_mtime=((uint32) find.ff_ftime);
#else
- } while ((eof= _findnext(handle,&find)) == 0 && fcnt < maxfcnt);
+ finfo.mystat->st_mtime=((uint32) find.time_write);
#endif
+ }
+ else
+ finfo.mystat= NULL;
- DBUG_PRINT("test",("eof: %d errno: %d",eof,errno));
- if (eof)
- break;
- size += STARTSIZE; obuffer = buffer;
- if (!(buffer = (char *) my_realloc((gptr) buffer, size,
- MyFlags | MY_FREE_ON_ERROR)))
+ if (push_dynamic(dir_entries_storage, (gptr)&finfo))
goto error;
- length= sizeof(struct fileinfo ) * firstfcnt;
- diff= PTR_BYTE_DIFF(buffer , obuffer) +length;
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr= ADD_TO_PTR(tempptr,diff,char*);
- for (i = 0; i < maxfcnt; i++)
- fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
-
- /* move filenames upp a bit */
- maxfcnt += firstfcnt;
- bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*),
- (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt));
- }
- {
- MY_DIR * s = (MY_DIR *) buffer;
- s->number_off_files = (uint) fcnt;
- s->dir_entry = fnames;
- }
- if (!(MyFlags & MY_DONT_SORT))
- qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names);
-#ifndef __BORLANDC__
+
+#ifdef __BORLANDC__
+ } while (findnext(&find) == 0);
+#else
+ } while (_findnext(handle,&find) == 0);
+
_findclose(handle);
#endif
- DBUG_RETURN((MY_DIR *) buffer);
+ result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
+ result->number_off_files= dir_entries_storage->elements;
+
+ if (!(MyFlags & MY_DONT_SORT))
+ qsort((void *) result->dir_entry, result->number_off_files,
+ sizeof(FILEINFO), (qsort_cmp) comp_names);
+ DBUG_RETURN(result);
error:
my_errno=errno;
#ifndef __BORLANDC__
if (handle != -1)
_findclose(handle);
#endif
+ my_dirend(result);
if (MyFlags & MY_FAE+MY_WME)
my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno);
DBUG_RETURN((MY_DIR *) NULL);
@@ -485,14 +500,14 @@ error:
MY_DIR *my_dir(const char* path, myf MyFlags)
{
- struct fileinfo *fnames;
- char *buffer, *obuffer, *tempptr;
- int eof,i,fcnt,firstfcnt,length,maxfcnt;
- uint size;
+ char *buffer;
+ MY_DIR *result= 0;
+ FILEINFO finfo;
+ DYNAMIC_ARRAY *dir_entries_storage;
+ MEM_ROOT *names_storage;
struct find_t find;
ushort mode;
char tmp_path[FN_REFLEN],*tmp_file,attrib;
- my_ptrdiff_t diff;
DBUG_ENTER("my_dir");
DBUG_PRINT("my",("path: '%s' stat: %d MyFlags: %d",path,MyFlags));
@@ -514,63 +529,65 @@ MY_DIR *my_dir(const char* path, myf MyFlags)
if (_dos_findfirst(tmp_path,_A_NORMAL | _A_SUBDIR, &find))
goto error;
- size = STARTSIZE;
- firstfcnt = maxfcnt = (size - sizeof(MY_DIR)) /
- (sizeof(struct fileinfo) + FN_LEN);
- if ((buffer = (char *) my_malloc(size, MyFlags)) == 0)
+ if (!(buffer= my_malloc(ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)) +
+ sizeof(MEM_ROOT), MyFlags)))
goto error;
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr = (char *) (fnames + maxfcnt);
- fcnt = 0;
- for (;;)
+ dir_entries_storage= (DYNAMIC_ARRAY*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)));
+ names_storage= (MEM_ROOT*)(buffer + ALIGN_SIZE(sizeof(MY_DIR)) +
+ ALIGN_SIZE(sizeof(DYNAMIC_ARRAY)));
+
+ if (my_init_dynamic_array(dir_entries_storage, sizeof(FILEINFO),
+ ENTRIES_START_SIZE, ENTRIES_INCREMENT))
+ {
+ my_free((gptr) buffer,MYF(0));
+ goto error;
+ }
+ init_alloc_root(names_storage, NAMES_START_SIZE, NAMES_START_SIZE);
+
+ /* MY_DIR structure is allocated and completly initialized at this point */
+ result= (MY_DIR*)buffer;
+
+ do
{
- do
+ if (!(finfo.name= strdup_root(names_storage, find.name)))
+ goto error;
+
+ if (MyFlags & MY_WANT_STAT)
{
- fnames[fcnt].name = tempptr;
- tempptr = strmov(tempptr,find.name) + 1;
- fnames[fcnt].mystat.st_size=find.size;
- fnames[fcnt].mystat.st_uid=fnames[fcnt].mystat.st_gid=0;
- mode=MY_S_IREAD; attrib=find.attrib;
+ if (!(finfo.mystat= (MY_STAT*)alloc_root(names_storage,
+ sizeof(MY_STAT))))
+ goto error;
+
+ bzero(finfo.mystat, sizeof(MY_STAT));
+ finfo.mystat->st_size= find.size;
+ mode= MY_S_IREAD; attrib= find.attrib;
if (!(attrib & _A_RDONLY))
- mode|=MY_S_IWRITE;
+ mode|= MY_S_IWRITE;
if (attrib & _A_SUBDIR)
- mode|=MY_S_IFDIR;
- fnames[fcnt].mystat.st_mode=mode;
- fnames[fcnt].mystat.st_mtime=((uint32) find.wr_date << 16) +
- find.wr_time;
- ++fcnt;
- } while ((eof= _dos_findnext(&find)) == 0 && fcnt < maxfcnt);
-
- DBUG_PRINT("test",("eof: %d errno: %d",eof,errno));
- if (eof)
- break;
- size += STARTSIZE; obuffer = buffer;
- if (!(buffer = (char *) my_realloc((gptr) buffer, size,
- MyFlags | MY_FREE_ON_ERROR)))
+ mode|= MY_S_IFDIR;
+ finfo.mystat->st_mode= mode;
+ finfo.mystat->st_mtime= ((uint32) find.wr_date << 16) + find.wr_time;
+ }
+ else
+ finfo.mystat= NULL;
+
+ if (push_dynamic(dir_entries_storage, (gptr)&finfo))
goto error;
- length= sizeof(struct fileinfo ) * firstfcnt;
- diff= PTR_BYTE_DIFF(buffer , obuffer) +length;
- fnames= (struct fileinfo *) (buffer + sizeof(MY_DIR));
- tempptr= ADD_TO_PTR(tempptr,diff,char*);
- for (i = 0; i < maxfcnt; i++)
- fnames[i].name = ADD_TO_PTR(fnames[i].name,diff,char*);
-
- /* move filenames upp a bit */
- maxfcnt += firstfcnt;
- bmove_upp(tempptr,ADD_TO_PTR(tempptr,-length,char*),
- (int) PTR_BYTE_DIFF(tempptr,fnames+maxfcnt));
- }
- {
- MY_DIR * s = (MY_DIR *) buffer;
- s->number_off_files = (uint) fcnt;
- s->dir_entry = fnames;
- }
+
+ } while (_dos_findnext(&find) == 0);
+
+ result->dir_entry= (FILEINFO *)dir_entries_storage->buffer;
+ result->number_off_files= dir_entries_storage->elements;
+
if (!(MyFlags & MY_DONT_SORT))
- qsort(fnames,fcnt,sizeof(struct fileinfo),(qsort_cmp) comp_names);
- DBUG_RETURN((MY_DIR *) buffer);
+ qsort((void *) result->dir_entry, result->number_off_files,
+ sizeof(FILEINFO), (qsort_cmp) comp_names);
+ DBUG_RETURN(result);
error:
+ my_dirend(result);
if (MyFlags & MY_FAE+MY_WME)
my_error(EE_DIR,MYF(ME_BELL+ME_WAITTANG),path,errno);
DBUG_RETURN((MY_DIR *) NULL);
@@ -602,9 +619,11 @@ MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags)
if ((m_used= (stat_area == NULL)))
if (!(stat_area = (MY_STAT *) my_malloc(sizeof(MY_STAT), my_flags)))
goto error;
- if ( ! stat((my_string) path, (struct stat *) stat_area) )
+ if (! stat((my_string) path, (struct stat *) stat_area) )
DBUG_RETURN(stat_area);
- my_errno=errno;
+
+ DBUG_PRINT("error",("Got errno: %d from stat", errno));
+ my_errno= errno;
if (m_used) /* Free if new area */
my_free((gptr) stat_area,MYF(0));
diff --git a/mysys/my_symlink.c b/mysys/my_symlink.c
index b9468d42cfc..045802c5e61 100644
--- a/mysys/my_symlink.c
+++ b/mysys/my_symlink.c
@@ -72,6 +72,7 @@ int my_symlink(const char *content, const char *linkname, myf MyFlags)
#else
int result;
DBUG_ENTER("my_symlink");
+ DBUG_PRINT("enter",("content: %s linkname: %s", content, linkname));
result= 0;
if (symlink(content, linkname))
diff --git a/mysys/my_symlink2.c b/mysys/my_symlink2.c
index 68b034bec5c..913f632fbb4 100644
--- a/mysys/my_symlink2.c
+++ b/mysys/my_symlink2.c
@@ -31,9 +31,19 @@ File my_create_with_symlink(const char *linkname, const char *filename,
File file;
int tmp_errno;
/* Test if we should create a link */
- int create_link=(linkname && strcmp(linkname,filename));
+ int create_link;
DBUG_ENTER("my_create_with_symlink");
+ if (my_disable_symlinks)
+ {
+ /* Create only the file, not the link and file */
+ create_link= 0;
+ if (linkname)
+ filename= linkname;
+ }
+ else
+ create_link= (linkname && strcmp(linkname,filename));
+
if (!(MyFlags & MY_DELETE_OLD))
{
if (!access(filename,F_OK))
diff --git a/mysys/my_thr_init.c b/mysys/my_thr_init.c
index 1d4219e7bfb..237eeefa325 100644
--- a/mysys/my_thr_init.c
+++ b/mysys/my_thr_init.c
@@ -44,12 +44,23 @@ pthread_mutexattr_t my_fast_mutexattr;
pthread_mutexattr_t my_errchk_mutexattr;
#endif
+/*
+ initialize thread environment
+
+ SYNOPSIS
+ my_thread_global_init()
+
+ RETURN
+ 0 ok
+ 1 error (Couldn't create THR_KEY_mysys)
+*/
+
my_bool my_thread_global_init(void)
{
- if (pthread_key_create(&THR_KEY_mysys,free))
+ if (pthread_key_create(&THR_KEY_mysys,0))
{
fprintf(stderr,"Can't initialize threads: error %d\n",errno);
- exit(1);
+ return 1;
}
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_init(&my_fast_mutexattr);
@@ -78,15 +89,18 @@ my_bool my_thread_global_init(void)
#ifndef HAVE_GETHOSTBYNAME_R
pthread_mutex_init(&LOCK_gethostbyname_r,MY_MUTEX_INIT_SLOW);
#endif
- return my_thread_init();
+ if (my_thread_init())
+ {
+ my_thread_global_end(); /* Clean up */
+ return 1;
+ }
+ return 0;
}
void my_thread_global_end(void)
{
-#if defined(USE_TLS)
- (void) TlsFree(THR_KEY_mysys);
-#endif
+ pthread_key_delete(THR_KEY_mysys);
#ifdef PTHREAD_ADAPTIVE_MUTEX_INITIALIZER_NP
pthread_mutexattr_destroy(&my_fast_mutexattr);
#endif
@@ -155,6 +169,9 @@ my_bool my_thread_init(void)
tmp= &THR_KEY_mysys;
#endif
tmp->id= ++thread_id;
+#if defined(__WIN__) && defined(EMBEDDED_LIBRARY)
+ tmp->thread_self= (pthread_t)getpid();
+#endif
pthread_mutex_init(&tmp->mutex,MY_MUTEX_INIT_FAST);
pthread_cond_init(&tmp->suspend, NULL);
tmp->init= 1;