diff --git a/include/config-win.h b/include/config-win.h
index edfb4ecc5c77fe5047c6d589a4585bea4e59175d..528bc8a8cdd2c94d9fa5dba09147aa4372d353db 100644
--- a/include/config-win.h
+++ b/include/config-win.h
@@ -325,6 +325,11 @@ inline double ulonglong2double(ulonglong value)
 #define HAVE_SETFILEPOINTER
 #define HAVE_VIO_READ_BUFF
 
+#ifndef __NT__
+#undef FILE_SHARE_DELETE
+#define FILE_SHARE_DELETE 0     /* Not implemented on Win 98/ME */
+#endif
+
 #ifdef NOT_USED
 #define HAVE_SNPRINTF		/* Gave link error */
 #define _snprintf snprintf
diff --git a/include/my_pthread.h b/include/my_pthread.h
index 6f60a6df2c1e3ce78a3424fcb80c788770fdda72..202e047dc4e3a39d2291813e9256ecd23d39b276 100644
--- a/include/my_pthread.h
+++ b/include/my_pthread.h
@@ -643,10 +643,10 @@ extern int pthread_dummy(int);
 
 #define THREAD_NAME_SIZE 10
 #ifndef DEFAULT_THREAD_STACK
-#if defined(__ia64__)
+#if SIZEOF_CHARP > 4
 /*
   MySQL can survive with 32K, but some glibc libraries require > 128K stack
-  To resolve hostnames
+  To resolve hostnames. Also recursive stored procedures needs stack.
 */
 #define DEFAULT_THREAD_STACK	(256*1024L)
 #else
diff --git a/mysql-test/r/rpl_relayrotate.result b/mysql-test/r/rpl_relayrotate.result
index b038e7b6a3e4def2a859729404d59289a6c01cb8..20f19973d8390d73909e3a72cdb3b064c1c74a00 100644
--- a/mysql-test/r/rpl_relayrotate.result
+++ b/mysql-test/r/rpl_relayrotate.result
@@ -10,9 +10,6 @@ reset slave;
 start slave;
 stop slave;
 start slave;
-select master_pos_wait('master-bin.001',3000)>=0;
-master_pos_wait('master-bin.001',3000)>=0
-1
 select max(a) from t1;
 max(a)
 8000
diff --git a/mysql-test/t/mysqltest.test b/mysql-test/t/mysqltest.test
index 8ccf2cb0c7a81bc0e3afd998961595f76e0868e4..440a7787985dcd130a1e485f1bf95eb5642afd83 100644
--- a/mysql-test/t/mysqltest.test
+++ b/mysql-test/t/mysqltest.test
@@ -968,9 +968,9 @@ drop table t1;
 
 --error 1
 --exec $MYSQL_TEST --record -x $MYSQL_TEST_DIR/var/tmp/bug11731.sql -R $MYSQL_TEST_DIR/var/tmp/bug11731.out
-# The .out file should be empty, cat will fail!
+# The .out file should be empty
 --error 1
---exec cat $MYSQL_TEST_DIR/var/tmp/bug11731.out
+--exec test -s $MYSQL_TEST_DIR/var/tmp/bug11731.out
 drop table t1;
 
 
diff --git a/mysql-test/t/rpl_deadlock.test b/mysql-test/t/rpl_deadlock.test
index 08921caf897a7fe6b1486a9bd5b583f1292b75f2..c74ed989ece0920f586101dc7e80d7554fbdf392 100644
--- a/mysql-test/t/rpl_deadlock.test
+++ b/mysql-test/t/rpl_deadlock.test
@@ -58,7 +58,7 @@ while ($1)
 enable_query_log;
 select * from t1 for update;
 start slave;
---sleep 3 # hope that slave is blocked now
+--real_sleep 3 # hope that slave is blocked now
 insert into t2 values(22); # provoke deadlock, slave should be victim
 commit;
 sync_with_master;
@@ -76,7 +76,7 @@ change master to master_log_pos=532; # the BEGIN log event
 begin;
 select * from t2 for update; # hold lock
 start slave;
---sleep 10 # slave should have blocked, and be retrying
+--real_sleep 10 # slave should have blocked, and be retrying
 commit;
 sync_with_master;
 select * from t1; # check that slave succeeded finally
@@ -97,7 +97,7 @@ change master to master_log_pos=532;
 begin;
 select * from t2 for update;
 start slave;
---sleep 10
+--real_sleep 10
 commit;
 sync_with_master;
 select * from t1;
diff --git a/mysql-test/t/rpl_relayrotate.test b/mysql-test/t/rpl_relayrotate.test
index e9a4cdd05c5cbdeb5aaa78b635a0dda0c148ac6d..04f03367e20ca2f9c64c2a29de67e4334534da7c 100644
--- a/mysql-test/t/rpl_relayrotate.test
+++ b/mysql-test/t/rpl_relayrotate.test
@@ -52,9 +52,8 @@ start slave;
 # which proves that the transaction restarted at
 # the right place.
 # We must wait for the transaction to commit before
-# reading, MASTER_POS_WAIT() will do it for sure
-# (the only statement with position>=3000 is COMMIT).
-select master_pos_wait('master-bin.001',3000)>=0;
+# reading:
+sync_with_master;
 select max(a) from t1;
 connection master;
 
diff --git a/mysql-test/t/symlink.test b/mysql-test/t/symlink.test
index b7a7e83d569b94d70c9dec0c1fef059859a93aa1..6a6dd305006aef01fbebbe3519243534a922844b 100644
--- a/mysql-test/t/symlink.test
+++ b/mysql-test/t/symlink.test
@@ -3,6 +3,8 @@ disable_query_log;
 show variables like "have_symlink";
 enable_query_log;
 
+--source include/not_windows.inc
+
 --disable_warnings
 drop table if exists t1,t2,t7,t8,t9;
 drop database if exists mysqltest;
diff --git a/mysql-test/t/trigger-compat.test b/mysql-test/t/trigger-compat.test
index ace1863917207c68baf00b9a2c8c7e90620f2ebe..c2acc235135f139134e3de05ed8ddd507d7c9976 100644
--- a/mysql-test/t/trigger-compat.test
+++ b/mysql-test/t/trigger-compat.test
@@ -61,7 +61,7 @@ CREATE TRIGGER wl2818_trg1 BEFORE INSERT ON t1
 --echo
 --echo ---> patching t1.TRG...
 
---exec grep --text -v 'definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
+--exec grep -v 'definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
 --exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG
 
 #
diff --git a/mysql-test/t/trigger-grant.test b/mysql-test/t/trigger-grant.test
index c058816ee757cef1234eeea5dd5a0ec20472a43b..deeaeacbccc712217d1465f4a8a0297982b06221 100644
--- a/mysql-test/t/trigger-grant.test
+++ b/mysql-test/t/trigger-grant.test
@@ -449,7 +449,7 @@ CREATE TRIGGER trg5 BEFORE DELETE ON t1
   FOR EACH ROW
     SET @a = 5;
 
---exec egrep --text -v '^definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
+--exec egrep -v '^definers=' $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG > $MYSQL_TEST_DIR/var/tmp/t1.TRG
 --exec echo "definers='' '@' '@abc@def@@' '@hostname' '@abcdef@@@hostname'" >> $MYSQL_TEST_DIR/var/tmp/t1.TRG
 --exec mv $MYSQL_TEST_DIR/var/tmp/t1.TRG $MYSQL_TEST_DIR/var/master-data/mysqltest_db1/t1.TRG
 
diff --git a/scripts/make_win_src_distribution.sh b/scripts/make_win_src_distribution.sh
index ea3ca66db6eaa1f55fad118bc0e9a6b7de05a510..53f05c131ac2efeeb2db375d36ae3d2dc27ca45c 100644
--- a/scripts/make_win_src_distribution.sh
+++ b/scripts/make_win_src_distribution.sh
@@ -199,7 +199,7 @@ copy_dir_files()
        print_debug "Creating directory '$arg'"
        mkdir $BASE/$arg
      fi
