summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/Makefile.am2
-rw-r--r--mysys/mf_dirname.c4
-rw-r--r--mysys/mf_keycache.c23
-rw-r--r--mysys/my_bitmap.c2
-rw-r--r--mysys/my_delete.c51
-rw-r--r--mysys/my_error.c4
-rw-r--r--mysys/my_handler.c7
-rw-r--r--mysys/my_init.c24
-rw-r--r--mysys/my_lib.c2
-rw-r--r--mysys/my_libwrap.c42
-rw-r--r--mysys/my_memmem.c19
-rw-r--r--mysys/my_pread.c70
-rw-r--r--mysys/thr_lock.c7
13 files changed, 233 insertions, 24 deletions
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index 2838427e9e0..b209d64e78f 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -53,7 +53,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \
my_gethostbyname.c rijndael.c my_aes.c sha1.c \
my_handler.c my_netware.c my_largepage.c \
my_memmem.c \
- my_windac.c my_access.c base64.c
+ my_windac.c my_access.c base64.c my_libwrap.c
EXTRA_DIST = thr_alarm.c thr_lock.c my_pthread.c my_thr_init.c \
thr_mutex.c thr_rwlock.c \
CMakeLists.txt mf_soundex.c \
diff --git a/mysys/mf_dirname.c b/mysys/mf_dirname.c
index 378fe7080b8..43fde95554a 100644
--- a/mysys/mf_dirname.c
+++ b/mysys/mf_dirname.c
@@ -72,7 +72,9 @@ uint dirname_part(my_string to, const char *name)
SYNPOSIS
convert_dirname()
- to Store result here
+ to Store result here. Must be at least of size
+ min(FN_REFLEN, strlen(from) + 1) to make room
+ for adding FN_LIBCHAR at the end.
from Original filename. May be == to
from_end Pointer at end of filename (normally end \0)
diff --git a/mysys/mf_keycache.c b/mysys/mf_keycache.c
index 71d73048a7b..e6f4348968f 100644
--- a/mysys/mf_keycache.c
+++ b/mysys/mf_keycache.c
@@ -470,8 +470,10 @@ int resize_key_cache(KEY_CACHE *keycache, uint key_cache_block_size,
uint age_threshold)
{
int blocks;
+#ifdef THREAD
struct st_my_thread_var *thread;
KEYCACHE_WQUEUE *wqueue;
+#endif
DBUG_ENTER("resize_key_cache");
if (!keycache->key_cache_inited)
@@ -1102,8 +1104,12 @@ static void unreg_request(KEY_CACHE *keycache,
static inline void remove_reader(BLOCK_LINK *block)
{
+#ifdef THREAD
if (! --block->hash_link->requests && block->condvar)
keycache_pthread_cond_signal(block->condvar);
+#else
+ --block->hash_link->requests;
+#endif
}
@@ -1112,7 +1118,8 @@ static inline void remove_reader(BLOCK_LINK *block)
signals on its termination
*/
-static inline void wait_for_readers(KEY_CACHE *keycache, BLOCK_LINK *block)
+static inline void wait_for_readers(KEY_CACHE *keycache __attribute__((unused)),
+ BLOCK_LINK *block)
{
#ifdef THREAD
struct st_my_thread_var *thread= my_thread_var;
@@ -1209,7 +1216,6 @@ static HASH_LINK *get_hash_link(KEY_CACHE *keycache,
int file, my_off_t filepos)
{
reg1 HASH_LINK *hash_link, **start;
- KEYCACHE_PAGE page;
#if defined(KEYCACHE_DEBUG)
int cnt;
#endif
@@ -1264,6 +1270,7 @@ restart:
#ifdef THREAD
/* Wait for a free hash link */
struct st_my_thread_var *thread= my_thread_var;
+ KEYCACHE_PAGE page;
KEYCACHE_DBUG_PRINT("get_hash_link", ("waiting"));
page.file= file;
page.filepos= filepos;
@@ -1588,8 +1595,10 @@ restart:
/* Remove the hash link for this page from the hash table */
unlink_hash(keycache, block->hash_link);
/* All pending requests for this page must be resubmitted */
+#ifdef THREAD
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
+#endif
}
link_to_file_list(keycache, block, file,
(my_bool)(block->hash_link ? 1 : 0));
@@ -1669,7 +1678,7 @@ restart:
portion is less than read_length, but not less than min_length.
*/
-static void read_block(KEY_CACHE *keycache,
+static void read_block(KEY_CACHE *keycache __attribute__((unused)),
BLOCK_LINK *block, uint read_length,
uint min_length, my_bool primary)
{
@@ -1707,8 +1716,10 @@ static void read_block(KEY_CACHE *keycache,
KEYCACHE_DBUG_PRINT("read_block",
("primary request: new page in cache"));
/* Signal that all pending requests for this page now can be processed */
+#ifdef THREAD
if (block->wqueue[COND_FOR_REQUESTED].last_thread)
release_queue(&block->wqueue[COND_FOR_REQUESTED]);
+#endif
}
else
{
@@ -1973,9 +1984,11 @@ int key_cache_insert(KEY_CACHE *keycache,
block->length= read_length+offset;
KEYCACHE_DBUG_PRINT("key_cache_insert",
("primary request: new page in cache"));
+#ifdef THREAD
/* Signal that all pending requests for this now can be processed. */
if (block->wqueue[COND_FOR_REQUESTED].last_thread)
release_queue(&block->wqueue[COND_FOR_REQUESTED]);
+#endif
}
remove_reader(block);
@@ -2219,9 +2232,11 @@ static void free_block(KEY_CACHE *keycache, BLOCK_LINK *block)
/* Keep track of the number of currently unused blocks. */
keycache->blocks_unused++;
+#ifdef THREAD
/* All pending requests for this page must be resubmitted. */
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
+#endif
}
@@ -2275,12 +2290,14 @@ static int flush_cached_blocks(KEY_CACHE *keycache,
if (!last_errno)
last_errno= errno ? errno : -1;
}
+ #ifdef THREAD
/*
Let to proceed for possible waiting requests to write to the block page.
It might happen only during an operation to resize the key cache.
*/
if (block->wqueue[COND_FOR_SAVED].last_thread)
release_queue(&block->wqueue[COND_FOR_SAVED]);
+#endif
/* type will never be FLUSH_IGNORE_CHANGED here */
if (! (type == FLUSH_KEEP || type == FLUSH_FORCE_WRITE))
{
diff --git a/mysys/my_bitmap.c b/mysys/my_bitmap.c
index 92b0cbb1371..2c85ce0bf04 100644
--- a/mysys/my_bitmap.c
+++ b/mysys/my_bitmap.c
@@ -101,7 +101,7 @@ static inline void bitmap_unlock(MY_BITMAP *map __attribute__((unused)))
my_bool bitmap_init(MY_BITMAP *map, my_bitmap_map *buf, uint n_bits,
- my_bool thread_safe)
+ my_bool thread_safe __attribute__((unused)))
{
DBUG_ENTER("bitmap_init");
if (!buf)
diff --git a/mysys/my_delete.c b/mysys/my_delete.c
index 5670f03da64..de2a9814a56 100644
--- a/mysys/my_delete.c
+++ b/mysys/my_delete.c
@@ -32,3 +32,54 @@ int my_delete(const char *name, myf MyFlags)
}
DBUG_RETURN(err);
} /* my_delete */
+
+#if defined(__WIN__) && defined(__NT__)
+/*
+ Delete file which is possibly not closed.
+
+ This function is intended to be used exclusively as a temporal solution
+ for Win NT in case when it is needed to delete a not closed file (note
+ that the file must be opened everywhere with FILE_SHARE_DELETE mode).
+ Deleting not-closed files can not be supported on Win 98|ME (and because
+ of that is considered harmful).
+
+ The function deletes the file with its preliminary renaming. This is
+ because when not-closed share-delete file is deleted it still lives on
+ a disk until it will not be closed everwhere. This may conflict with an
+ attempt to create a new file with the same name. The deleted file is
+ renamed to <name>.<num>.deleted where <name> - the initial name of the
+ file, <num> - a hexadecimal number chosen to make the temporal name to
+ be unique.
+*/
+int nt_share_delete(const char *name, myf MyFlags)
+{
+ char buf[MAX_PATH + 20];
+ ulong cnt;
+ DBUG_ENTER("nt_share_delete");
+ DBUG_PRINT("my",("name %s MyFlags %d", name, MyFlags));
+
+ for (cnt= GetTickCount(); cnt; cnt--)
+ {
+ sprintf(buf, "%s.%08X.deleted", name, cnt);
+ if (MoveFile(name, buf))
+ break;
+
+ if ((errno= GetLastError()) == ERROR_ALREADY_EXISTS)
+ continue;
+
+ DBUG_PRINT("warning", ("Failed to rename %s to %s, errno: %d",
+ name, buf, errno));
+ break;
+ }
+
+ if (DeleteFile(buf))
+ DBUG_RETURN(0);
+
+ my_errno= GetLastError();
+ if (MyFlags & (MY_FAE+MY_WME))
+ my_error(EE_DELETE, MYF(ME_BELL + ME_WAITTANG + (MyFlags & ME_NOINPUT)),
+ name, my_errno);
+
+ DBUG_RETURN(-1);
+}
+#endif
diff --git a/mysys/my_error.c b/mysys/my_error.c
index d7177e7a047..e60c4eb21d7 100644
--- a/mysys/my_error.c
+++ b/mysys/my_error.c
@@ -53,8 +53,10 @@ static struct my_err_head
int meh_first; /* error number matching array slot 0 */
int meh_last; /* error number matching last slot */
} my_errmsgs_globerrs = {NULL, globerrs, EE_ERROR_FIRST, EE_ERROR_LAST};
+
static struct my_err_head *my_errmsgs_list= &my_errmsgs_globerrs;
+
/*
Error message to user
@@ -76,7 +78,6 @@ int my_error(int nr, myf MyFlags, ...)
va_list args;
char ebuff[ERRMSGSIZE + 20];
DBUG_ENTER("my_error");
-
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
/* Search for the error messages array, which could contain the message. */
@@ -102,6 +103,7 @@ int my_error(int nr, myf MyFlags, ...)
DBUG_RETURN((*error_handler_hook)(nr, ebuff, MyFlags));
}
+
/*
Error as printf
diff --git a/mysys/my_handler.c b/mysys/my_handler.c
index 56f2298a9f0..bfec44d57a4 100644
--- a/mysys/my_handler.c
+++ b/mysys/my_handler.c
@@ -504,6 +504,7 @@ HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a)
switch ((enum ha_base_keytype) keyseg->type) {
case HA_KEYTYPE_TEXT:
case HA_KEYTYPE_BINARY:
+ case HA_KEYTYPE_BIT:
if (keyseg->flag & HA_SPACE_PACK)
{
int a_length;
@@ -515,7 +516,9 @@ HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a)
a= end;
break;
case HA_KEYTYPE_VARTEXT1:
+ case HA_KEYTYPE_VARTEXT2:
case HA_KEYTYPE_VARBINARY1:
+ case HA_KEYTYPE_VARBINARY2:
{
int a_length;
get_key_length(a_length, a);
@@ -545,6 +548,10 @@ HA_KEYSEG *ha_find_null(HA_KEYSEG *keyseg, uchar *a)
case HA_KEYTYPE_DOUBLE:
a= end;
break;
+ case HA_KEYTYPE_END: /* purecov: inspected */
+ /* keep compiler happy */
+ DBUG_ASSERT(0);
+ break;
}
}
return keyseg;
diff --git a/mysys/my_init.c b/mysys/my_init.c
index 588bb6f46d6..dca68637161 100644
--- a/mysys/my_init.c
+++ b/mysys/my_init.c
@@ -246,6 +246,22 @@ void setEnvString(char *ret, const char *name, const char *value)
DBUG_VOID_RETURN ;
}
+/*
+ my_paramter_handler
+ Invalid paramter handler we will use instead of the one "baked" into the CRT
+ for MSC v8. This one just prints out what invalid parameter was encountered.
+ By providing this routine, routines like lseek will return -1 when we expect them
+ to instead of crash.
+*/
+void my_parameter_handler(const wchar_t * expression, const wchar_t * function,
+ const wchar_t * file, unsigned int line,
+ uintptr_t pReserved)
+{
+ DBUG_PRINT("my",("Expression: %s function: %s file: %s, line: %d",
+ expression, function, file, line));
+}
+
+
static void my_win_init(void)
{
HKEY hSoftMysql ;
@@ -263,12 +279,18 @@ static void my_win_init(void)
setlocale(LC_CTYPE, ""); /* To get right sortorder */
-#if defined(_MSC_VER) && (_MSC_VER < 1300)
+#if defined(_MSC_VER)
+#if _MSC_VER < 1300
/*
Clear the OS system variable TZ and avoid the 100% CPU usage
Only for old versions of Visual C++
*/
_putenv( "TZ=" );
+#endif
+#if _MSC_VER >= 1400
+ /* this is required to make crt functions return -1 appropriately */
+ _set_invalid_parameter_handler(my_parameter_handler);
+#endif
#endif
_tzset();
diff --git a/mysys/my_lib.c b/mysys/my_lib.c
index 4ed44b0573f..76c31a8fbae 100644
--- a/mysys/my_lib.c
+++ b/mysys/my_lib.c
@@ -494,7 +494,7 @@ MY_DIR *my_dir(const char *path, myf MyFlags)
if (!(MyFlags & MY_DONT_SORT))
qsort((void *) result->dir_entry, result->number_off_files,
sizeof(FILEINFO), (qsort_cmp) comp_names);
- DBUG_PRINT(exit, ("found %d files", result->number_off_files));
+ DBUG_PRINT("exit", ("found %d files", result->number_off_files));
DBUG_RETURN(result);
error:
my_errno=errno;
diff --git a/mysys/my_libwrap.c b/mysys/my_libwrap.c
new file mode 100644
index 00000000000..be8adbab0a1
--- /dev/null
+++ b/mysys/my_libwrap.c
@@ -0,0 +1,42 @@
+/* Copyright (C) 2003 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 */
+
+/*
+ This is needed to be able to compile with original libwrap header
+ files that don't have the prototypes
+*/
+
+#include <my_global.h>
+#include <my_libwrap.h>
+
+#ifdef HAVE_LIBWRAP
+
+void my_fromhost(struct request_info *req)
+{
+ fromhost(req);
+}
+
+int my_hosts_access(struct request_info *req)
+{
+ hosts_access(req);
+}
+
+char *my_eval_client(struct request_info *req)
+{
+ eval_client(req);
+}
+
+#endif /* HAVE_LIBWRAP */
diff --git a/mysys/my_memmem.c b/mysys/my_memmem.c
index 682a1314f09..86916bff860 100644
--- a/mysys/my_memmem.c
+++ b/mysys/my_memmem.c
@@ -1,4 +1,21 @@
-#include "my_base.h"
+/* Copyright (C) 2000 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 <m_string.h>
/*
my_memmem, port of a GNU extension.
diff --git a/mysys/my_pread.c b/mysys/my_pread.c
index 3d02e368720..ac52895efe9 100644
--- a/mysys/my_pread.c
+++ b/mysys/my_pread.c
@@ -27,7 +27,7 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
myf MyFlags)
{
uint readbytes;
- int error;
+ int error= 0;
DBUG_ENTER("my_pread");
DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: 0x%lx Count: %u MyFlags: %d",
Filedes, (ulong) offset, Buffer, Count, MyFlags));
@@ -38,17 +38,40 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
errno=0; /* Linux doesn't reset this */
#endif
#ifndef HAVE_PREAD
+ off_t old_offset;
+
pthread_mutex_lock(&my_file_info[Filedes].mutex);
- readbytes= (uint) -1;
- error= (lseek(Filedes, offset, MY_SEEK_SET) == -1L ||
- (readbytes = (uint) read(Filedes, Buffer, Count)) != Count);
+ /*
+ As we cannot change the file pointer, we save the old position,
+ before seeking to the given offset
+ */
+
+ error= (old_offset= lseek(Filedes, 0L, MY_SEEK_CUR)) == -1L ||
+ lseek(Filedes, offset, MY_SEEK_SET) == -1L;
+
+ if (!error) /* Seek was successful */
+ {
+ if ((readbytes = (uint) read(Filedes, Buffer, Count)) == -1L)
+ my_errno= errno;
+
+ /*
+ We should seek back, even if read failed. If this fails,
+ we will return an error. If read failed as well, we will
+ save the errno from read, not from lseek().
+ */
+ if ((error= (lseek(Filedes, old_offset, MY_SEEK_SET) == -1L)) &&
+ readbytes != -1L)
+ my_errno= errno;
+ }
+
pthread_mutex_unlock(&my_file_info[Filedes].mutex);
#else
- error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count);
+ if ((error= ((readbytes =
+ (uint) pread(Filedes, Buffer, Count, offset)) != Count)))
+ my_errno= errno;
#endif
- if (error)
+ if (error || readbytes != Count)
{
- my_errno=errno;
DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
readbytes,Count,Filedes,my_errno));
#ifdef THREAD
@@ -89,17 +112,41 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
for (;;)
{
#ifndef HAVE_PREAD
- int error;
+ int error= 0;
+ off_t old_offset;
writenbytes= (uint) -1;
pthread_mutex_lock(&my_file_info[Filedes].mutex);
- error=(lseek(Filedes, offset, MY_SEEK_SET) != -1L &&
- (writenbytes = (uint) write(Filedes, Buffer, Count)) == Count);
+
+ /*
+ As we cannot change the file pointer, we save the old position,
+ before seeking to the given offset
+ */
+ error= ((old_offset= lseek(Filedes, 0L, MY_SEEK_CUR)) == -1L ||
+ lseek(Filedes, offset, MY_SEEK_SET) == -1L);
+
+ if (!error) /* Seek was successful */
+ {
+ if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == -1L)
+ my_errno= errno;
+
+ /*
+ We should seek back, even if write failed. If this fails,
+ we will return an error. If write failed as well, we will
+ save the errno from write, not from lseek().
+ */
+ if ((error= (lseek(Filedes, old_offset, MY_SEEK_SET) == -1L)) &&
+ writenbytes != -1L)
+ my_errno= errno;
+ }
pthread_mutex_unlock(&my_file_info[Filedes].mutex);
- if (error)
+
+ if (!error && writenbytes == Count)
break;
#else
if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count)
break;
+ else
+ my_errno= errno;
#endif
if ((int) writenbytes != -1)
{ /* Safegueard */
@@ -108,7 +155,6 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
Count-=writenbytes;
offset+=writenbytes;
}
- my_errno=errno;
DBUG_PRINT("error",("Write only %d bytes",writenbytes));
#ifndef NO_BACKGROUND
#ifdef THREAD
diff --git a/mysys/thr_lock.c b/mysys/thr_lock.c
index b4de57229bf..74d6f7431a8 100644
--- a/mysys/thr_lock.c
+++ b/mysys/thr_lock.c
@@ -1123,10 +1123,12 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
enum thr_lock_type new_lock_type)
{
THR_LOCK *lock=in_data->lock;
- THR_LOCK_DATA *data, *next;
enum thr_lock_type old_lock_type= in_data->type;
+#ifdef TO_BE_REMOVED
+ THR_LOCK_DATA *data, *next;
bool start_writers= FALSE;
bool start_readers= FALSE;
+#endif
DBUG_ENTER("thr_downgrade_write_only_lock");
pthread_mutex_lock(&lock->mutex);
@@ -1134,7 +1136,8 @@ void thr_downgrade_write_lock(THR_LOCK_DATA *in_data,
DBUG_ASSERT(old_lock_type > new_lock_type);
in_data->type= new_lock_type;
check_locks(lock,"after downgrading lock",0);
-#if 0
+
+#if TO_BE_REMOVED
switch (old_lock_type)
{
case TL_WRITE_ONLY: