List:Commits« Previous MessageNext Message »
From:sergeyv Date:April 3 2006 6:11pm
Subject:bk commit into 5.2 tree (SergeyV:1.2154)
View as plain text  
Below is the list of changes that have just been committed into a local
5.2 repository of sergeyv. When sergeyv does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.2154 06/04/03 20:11:00 SergeyV@selena. +25 -0
  WIN32 native IO patch.

  sql/ha_innodb.cc
    1.262 06/04/03 20:10:40 SergeyV@selena. +17 -5
    innobase_tempfile function changed to work properly with win32 native IO

  mysys/my_write.c
    1.12 06/04/03 20:10:39 SergeyV@selena. +23 -10
    my_write() - native win32 IO implementation

  mysys/my_sync.c
    1.5 06/04/03 20:10:38 SergeyV@selena. +2 -1
    my_sync() - native win32 IO implementation

  mysys/my_seek.c
    1.12 06/04/03 20:10:37 SergeyV@selena. +40 -1
    my_seek() - native win32 IO implementation

  mysys/my_read.c
    1.8 06/04/03 20:10:37 SergeyV@selena. +8 -1
    my_read() - native win32 IO implementation

  mysys/my_quick.c
    1.5 06/04/03 20:10:36 SergeyV@selena. +26 -2
    my_quick() - native win32 IO implementation

  mysys/my_pread.c
    1.11 06/04/03 20:10:35 SergeyV@selena. +44 -14
    my_pread() - native win32 IO implementation

  mysys/my_open.c
    1.26 06/04/03 20:10:34 SergeyV@selena. +111 -164
    my_getoshandle added to resolve win32 handle by internal file number
    my_make_winflags added to map POSIX IO flags into win32 IO flags
    my_register_filename updated to store native win32 handle and append flag for file
    my_open updated to support native win32 IO

  mysys/my_net.c
    1.8 06/04/03 20:10:34 SergeyV@selena. +5 -0
    Removed unnecessary critical section for win32

  mysys/my_lwrite.c
    1.7 06/04/03 20:10:33 SergeyV@selena. +17 -4
    my_lwrite() - native win32 IO implementation

  mysys/my_lread.c
    1.6 06/04/03 20:10:32 SergeyV@selena. +8 -1
    my_lread() - native win32 IO implementation

  mysys/my_lock.c
    1.13 06/04/03 20:10:31 SergeyV@selena. +15 -1
    my_lock() - native win32 IO implementation

  mysys/my_lib.c
    1.23 06/04/03 20:10:31 SergeyV@selena. +42 -1
    Added functions to retrieve file stat on win32 with native win32 IO API

  mysys/my_init.c
    1.46 06/04/03 20:10:30 SergeyV@selena. +2 -0
    DBUG_VOID_RETURN removed from my_end, since it is not valid after my_thread_end()

  mysys/my_gethostbyname.c
    1.8 06/04/03 20:10:29 SergeyV@selena. +9 -0
    Removed critical section for win32

  mysys/my_fopen.c
    1.16 06/04/03 20:10:28 SergeyV@selena. +58 -10
    my_fdopen() - native win32 implementation
    my_fileno() - function added to resolve File* into internal file number

  mysys/my_error.c
    1.22 06/04/03 20:10:27 SergeyV@selena. +9 -0
    Added my_dosmaperr() to do mapping between win32 and libc.

  mysys/my_dup.c
    1.5 06/04/03 20:10:26 SergeyV@selena. +14 -1
    my_dup native win32 IO implementation

  mysys/my_create.c
    1.14 06/04/03 20:10:26 SergeyV@selena. +27 -4
    my_create() native win32 IO implementation

  mysys/my_chsize.c
    1.18 06/04/03 20:10:25 SergeyV@selena. +3 -3
    my_chsize() native win32 IO implementation

  mysys/mf_tempfile.c
    1.25 06/04/03 20:10:24 SergeyV@selena. +1 -1
    2 new arguments added in my_register_filename

  mysys/charset.c
    1.148 06/04/03 20:10:23 SergeyV@selena. +1 -1
    read() changed to my_read in order to work properly with native win32 IO

  include/my_sys.h
    1.189 06/04/03 20:10:23 SergeyV@selena. +14 -3
    Added number of definitions for native win32 IO support

  include/my_pthread.h
    1.92 06/04/03 20:10:22 SergeyV@selena. +1 -1
    pthread_mutex_trylock redefined for correct usage

  VC++Files/mysql.sln
    1.17 06/04/03 20:10:21 SergeyV@selena. +43 -0
    mysql.sln is updated to include gen_lex_hash project

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	SergeyV
# Host:	selena.
# Root:	H:/MYSQL/src/$00010-mysql-5.2

--- 1.91/include/my_pthread.h	2005-12-20 16:54:43 +03:00
+++ 1.92/include/my_pthread.h	2006-04-03 20:10:22 +04:00
@@ -149,7 +149,7 @@
 #else
 #define pthread_mutex_init(A,B)  (InitializeCriticalSection(A),0)
 #define pthread_mutex_lock(A)	 (EnterCriticalSection(A),0)
-#define pthread_mutex_trylock(A) (WaitForSingleObject((A), 0) == WAIT_TIMEOUT)
+#define pthread_mutex_trylock(A) (TryEnterCriticalSection(A) == 0)
 #define pthread_mutex_unlock(A)  LeaveCriticalSection(A)
 #define pthread_mutex_destroy(A) DeleteCriticalSection(A)
 #define my_pthread_setprio(A,B)  SetThreadPriority(GetCurrentThread(), (B))

--- 1.188/include/my_sys.h	2006-02-25 00:20:42 +03:00
+++ 1.189/include/my_sys.h	2006-04-03 20:10:23 +04:00
@@ -309,13 +309,15 @@
 enum file_type
 {
   UNOPEN = 0, FILE_BY_OPEN, FILE_BY_CREATE, STREAM_BY_FOPEN, STREAM_BY_FDOPEN,
-  FILE_BY_MKSTEMP, FILE_BY_DUP
+  FILE_BY_MKSTEMP, FILE_BY_DUP, FILE_DES_RESERVED
 };
 
 struct st_my_file_info
 {
   my_string		name;
   enum file_type	type;
+  int os_handle;
+  int append_flag;
 #if defined(THREAD) && !defined(HAVE_PREAD)
   pthread_mutex_t	mutex;
 #endif
@@ -557,11 +559,20 @@
 extern File my_open(const char *FileName,int Flags,myf MyFlags);
 extern File my_register_filename(File fd, const char *FileName,
 				 enum file_type type_of_file,
-				 uint error_message_number, myf MyFlags);
+                                 uint error_message_number, myf MyFlags,
+                                 int os_handle, int append_flag);
 extern File my_create(const char *FileName,int CreateFlags,
 		      int AccsesFlags, myf MyFlags);
 extern int my_close(File Filedes,myf MyFlags);
 extern File my_dup(File file, myf MyFlags);
+#ifdef __WIN__
+extern void my_make_winflags(int Flags, DWORD *CreationDisposition,
+                             DWORD *DesiredAccess, DWORD *ShareMode,
+                             DWORD *FlagsAndAttributes);
+extern int my_nextfd();
+extern int my_getoshandle(File file);
+extern int my_dosmaperr();
+#endif
 extern int my_mkdir(const char *dir, int Flags, myf MyFlags);
 extern int my_readlink(char *to, const char *filename, myf MyFlags);
 extern int my_realpath(char *to, const char *filename, myf MyFlags);
@@ -603,7 +614,6 @@
 
 #ifdef __WIN__
 extern int my_access(const char *path, int amode);
-extern File my_sopen(const char *path, int oflag, int shflag, int pmode);
 #else
 #define my_access access
 #endif
@@ -615,6 +625,7 @@
 extern void init_glob_errs(void);
 extern FILE *my_fopen(const char *FileName,int Flags,myf MyFlags);
 extern FILE *my_fdopen(File Filedes,const char *name, int Flags,myf MyFlags);
+extern int my_fileno(FILE *fd);
 extern int my_fclose(FILE *fd,myf MyFlags);
 extern int my_chsize(File fd,my_off_t newlength, int filler, myf MyFlags);
 extern int my_sync(File fd, myf my_flags);

--- 1.147/mysys/charset.c	2005-10-20 10:12:26 +04:00
+++ 1.148/mysys/charset.c	2006-04-03 20:10:23 +04:00
@@ -325,7 +325,7 @@
     my_free(buf,myflags);
     return TRUE;
   }
-  len=read(fd,buf,len);
+  len= my_read(fd, buf, len, 0);
   my_close(fd,myflags);
   
   if (my_parse_charset_xml(buf,len,add_collation))

--- 1.17/mysys/my_chsize.c	2005-05-16 01:53:56 +04:00
+++ 1.18/mysys/my_chsize.c	2006-04-03 20:10:25 +04:00
@@ -54,16 +54,16 @@
 #if defined(HAVE_SETFILEPOINTER)
   /* This is for the moment only true on windows */
     long is_success;
-    HANDLE win_file= (HANDLE) _get_osfhandle(fd);
+    HANDLE win_file= (HANDLE)my_getoshandle(fd);
     long length_low, length_high;
     length_low= (long) (ulong) newlength;
     length_high= (long) ((ulonglong) newlength >> 32);
     is_success= SetFilePointer(win_file, length_low, &length_high, FILE_BEGIN);
-    if (is_success == -1 && (my_errno= GetLastError()) != NO_ERROR)
+    if (is_success == -1 && (my_errno= my_dosmaperr()) != NO_ERROR)
       goto err;
     if (SetEndOfFile(win_file))
       DBUG_RETURN(0);
-    my_errno= GetLastError();
+    my_errno= my_dosmaperr();
     goto err;
 #elif defined(HAVE_FTRUNCATE)
     if (ftruncate(fd, (off_t) newlength))

--- 1.13/mysys/my_create.c	2005-11-22 03:02:33 +03:00
+++ 1.14/mysys/my_create.c	2006-04-03 20:10:26 +04:00
@@ -36,7 +36,7 @@
 File my_create(const char *FileName, int CreateFlags, int access_flags,
 	       myf MyFlags)
 {
-  int fd;
+  int fd, os_handle= 0, append_flag= 0;
   DBUG_ENTER("my_create");
   DBUG_PRINT("my",("Name: '%s' CreateFlags: %d  AccessFlags: %d  MyFlags: %d",
 		   FileName, CreateFlags, access_flags, MyFlags));
@@ -55,12 +55,35 @@
     fd =  open((my_string) FileName, access_flags | O_CREAT | O_BINARY,
 	       MY_S_IREAD | MY_S_IWRITE);
 #elif defined(__WIN__)
-  fd= my_sopen((my_string) FileName, access_flags | O_CREAT | O_BINARY,
-	       SH_DENYNO, MY_S_IREAD | MY_S_IWRITE);
+  {
+    DWORD CreationDisposition= 0, DesiredAccess= 0,
+          ShareMode= 0, FlagsAndAttributes= 0;
+
+    /* Force create file flag */
+    access_flags|= O_CREAT;
+
+    /* Emulate O_APPEND */
+    append_flag= access_flags & O_APPEND;
+
+    /* Convert open() flags into Win32 flags */
+    my_make_winflags(access_flags, &CreationDisposition, &DesiredAccess,
+                     &ShareMode, &FlagsAndAttributes);
+
+    /* Open Win32 file handle */
+    os_handle= (int)CreateFile(FileName, DesiredAccess, ShareMode, NULL,
+                               CreationDisposition, 0, NULL);
+
+    /* Emulate C runtime file handle */
+    if (os_handle == (int)INVALID_HANDLE_VALUE)
+      fd= -1;
+    else
+      fd= my_nextfd();
+  }
 #else
   fd = open(FileName, access_flags);
 #endif
 
   DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_CREATE,
-				   EE_CANTCREATEFILE, MyFlags));
+				                           EE_CANTCREATEFILE, MyFlags,
+                                   os_handle, append_flag));
 } /* my_create */

--- 1.21/mysys/my_error.c	2006-01-03 19:54:34 +03:00
+++ 1.22/mysys/my_error.c	2006-04-03 20:10:27 +04:00
@@ -250,3 +250,12 @@
   
   return errmsgs;
 }
+
+#ifdef __WIN__
+extern void __cdecl _dosmaperr(int);
+int my_dosmaperr()
+{
+  _dosmaperr(GetLastError());
+  return errno;
+}
+#endif

--- 1.15/mysys/my_fopen.c	2005-06-21 19:18:50 +04:00
+++ 1.16/mysys/my_fopen.c	2006-04-03 20:10:28 +04:00
@@ -38,6 +38,7 @@
 FILE *my_fopen(const char *filename, int flags, myf MyFlags)
 {
   FILE *fd;
+  int filenum;
   char type[5];
   DBUG_ENTER("my_fopen");
   DBUG_PRINT("my",("Name: '%s'  flags: %d  MyFlags: %d",
@@ -63,21 +64,30 @@
   if (fd != 0)
   {
     /*
+      Under Win32 we emulate a C runtime file handle instead of using fileno()
+    */
+#ifdef __WIN__
+    filenum= my_nextfd();
+    my_file_info[filenum].os_handle= _get_osfhandle(fileno(fd));
+#else
+    filenum= fileno(fd);
+#endif
+    /*
       The test works if MY_NFILE < 128. The problem is that fileno() is char
       on some OS (SUNOS). Actually the filename save isn't that important
       so we can ignore if this doesn't work.
     */
-    if ((uint) fileno(fd) >= my_file_limit)
+    if ((uint) filenum >= my_file_limit)
     {
       thread_safe_increment(my_stream_opened,&THR_LOCK_open);
       DBUG_RETURN(fd);				/* safeguard */
     }
     pthread_mutex_lock(&THR_LOCK_open);
-    if ((my_file_info[fileno(fd)].name = (char*)
+    if ((my_file_info[filenum].name = (char*)
 	 my_strdup(filename,MyFlags)))
     {
       my_stream_opened++;
-      my_file_info[fileno(fd)].type = STREAM_BY_FOPEN;
+      my_file_info[filenum].type = STREAM_BY_FOPEN;
       pthread_mutex_unlock(&THR_LOCK_open);
       DBUG_PRINT("exit",("stream: 0x%lx",fd));
       DBUG_RETURN(fd);
@@ -106,7 +116,9 @@
   DBUG_PRINT("my",("stream: 0x%lx  MyFlags: %d",fd, MyFlags));
 
   pthread_mutex_lock(&THR_LOCK_open);
-  file=fileno(fd);
+
+  file= my_fileno(fd);
+
   if ((err = fclose(fd)) < 0)
   {
     my_errno=errno;
@@ -122,6 +134,7 @@
     my_free(my_file_info[file].name, MYF(MY_ALLOW_ZERO_PTR));
   }
   pthread_mutex_unlock(&THR_LOCK_open);
+
   DBUG_RETURN(err);
 } /* my_fclose */
 
@@ -132,13 +145,26 @@
 FILE *my_fdopen(File Filedes, const char *name, int Flags, myf MyFlags)
 {
   FILE *fd;
+  int file;
   char type[5];
   DBUG_ENTER("my_fdopen");
   DBUG_PRINT("my",("Fd: %d  Flags: %d  MyFlags: %d",
 		   Filedes, Flags, MyFlags));
 
   make_ftype(type,Flags);
-  if ((fd = fdopen(Filedes, type)) == 0)
+#ifdef __WIN__
+  /*
+    Here we convert the os_handle (Win32 HANDLE) to a C runtime
+    handle via _open_osfhandle() and then do an fdopen() on that
+    handle.  The C runtime handle is automatically closed by fclose()
+  */
+  file= _open_osfhandle(my_getoshandle(Filedes),Flags);
+  fd= fdopen(file,type);
+#else
+  fd= fdopen(Filedes,type);
+#endif
+
+  if (fd == 0)
   {
     my_errno=errno;
     if (MyFlags & (MY_FAE | MY_WME))
@@ -151,13 +177,9 @@
     if ((uint) Filedes < (uint) my_file_limit)
     {
       if (my_file_info[Filedes].type != UNOPEN)
-      {
         my_file_opened--;		/* File is opened with my_open ! */
-      }
       else
-      {
-        my_file_info[Filedes].name=  my_strdup(name,MyFlags);
-      }
+        my_file_info[Filedes].name= my_strdup(name ? name : "unknown" ,MyFlags);
       my_file_info[Filedes].type = STREAM_BY_FDOPEN;
     }
     pthread_mutex_unlock(&THR_LOCK_open);
@@ -221,3 +243,29 @@
 #endif  
   *to='\0';
 } /* make_ftype */
+
+
+/*
+  Resolve a FILE* to its C runtime file descriptor (virtual under Win32)
+*/
+
+int my_fileno(FILE *fd)
+{
+#ifndef __WIN__
+  return fileno(fd);
+#else
+  int filenum;
+  int handle= _get_osfhandle(fileno(fd));
+  pthread_mutex_lock(&THR_LOCK_open);
+  for(filenum= 3; filenum < MY_NFILE; filenum++)
+  {
+    if (my_file_info[filenum].type == STREAM_BY_FOPEN)
+      if (my_file_info[filenum].os_handle == handle)
+        break;
+  }
+  pthread_mutex_unlock(&THR_LOCK_open);
+  if (filenum == MY_NFILE)
+    filenum= -1;
+  return filenum;
+#endif
+}

--- 1.45/mysys/my_init.c	2006-02-15 02:01:34 +03:00
+++ 1.46/mysys/my_init.c	2006-04-03 20:10:30 +04:00
@@ -214,7 +214,9 @@
     WSACleanup();
 #endif /* __WIN__ */
   my_init_done=0;
+#ifndef __WIN__
   DBUG_VOID_RETURN;
+#endif
 } /* my_end */
 
 

--- 1.22/mysys/my_lib.c	2006-01-24 14:59:02 +03:00
+++ 1.23/mysys/my_lib.c	2006-04-03 20:10:31 +04:00
@@ -613,14 +613,55 @@
 ** Note that MY_STAT is assumed to be same as struct stat
 ****************************************************************************/ 
 
+#ifdef __WIN__
+time_t FILETIME_to_time_t(FILETIME ftime)
+{
+  const __int64 Epoch= 116444736000000000;
+  const __int64 Increments= 10000000;
+
+  LARGE_INTEGER seconds;
+  seconds.LowPart= ftime.dwLowDateTime;
+  seconds.HighPart= ftime.dwHighDateTime;
+
+  /* Convert from January 1, 1601 to January 1, 1970 */
+  seconds.QuadPart-= Epoch;
+
+  /* Convert from 100 nanosecond intervals to seconds */
+  seconds.QuadPart/= Increments;
+
+  return (time_t)seconds.QuadPart;
+}
+
+int win_stat(int Filedes,struct stat *stat_area)
+{
+  BY_HANDLE_FILE_INFORMATION FileInfo;
+  memset(stat_area,0,sizeof(struct stat));
+  if (!GetFileInformationByHandle((HANDLE)my_getoshandle(Filedes),
+                                  &FileInfo))
+  {
+    return my_dosmaperr();
+  }
+  stat_area->st_ctime= FILETIME_to_time_t(FileInfo.ftCreationTime);
+  stat_area->st_mtime= FILETIME_to_time_t(FileInfo.ftLastWriteTime);
+  stat_area->st_atime= FILETIME_to_time_t(FileInfo.ftLastAccessTime);
+  stat_area->st_size= FileInfo.nFileSizeLow;
+  stat_area->st_dev= 0;
+  stat_area->st_nlink= (short)FileInfo.nNumberOfLinks;
+  return 0;
+}
+#endif
+
 int my_fstat(int Filedes, MY_STAT *stat_area,
              myf MyFlags __attribute__((unused)))
 {
   DBUG_ENTER("my_fstat");
   DBUG_PRINT("my",("fd: %d MyFlags: %d",Filedes,MyFlags));
+#ifdef __WIN__
+  DBUG_RETURN(win_stat(Filedes, (struct stat *) stat_area));
+#else
   DBUG_RETURN(fstat(Filedes, (struct stat *) stat_area));
+#endif
 }
-
 
 MY_STAT *my_stat(const char *path, MY_STAT *stat_area, myf my_flags)
 {

--- 1.12/mysys/my_lock.c	2004-06-27 20:17:23 +04:00
+++ 1.13/mysys/my_lock.c	2006-04-03 20:10:31 +04:00
@@ -101,8 +101,22 @@
    if (!_lock64( fd, locktype, start, length, MyFlags))
     DBUG_RETURN(0);
 
-#elif defined(HAVE_LOCKING)
+#elif defined(__WIN__)
   /* Windows */
+  {
+    my_bool error;
+    ULARGE_INTEGER Offset, Length;
+    Offset.QuadPart= start;
+    Length.QuadPart= length;
+    error= LockFile((HANDLE)my_getoshandle(fd),
+                    Offset.LowPart, Offset.HighPart,
+                    Length.LowPart, Length.HighPart);
+    if (!error)
+      DBUG_RETURN(0);
+
+    my_dosmaperr();
+  }
+#elif defined(HAVE_LOCKING)
   {
     my_bool error;
     pthread_mutex_lock(&my_file_info[fd].mutex);

--- 1.5/mysys/my_lread.c	2001-12-06 15:10:42 +03:00
+++ 1.6/mysys/my_lread.c	2006-04-03 20:10:32 +04:00
@@ -30,8 +30,15 @@
   DBUG_PRINT("my",("Fd: %d  Buffer: %ld  Count: %ld  MyFlags: %d",
 		   Filedes, Buffer, Count, MyFlags));
 
+#ifdef __WIN__
+  ReadFile((HANDLE)my_getoshandle(Filedes),
+           Buffer, (DWORD)Count, &readbytes, NULL);
+  my_dosmaperr();
+#else
   /* Temp hack to get count to int32 while read wants int */
-  if ((readbytes = (uint32) read(Filedes, Buffer, (uint) Count)) != Count)
+  readbytes= (uint32) read(Filedes, Buffer, (uint) Count);
+#endif
+  if (readbytes != Count)
   {
     my_errno=errno;
     if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))

--- 1.6/mysys/my_lwrite.c	2004-08-23 14:46:49 +04:00
+++ 1.7/mysys/my_lwrite.c	2006-04-03 20:10:33 +04:00
@@ -21,16 +21,29 @@
 
 uint32 my_lwrite(int Filedes, const byte *Buffer, uint32 Count, myf MyFlags)
 {
-  uint32 writenbytes;
+  uint32 writtenbytes;
   DBUG_ENTER("my_lwrite");
   DBUG_PRINT("my",("Fd: %d  Buffer: 0x%lx  Count: %ld  MyFlags: %d",
 		   Filedes, Buffer, Count, MyFlags));
 
+#ifdef __WIN__
+  /* Emulate O_APPEND */
+  if (my_file_info[Filedes].append_flag)
+    SetFilePointer((HANDLE)my_getoshandle(Filedes), 0, 0, FILE_END);
+
+  WriteFile((HANDLE)my_getoshandle(Filedes), Buffer, Count,
+            &writtenbytes, NULL);
+
+  my_dosmaperr();
+#else
   /* Temp hack to get count to int32 while write wants int */
-  if ((writenbytes = (uint32) write(Filedes, Buffer, (uint) Count)) != Count)
+  writtenbytes= (uint32) write(Filedes, Buffer, (uint) Count);
+#endif
+
+  if (writtenbytes != Count)
   {
     my_errno=errno;
-    if (writenbytes == (uint32) -1 || MyFlags & (MY_NABP | MY_FNABP))
+    if (writtenbytes == (uint32) -1 || MyFlags & (MY_NABP | MY_FNABP))
     {
       if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
       {
@@ -42,5 +55,5 @@
   }
   if (MyFlags & (MY_NABP | MY_FNABP))
     DBUG_RETURN(0);			/* Ok vid l{sning */
-  DBUG_RETURN(writenbytes);
+  DBUG_RETURN(writtenbytes);
 } /* my_lwrite */

--- 1.7/mysys/my_net.c	2002-08-12 04:42:36 +04:00
+++ 1.8/mysys/my_net.c	2006-04-03 20:10:34 +04:00
@@ -36,8 +36,13 @@
 void my_inet_ntoa(struct in_addr in, char *buf)
 {
   char *ptr;
+  /* inet_ntoa() is thread-safe on Windows, so no need for mutex. */
+#ifndef __WIN__
   pthread_mutex_lock(&THR_LOCK_net);
+#endif
   ptr=inet_ntoa(in);
   strmov(buf,ptr);
+#ifndef __WIN__
   pthread_mutex_unlock(&THR_LOCK_net);
+#endif
 }

--- 1.25/mysys/my_open.c	2005-11-28 12:26:41 +03:00
+++ 1.26/mysys/my_open.c	2006-04-03 20:10:34 +04:00
@@ -42,6 +42,7 @@
 				/* Special flags */
 {
   File fd;
+  int os_handle= 0, append_flag=0;
   DBUG_ENTER("my_open");
   DBUG_PRINT("my",("Name: '%s'  Flags: %d  MyFlags: %d",
 		   FileName, Flags, MyFlags));
@@ -54,18 +55,37 @@
   {
     errno= EACCES;
     DBUG_RETURN(my_register_filename(-1, FileName, FILE_BY_OPEN,
-                                     EE_FILENOTFOUND, MyFlags));
+                                     EE_FILENOTFOUND, MyFlags, 0, 0));
   }
-#ifndef __WIN__
+
+#if defined(__WIN__)
+  {
+    DWORD CreationDisposition= 0, DesiredAccess= 0,
+          ShareMode=0, FlagsAndAttributes= 0;
+
+    /* Emulate O_APPEND */
+    append_flag= Flags & O_APPEND;
+
+    /* Convert open() flags into Win32 flags */
+    my_make_winflags(Flags, &CreationDisposition, &DesiredAccess,
+                     &ShareMode, &FlagsAndAttributes);
+
+    /* Open Win32 file handle */
+    os_handle= (int)CreateFile(FileName, DesiredAccess, ShareMode,
+                               NULL, CreationDisposition, 0, NULL);
+
+    /* Emulate C runtime file handle */
+    if (os_handle == (int)INVALID_HANDLE_VALUE)
+      fd= -1;
+    else
+      fd= my_nextfd();
+  }
+#else
   if (Flags & O_SHARE)
     fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO,
 	       MY_S_IREAD | MY_S_IWRITE);
   else
-    fd = open((my_string) FileName, Flags | O_BINARY,
-	      MY_S_IREAD | MY_S_IWRITE);
-#else
-  fd= my_sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO,
-	       MY_S_IREAD | MY_S_IWRITE);
+    fd= open((my_string) FileName, Flags | O_BINARY, MY_S_IREAD | MY_S_IWRITE);
 #endif
 
 #elif !defined(NO_OPEN_3)
@@ -74,7 +94,8 @@
   fd = open((my_string) FileName, Flags);
 #endif
   DBUG_RETURN(my_register_filename(fd, FileName, FILE_BY_OPEN,
-				   EE_FILENOTFOUND, MyFlags));
+				                           EE_FILENOTFOUND, MyFlags,
+                                   os_handle, append_flag));
 } /* my_open */
 
 
@@ -97,13 +118,18 @@
   pthread_mutex_lock(&THR_LOCK_open);
   do
   {
+#ifndef __WIN__
     err= close(fd);
+#else
+    err= !CloseHandle((HANDLE)my_getoshandle(fd));
+    my_dosmaperr();
+#endif
   } while (err == -1 && errno == EINTR);
 
   if (err)
   {
     DBUG_PRINT("error",("Got error %d on close",err));
-    my_errno=errno;
+    my_errno= errno;
     if (MyFlags & (MY_FAE | MY_WME))
       my_error(EE_BADCLOSE, MYF(ME_BELL+ME_WAITTANG),my_filename(fd),errno);
   }
@@ -132,7 +158,8 @@
 */
 
 File my_register_filename(File fd, const char *FileName, enum file_type
-			  type_of_file, uint error_message_number, myf MyFlags)
+                          type_of_file, uint error_message_number, myf MyFlags,
+                          int os_handle, int append_flag)
 {
   if ((int) fd >= 0)
   {
@@ -154,7 +181,9 @@
     {
       my_file_opened++;
       my_file_info[fd].type = type_of_file;
-#if defined(THREAD) && !defined(HAVE_PREAD)
+      my_file_info[fd].os_handle= os_handle;
+      my_file_info[fd].append_flag= append_flag;
+#if defined(THREAD) && !defined(HAVE_PREAD) && !defined(__WIN__)
       pthread_mutex_init(&my_file_info[fd].mutex,MY_MUTEX_INIT_FAST);
 #endif
       pthread_mutex_unlock(&THR_LOCK_open);
@@ -175,179 +204,97 @@
 }
 
 #ifdef __WIN__
-
-extern void __cdecl _dosmaperr(unsigned long);
-
 /*
-  Open a file with sharing. Similar to _sopen() from libc, but allows managing
-  share delete on win32
+  Convert POSIX open() flags into Win32 CreateFile() flags
 
   SYNOPSIS
-    my_sopen()
-      path    fully qualified file name
-      oflag   operation flags
-      shflag	share flag
-      pmode   permission flags
-
-  RETURN VALUE
-    File descriptor of opened file if success
-    -1 and sets errno if fails.
+    my_make_winflags()
+      Flags                   POSIX open() flags
+      CreationDisposition     Action to take on files that exist or do not exist
+      DesiredAccess           Access to the object: r/w, read-only, write-only
+      ShareMode               Sharing mode of the object
+      FlagsAndAttributes      Other file attributes and flags
 */
 
-File my_sopen(const char *path, int oflag, int shflag, int pmode)
+void my_make_winflags(int Flags, DWORD *CreationDisposition,
+                      DWORD *DesiredAccess, DWORD *ShareMode,
+                      DWORD *FlagsAndAttributes)
 {
-  int  fh;                                /* handle of opened file */
-  int mask;
-  HANDLE osfh;                            /* OS handle of opened file */
-  DWORD fileaccess;                       /* OS file access (requested) */
-  DWORD fileshare;                        /* OS file sharing mode */
-  DWORD filecreate;                       /* OS method of opening/creating */
-  DWORD fileattrib;                       /* OS file attribute flags */
-  SECURITY_ATTRIBUTES SecurityAttributes;
-
-  SecurityAttributes.nLength= sizeof(SecurityAttributes);
-  SecurityAttributes.lpSecurityDescriptor= NULL;
-  SecurityAttributes.bInheritHandle= !(oflag & _O_NOINHERIT);
+  *FlagsAndAttributes=0;
 
-  /*
-   * decode the access flags
-   */
-  switch (oflag & (_O_RDONLY | _O_WRONLY | _O_RDWR)) {
-    case _O_RDONLY:         /* read access */
-      fileaccess= GENERIC_READ;
-      break;
-    case _O_WRONLY:         /* write access */
-      fileaccess= GENERIC_WRITE;
-      break;
-    case _O_RDWR:           /* read and write access */
-      fileaccess= GENERIC_READ | GENERIC_WRITE;
-      break;
-    default:                /* error, bad oflag */
-      errno= EINVAL;
-      _doserrno= 0L;        /* not an OS error */
-      return -1;
-  }
-
-  /*
-   * decode sharing flags
-   */
-  switch (shflag) {
-    case _SH_DENYRW:        /* exclusive access except delete */
-      fileshare= FILE_SHARE_DELETE;
-      break;
-    case _SH_DENYWR:        /* share read and delete access */
-      fileshare= FILE_SHARE_READ | FILE_SHARE_DELETE;
-      break;
-    case _SH_DENYRD:        /* share write and delete access */
-      fileshare= FILE_SHARE_WRITE | FILE_SHARE_DELETE;
-      break;
-    case _SH_DENYNO:        /* share read, write and delete access */
-      fileshare= FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
-      break;
-    case _SH_DENYRWD:       /* exclusive access */
-      fileshare= 0L;
-      break;
-    case _SH_DENYWRD:       /* share read access */
-      fileshare= FILE_SHARE_READ;
-      break;
-    case _SH_DENYRDD:       /* share write access */
-      fileshare= FILE_SHARE_WRITE;
-      break;
-    case _SH_DENYDEL:       /* share read and write access */
-      fileshare= FILE_SHARE_READ | FILE_SHARE_WRITE;
-      break;
-    default:                /* error, bad shflag */
-      errno= EINVAL;
-      _doserrno= 0L;        /* not an OS error */
-      return -1;
+  /* Creation Disposition */
+  if (Flags & O_CREAT)
+  {
+    if (Flags & O_TRUNC)
+      *CreationDisposition= CREATE_ALWAYS;
+    else if (Flags & O_EXCL)
+      *CreationDisposition= CREATE_NEW;
+    else
+      *CreationDisposition= OPEN_ALWAYS;
+  
+    if (Flags & O_TEMPORARY)
+      *FlagsAndAttributes|= FILE_FLAG_DELETE_ON_CLOSE;
   }
+  else
+    *CreationDisposition= OPEN_EXISTING;
 
-  /*
-   * decode open/create method flags
-   */
-  switch (oflag & (_O_CREAT | _O_EXCL | _O_TRUNC)) {
-    case 0:
-    case _O_EXCL:                   /* ignore EXCL w/o CREAT */
-      filecreate= OPEN_EXISTING;
-      break;
-
-    case _O_CREAT:
-      filecreate= OPEN_ALWAYS;
-      break;
-
-    case _O_CREAT | _O_EXCL:
-    case _O_CREAT | _O_TRUNC | _O_EXCL:
-      filecreate= CREATE_NEW;
-      break;
-
-    case _O_TRUNC:
-    case _O_TRUNC | _O_EXCL:        /* ignore EXCL w/o CREAT */
-      filecreate= TRUNCATE_EXISTING;
-      break;
-
-    case _O_CREAT | _O_TRUNC:
-      filecreate= CREATE_ALWAYS;
-      break;
-
-    default:
-      /* this can't happen ... all cases are covered */
-      errno= EINVAL;
-      _doserrno= 0L;
-      return -1;
-  }
+  /* Desired Access */
+  if(Flags & O_RDWR)
+    *DesiredAccess= GENERIC_READ | GENERIC_WRITE;
+  else if(Flags & O_WRONLY)
+    *DesiredAccess= GENERIC_WRITE;
+  else /* O_RDONLY */
+    *DesiredAccess= GENERIC_READ;
 
-  /*
-   * decode file attribute flags if _O_CREAT was specified
-   */
-  fileattrib= FILE_ATTRIBUTE_NORMAL;     /* default */
-  if (oflag & _O_CREAT) 
+  /* Share Modes */
+#if 0
+  if (Flags & O_SHARE)
+#endif
   {
-    _umask((mask= _umask(0)));
-    
-    if (!((pmode & ~mask) & _S_IWRITE))
-      fileattrib= FILE_ATTRIBUTE_READONLY;
+    *ShareMode= FILE_SHARE_READ | FILE_SHARE_WRITE;
+    Flags&= ~O_SHARE;
   }
 
+  /* Access Type Flags */
+  if (Flags & O_RANDOM)
+    *FlagsAndAttributes|= FILE_FLAG_RANDOM_ACCESS;
+  else if (Flags & O_SEQUENTIAL)
+    *FlagsAndAttributes|= FILE_FLAG_SEQUENTIAL_SCAN;
+}
+
   /*
-   * Set temporary file (delete-on-close) attribute if requested.
+  Emulate sequential file descriptors on platforms such as Windows that do
+  not have sequential OS file handles.
    */
-  if (oflag & _O_TEMPORARY) 
+int my_nextfd()
+{
+  int fd;
+  pthread_mutex_lock(&THR_LOCK_open);
+  for (fd= 3; fd < MY_NFILE; fd++)
   {
-    fileattrib|= FILE_FLAG_DELETE_ON_CLOSE;
-    fileaccess|= DELETE;
+    if (my_file_info[fd].type == UNOPEN)
+    {
+      /* Reserve this file descriptor entry */
+      my_file_info[fd].type= FILE_DES_RESERVED;
+      break;
+    }
   }
 
-  /*
-   * Set temporary file (delay-flush-to-disk) attribute if requested.
-   */
-  if (oflag & _O_SHORT_LIVED)
-    fileattrib|= FILE_ATTRIBUTE_TEMPORARY;
-
-  /*
-   * Set sequential or random access attribute if requested.
-   */
-  if (oflag & _O_SEQUENTIAL)
-    fileattrib|= FILE_FLAG_SEQUENTIAL_SCAN;
-  else if (oflag & _O_RANDOM)
-    fileattrib|= FILE_FLAG_RANDOM_ACCESS;
+  pthread_mutex_unlock(&THR_LOCK_open);
+  if (fd == MY_NFILE)
+    fd= -1;
+  return fd;
+}
 
-  /*
-   * try to open/create the file
-   */
-  if ((osfh= CreateFile(path, fileaccess, fileshare, &SecurityAttributes, 
-                        filecreate, fileattrib, NULL)) == (HANDLE)0xffffffff)
-  {
-    /*
-     * OS call to open/create file failed! map the error, release
-     * the lock, and return -1. note that it's not necessary to
-     * call _free_osfhnd (it hasn't been used yet).
-     */
-    _dosmaperr(GetLastError());     /* map error */
-    return -1;                      /* return error to caller */
-  }
+int my_getoshandle(File fd)
+{
+  if (fd < 3)
+    return _get_osfhandle(fd);
 
-  fh= _open_osfhandle((long)osfh, oflag & (_O_APPEND | _O_RDONLY | _O_TEXT));
+  if (my_file_info[fd].type == UNOPEN)
+    return (int)INVALID_HANDLE_VALUE;
 
-  return fh;                        /* return handle */
+  return my_file_info[fd].os_handle;
 }
+
 #endif /* __WIN__ */

--- 1.10/mysys/my_pread.c	2004-10-06 20:14:29 +04:00
+++ 1.11/mysys/my_pread.c	2006-04-03 20:10:35 +04:00
@@ -38,11 +38,25 @@
     errno=0;					/* Linux doesn't reset this */
 #endif
 #ifndef HAVE_PREAD
+#ifdef __WIN__
+    {
+      OVERLAPPED Overlapped;
+      ULARGE_INTEGER Offset;
+      Offset.QuadPart= offset;
+      ZeroMemory(&Overlapped,sizeof(Overlapped));
+      Overlapped.Offset= Offset.LowPart;
+      Overlapped.OffsetHigh= Offset.HighPart;
+      error= (!ReadFile((HANDLE)my_getoshandle(Filedes),
+                        Buffer, Count, &readbytes, &Overlapped));
+      my_dosmaperr();
+    }
+#else
     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);
     pthread_mutex_unlock(&my_file_info[Filedes].mutex);
+#endif
 #else
     error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count);
 #endif
@@ -79,7 +93,7 @@
 uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
 	       myf MyFlags)
 {
-  uint writenbytes,errors;
+  uint writtenbytes,errors;
   ulong written;
   DBUG_ENTER("my_pwrite");
   DBUG_PRINT("my",("Fd: %d  Seek: %lu  Buffer: 0x%lx  Count: %d  MyFlags: %d",
@@ -88,28 +102,44 @@
 
   for (;;)
   {
-#ifndef HAVE_PREAD
     int error;
-    writenbytes= (uint) -1;
+#ifndef HAVE_PREAD
+#ifdef __WIN__
+    {
+      OVERLAPPED Overlapped;
+      ULARGE_INTEGER Offset;
+      Offset.QuadPart= offset;
+      ZeroMemory(&Overlapped, sizeof(Overlapped));
+      Overlapped.Offset= Offset.LowPart;
+      Overlapped.OffsetHigh= Offset.HighPart;
+      error= (!WriteFile((HANDLE)my_getoshandle(Filedes),
+                         Buffer, Count, &writtenbytes, &Overlapped));
+      if (!error)
+        break;
+      my_dosmaperr();
+    }
+#else
+    writtenbytes= (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);
+	          (writtenbytes= (uint) write(Filedes, Buffer, Count)) == Count);
     pthread_mutex_unlock(&my_file_info[Filedes].mutex);
     if (error)
       break;
+#endif
 #else
-    if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count)
+    if ((writtenbytes= (uint) pwrite(Filedes, Buffer, Count,offset)) == Count)
       break;
 #endif
-    if ((int) writenbytes != -1)
+    if ((int) writtenbytes != -1)
     {					/* Safegueard */
-      written+=writenbytes;
-      Buffer+=writenbytes;
-      Count-=writenbytes;
-      offset+=writenbytes;
+      written+= writtenbytes;
+      Buffer+= writtenbytes;
+      Count-= writtenbytes;
+      offset+= writtenbytes;
     }
     my_errno=errno;
-    DBUG_PRINT("error",("Write only %d bytes",writenbytes));
+    DBUG_PRINT("error", ("Write only %d bytes", writtenbytes));
 #ifndef NO_BACKGROUND
 #ifdef THREAD
     if (my_thread_var->abort)
@@ -124,8 +154,8 @@
       VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
       continue;
     }
-    if ((writenbytes == 0 && my_errno == EINTR) ||
-	(writenbytes > 0 && (uint) writenbytes != (uint) -1))
+    if ((writtenbytes == 0 && my_errno == EINTR) ||
+      	(writtenbytes > 0 && (uint) writtenbytes != (uint) -1))
       continue;					/* Retry */
 #endif
     if (MyFlags & (MY_NABP | MY_FNABP))
@@ -142,5 +172,5 @@
   }
   if (MyFlags & (MY_NABP | MY_FNABP))
     DBUG_RETURN(0);			/* Want only errors */
-  DBUG_RETURN(writenbytes+written); /* purecov: inspected */
+  DBUG_RETURN(writtenbytes + written); /* purecov: inspected */
 } /* my_pwrite */

--- 1.4/mysys/my_quick.c	2001-12-06 15:10:43 +03:00
+++ 1.5/mysys/my_quick.c	2006-04-03 20:10:36 +04:00
@@ -24,7 +24,16 @@
 {
   uint readbytes;
 
-  if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count)
+#ifdef __WIN__
+  ReadFile((HANDLE)my_getoshandle(Filedes),
+           Buffer, (DWORD)Count, &readbytes, NULL);
+  my_dosmaperr();
+#else
+  /* Temp hack to get count to int32 while read wants int */
+  readbytes= (uint32) read(Filedes, Buffer, (uint) Count);
+#endif
+
+  if (readbytes != Count)
   {
     my_errno=errno;
     return readbytes;
@@ -35,7 +44,22 @@
 
 uint my_quick_write(File Filedes,const byte *Buffer,uint Count)
 {
-  if ((uint) write(Filedes,Buffer,Count) != Count)
+  uint writtenbytes;
+
+#ifdef __WIN__
+  /* Emulate O_APPEND */
+  if (my_file_info[Filedes].append_flag)
+    SetFilePointer((HANDLE)my_getoshandle(Filedes), 0, 0, FILE_END);
+
+  WriteFile((HANDLE)my_getoshandle(Filedes),
+            Buffer, Count, &writtenbytes, NULL);
+  my_dosmaperr();
+#else
+  /* Temp hack to get count to int32 while write wants int */
+  writtenbytes= (uint32) write(Filedes, Buffer, (uint) Count);
+#endif
+
+  if (writtenbytes != Count)
   {
     my_errno=errno;
     return (uint) -1;

--- 1.7/mysys/my_read.c	2004-08-23 14:46:49 +04:00
+++ 1.8/mysys/my_read.c	2006-04-03 20:10:37 +04:00
@@ -45,7 +45,14 @@
   for (;;)
   {
     errno=0;					/* Linux doesn't reset this */
-    if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count)
+#ifdef __WIN__
+    ReadFile((HANDLE)my_getoshandle(Filedes),
+             Buffer, Count, &readbytes, 0);
+    my_dosmaperr();
+#else
+    readbytes= (uint)read(Filedes, Buffer, Count);
+#endif
+    if (readbytes != Count)
     {
       my_errno=errno ? errno : -1;
       DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",

--- 1.11/mysys/my_seek.c	2004-06-10 23:58:36 +04:00
+++ 1.12/mysys/my_seek.c	2006-04-03 20:10:37 +04:00
@@ -29,7 +29,37 @@
 		   whence, MyFlags));
   DBUG_ASSERT(pos != MY_FILEPOS_ERROR);		/* safety check */
 
+#ifdef __WIN__
+  {
+    DWORD MoveMethod;
+    ULARGE_INTEGER Offset;
+
+    switch (whence) {
+    case SEEK_SET:
+      MoveMethod= FILE_BEGIN;
+      break;
+    case SEEK_CUR:
+      MoveMethod= FILE_CURRENT;
+      break;
+    case SEEK_END:
+      MoveMethod= FILE_END;
+    }
+
+     Offset.QuadPart= pos;
+     Offset.LowPart= SetFilePointer((HANDLE)my_getoshandle(fd),
+                                    Offset.LowPart, &Offset.HighPart,
+                                    MoveMethod);
+     if (Offset.LowPart == 0xFFFFFFFF && GetLastError() != NO_ERROR)
+        Offset.QuadPart= -1;
+
+    newpos= Offset.QuadPart;
+
+    my_dosmaperr();
+  }
+#else
   newpos=lseek(fd, pos, whence);
+#endif
+
   if (newpos == (os_off_t) -1)
   {
     my_errno=errno;
@@ -52,7 +82,16 @@
   os_off_t pos;
   DBUG_ENTER("my_tell");
   DBUG_PRINT("my",("Fd: %d  MyFlags: %d",fd, MyFlags));
-#ifdef HAVE_TELL
+#ifdef __WIN__
+  {
+    ULARGE_INTEGER Offset;
+    Offset.QuadPart= 0;
+    Offset.LowPart= SetFilePointer((HANDLE)my_getoshandle(fd),
+                                   0, &Offset.HighPart, FILE_CURRENT);
+    pos= Offset.QuadPart;
+    my_dosmaperr();
+  }
+#elif defined(HAVE_TELL)
   pos=tell(fd);
 #else
   pos=lseek(fd, 0L, MY_SEEK_CUR);

--- 1.11/mysys/my_write.c	2005-01-06 23:31:45 +03:00
+++ 1.12/mysys/my_write.c	2006-04-03 20:10:39 +04:00
@@ -23,8 +23,9 @@
 
 uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags)
 {
-  uint writenbytes,errors;
+  uint writtenbytes,errors;
   ulong written;
+
   DBUG_ENTER("my_write");
   DBUG_PRINT("my",("Fd: %d  Buffer: 0x%lx  Count: %d  MyFlags: %d",
 		   Filedes, Buffer, Count, MyFlags));
@@ -32,17 +33,29 @@
 
   for (;;)
   {
-    if ((writenbytes = (uint) write(Filedes, Buffer, Count)) == Count)
+    errno= 0;					/* Linux doesn't reset this */
+#ifdef __WIN__
+    /* Emulate O_APPEND */
+    if (my_file_info[Filedes].append_flag)
+      SetFilePointer((HANDLE)my_getoshandle(Filedes), 0, 0, FILE_END);
+
+    WriteFile((HANDLE)my_getoshandle(Filedes), Buffer, Count,
+              &writtenbytes, NULL);
+    my_dosmaperr();
+#else
+    writtenbytes= (uint) write(Filedes, Buffer, Count);
+#endif
+    if (writtenbytes == Count)
       break;
-    if ((int) writenbytes != -1)
+    if ((int) writtenbytes != -1)
     {						/* Safeguard */
-      written+=writenbytes;
-      Buffer+=writenbytes;
-      Count-=writenbytes;
+      written+= writtenbytes;
+      Buffer+= writtenbytes;
+      Count-= writtenbytes;
     }
     my_errno=errno;
     DBUG_PRINT("error",("Write only %d bytes, error: %d",
-			writenbytes,my_errno));
+			writtenbytes,my_errno));
 #ifndef NO_BACKGROUND
 #ifdef THREAD
     if (my_thread_var->abort)
@@ -57,7 +70,7 @@
       VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
       continue;
     }
-    if (!writenbytes)
+    if (!writtenbytes)
     {
       /* We may come here on an interrupt or if the file quote is exeeded */
       if (my_errno == EINTR)
@@ -68,7 +81,7 @@
 	continue;
       }
     }
-    else if ((uint) writenbytes != (uint) -1)
+    else if ((uint) writtenbytes != (uint) -1)
       continue;					/* Retry */
 #endif
     if (MyFlags & (MY_NABP | MY_FNABP))
@@ -85,5 +98,5 @@
   }
   if (MyFlags & (MY_NABP | MY_FNABP))
     DBUG_RETURN(0);			/* Want only errors */
-  DBUG_RETURN(writenbytes+written);
+  DBUG_RETURN(writtenbytes + written);
 } /* my_write */

--- 1.16/VC++Files/mysql.sln	2006-03-03 14:03:23 +03:00
+++ 1.17/VC++Files/mysql.sln	2006-04-03 20:10:21 +04:00
@@ -307,6 +307,13 @@
 	ProjectSection(ProjectDependencies) = postProject
 	EndProjectSection
 EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gen_lex_hash",
"sql\gen_lex_hash.vcproj", "{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}"
+	ProjectSection(ProjectDependencies) = postProject
+		{EEC1300B-85A5-497C-B3E1-F708021DF859} = {EEC1300B-85A5-497C-B3E1-F708021DF859}
+		{44D9C7DC-6636-4B82-BD01-6876C64017DF} = {44D9C7DC-6636-4B82-BD01-6876C64017DF}
+		{FC369DF4-AEB7-4531-BF34-A638C4363BFE} = {FC369DF4-AEB7-4531-BF34-A638C4363BFE}
+	EndProjectSection
+EndProject
 Global
 	GlobalSection(SolutionConfiguration) = preSolution
 		classic = classic
@@ -1802,6 +1809,42 @@
 		{BFCDA391-91A5-45F5-A14F-1011F8424113}.TLS.Build.0 = Release|Win32
 		{BFCDA391-91A5-45F5-A14F-1011F8424113}.TLS_DEBUG.ActiveCfg = Release|Win32
 		{BFCDA391-91A5-45F5-A14F-1011F8424113}.TLS_DEBUG.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.classic.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.classic.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.classic nt.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.classic nt.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Debug.ActiveCfg = Debug|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Debug.Build.0 = Debug|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Classic.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Classic.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Debug.ActiveCfg = Debug|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Debug.Build.0 = Debug|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Pro.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Pro.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_ProGPL.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_ProGPL.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Release.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Embedded_Release.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Max.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Max.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Max nt.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Max nt.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.nt.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.nt.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro gpl.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro gpl.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro gpl nt.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro gpl nt.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro nt.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.pro nt.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Release.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.Release.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.TLS.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.TLS.Build.0 = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.TLS_DEBUG.ActiveCfg = Release|Win32
+		{D593B5D1-8EFC-44FE-9937-A5AAD1E619A1}.TLS_DEBUG.Build.0 = Release|Win32
 	EndGlobalSection
 	GlobalSection(ExtensibilityGlobals) = postSolution
 	EndGlobalSection

--- 1.24/mysys/mf_tempfile.c	2005-04-01 20:46:34 +04:00
+++ 1.25/mysys/mf_tempfile.c	2006-04-03 20:10:24 +04:00
@@ -103,7 +103,7 @@
     strmov(convert_dirname(to,dir,NullS),prefix_buff);
     org_file=mkstemp(to);
     file=my_register_filename(org_file, to, FILE_BY_MKSTEMP,
-			      EE_CANTCREATEFILE, MyFlags);
+			                        EE_CANTCREATEFILE, MyFlags, 0, 0);
     /* If we didn't manage to register the name, remove the temp file */
     if (org_file >= 0 && file < 0)
     {

--- 1.261/sql/ha_innodb.cc	2006-03-08 17:21:03 +03:00
+++ 1.262/sql/ha_innodb.cc	2006-04-03 20:10:40 +04:00
@@ -738,13 +738,13 @@
 {
 	char	filename[FN_REFLEN];
 	int	fd2 = -1;
-	File	fd = create_temp_file(filename, mysql_tmpdir, "ib",
+	int	flags = O_CREAT | O_EXCL | O_RDWR;
 #ifdef __WIN__
-				O_BINARY | O_TRUNC | O_SEQUENTIAL |
-				O_TEMPORARY | O_SHORT_LIVED |
+  flags |= O_BINARY | O_TRUNC | O_SEQUENTIAL |
+           O_TEMPORARY | O_SHORT_LIVED;
 #endif /* __WIN__ */
-				O_CREAT | O_EXCL | O_RDWR,
-				MYF(MY_WME));
+	File	fd = create_temp_file(filename, NullS, "ib",
+                              flags, MYF(MY_WME));
 	if (fd >= 0) {
 #ifndef __WIN__
 		/* On Windows, open files cannot be removed, but files can be
@@ -760,7 +760,19 @@
 		will be passed to fdopen(), it will be closed by invoking
 		fclose(), which in turn will invoke close() instead of
 		my_close(). */
+#ifdef __WIN__
+    /* Get a POSIX file handle, rather than a Windows HANDLE */
+    {
+      HANDLE NewHandle;
+      DuplicateHandle(GetCurrentProcess(),
+                      (HANDLE)my_file_info[fd].os_handle,
+                      GetCurrentProcess(),
+                      &NewHandle, 0, FALSE, DUPLICATE_SAME_ACCESS);
+      fd2 = _open_osfhandle((long)NewHandle,flags);
+    }
+#else
 		fd2 = dup(fd);
+#endif
 		if (fd2 < 0) {
 			DBUG_PRINT("error",("Got error %d on dup",fd2));
 			my_errno=errno;

--- 1.4/mysys/my_dup.c	2004-02-19 20:33:03 +03:00
+++ 1.5/mysys/my_dup.c	2006-04-03 20:10:26 +04:00
@@ -28,12 +28,25 @@
 File my_dup(File file, myf MyFlags)
 {
   File fd;
+  int os_handle= 0, append_flag= 0;
   const char *filename;
   DBUG_ENTER("my_dup");
   DBUG_PRINT("my",("file: %d  MyFlags: %d", MyFlags));
+#ifdef __WIN__
+  /* Duplicate the Win32 file handle */
+  DuplicateHandle(GetCurrentProcess(), (HANDLE)my_getoshandle(file),
+                  GetCurrentProcess(),(HANDLE*)&os_handle,
+                  DUPLICATE_SAME_ACCESS, FALSE, 0);
+  /* Emulate C runtime file handle */
+  fd= my_nextfd();
+  /* Emulate O_APPEND */
+  append_flag= my_file_info[file].append_flag;
+#else
   fd = dup(file);
+#endif
   filename= (((uint) file < my_file_limit) ?
 	     my_file_info[(int) file].name : "Unknown");
   DBUG_RETURN(my_register_filename(fd, filename, FILE_BY_DUP,
-				   EE_FILENOTFOUND, MyFlags));
+				      EE_FILENOTFOUND, MyFlags,
+              os_handle, append_flag));
 } /* my_open */

--- 1.7/mysys/my_gethostbyname.c	2004-06-10 23:58:36 +04:00
+++ 1.8/mysys/my_gethostbyname.c	2006-04-03 20:10:29 +04:00
@@ -96,7 +96,14 @@
 				   int buflen, int *h_errnop)
 {
   struct hostent *hp;
+
+/*
+  gethostbyname() is thread safe under Windows
+*/
+#ifndef __WIN__
   pthread_mutex_lock(&LOCK_gethostbyname_r);
+#endif
+
   hp= gethostbyname(name);
   *h_errnop= h_errno;
   return hp;
@@ -104,7 +111,9 @@
 
 void my_gethostbyname_r_free()
 {
+#ifndef __WIN__
   pthread_mutex_unlock(&LOCK_gethostbyname_r);  
+#endif
 }
 
 #endif /* !HAVE_GETHOSTBYNAME_R */

--- 1.4/mysys/my_sync.c	2005-04-06 20:43:27 +04:00
+++ 1.5/mysys/my_sync.c	2006-04-03 20:10:38 +04:00
@@ -54,7 +54,8 @@
 #elif defined(HAVE_FSYNC)
     res= fsync(fd);
 #elif defined(__WIN__)
-    res= _commit(fd);
+    res= !FlushFileBuffers((HANDLE)my_getoshandle(fd));
+    my_dosmaperr();
 #else
     res= 0;					/* No sync (strange OS) */
 #endif
Thread
bk commit into 5.2 tree (SergeyV:1.2154)sergeyv3 Apr