-    for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp *.dsp *.dsw \
+    for i in *.c *.cpp *.h *.ih *.i *.ic *.asm *.def *.hpp \
              README INSTALL* LICENSE AUTHORS NEWS ChangeLog \
              *.inc *.test *.result *.pem Moscow_leap des_key_file \
              *.vcproj *.sln *.dat *.000001 *.require *.opt
@@ -342,7 +342,7 @@ mv $BASE/sql/sql_yacc.cpp-new $BASE/sql/sql_yacc.cpp
 #
 # Search the tree for plain text files and adapt the line end marker
 #
-find $BASE \( -name "*.dsp" -o -name "*.dsw" -o -name "*.cnf" -o -name "*.ini" \
+find $BASE \( -name "*.cnf" -o -name "*.ini" \
            -o -name COPYING -o -name ChangeLog -o -name EXCEPTIONS-CLIENT \
            -o -name "INSTALL*" -o -name LICENSE -o -name "README*" \
            -o -name "*.vcproj" -o -name "*.sln" \) -type f -print \
diff --git a/sql/mysqld.cc b/sql/mysqld.cc
index cd0c2d736c21feb2b7d98dabc5a2c9a1e689289c..aaa467603f530edb1029993b46c527cd03c531ef 100644
--- a/sql/mysqld.cc
+++ b/sql/mysqld.cc
@@ -6358,7 +6358,7 @@ static void mysql_init_variables(void)
 #else
   have_openssl=SHOW_OPTION_NO;
 #endif
-#if !defined(HAVE_REALPATH) || defined(HAVE_BROKEN_REALPATH)
+#ifdef HAVE_BROKEN_REALPATH
   have_symlink=SHOW_OPTION_NO;
 #else
   have_symlink=SHOW_OPTION_YES;
@@ -7053,7 +7053,7 @@ static void get_options(int argc,char **argv)
     usage();
     exit(0);
   }
-#if !defined(HAVE_REALPATH) || defined(HAVE_BROKEN_REALPATH)
+#if defined(HAVE_BROKEN_REALPATH)
   my_use_symdir=0;
   my_disable_symlinks=1;
   have_symlink=SHOW_OPTION_NO;
diff --git a/sql/sp_head.cc b/sql/sp_head.cc
index 18bcd8b94d0c6caabb8061a6c0dcd6cd6d4a7e24..88d3ed83278547df617250d85a18f5069cbb2218 100644
--- a/sql/sp_head.cc
+++ b/sql/sp_head.cc
@@ -880,7 +880,7 @@ void sp_head::recursion_level_error()
     THD *thd= current_thd;
     my_error(ER_SP_RECURSION_LIMIT, MYF(0),
              thd->variables.max_sp_recursion_depth,
-             m_name);
+             m_name.str);
   }
   else
     my_error(ER_SP_NO_RECURSION, MYF(0));
diff --git a/sql/table.cc b/sql/table.cc
index 268d7a0be490484d0ae7ce78f19c0a9f4290c898..fc75568b6152799b8992f3ee16f783cdddb2c623 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1403,13 +1403,12 @@ File create_frm(THD *thd, my_string name, const char *db,
   if (create_info->options & HA_LEX_CREATE_TMP_TABLE)
     create_flags|= O_EXCL | O_NOFOLLOW;
 
-#if SIZEOF_OFF_T > 4
   /* Fix this when we have new .frm files;  Current limit is 4G rows (QQ) */
   if (create_info->max_rows > UINT_MAX32)
     create_info->max_rows= UINT_MAX32;
   if (create_info->min_rows > UINT_MAX32)
     create_info->min_rows= UINT_MAX32;
-#endif
+
   /*
     Ensure that raid_chunks can't be larger than 255, as this would cause
     problems with drop database