Commit 4d76c28c authored by petr@mysql.com's avatar petr@mysql.com

Fix Bug#20692 rpl_* tests failure on hpux

parent 45598df7
...@@ -27,7 +27,7 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, ...@@ -27,7 +27,7 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
myf MyFlags) myf MyFlags)
{ {
uint readbytes; uint readbytes;
int error; int error= 0;
DBUG_ENTER("my_pread"); DBUG_ENTER("my_pread");
DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: 0x%lx Count: %u MyFlags: %d", DBUG_PRINT("my",("Fd: %d Seek: %lu Buffer: 0x%lx Count: %u MyFlags: %d",
Filedes, (ulong) offset, Buffer, Count, MyFlags)); Filedes, (ulong) offset, Buffer, Count, MyFlags));
...@@ -38,17 +38,39 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset, ...@@ -38,17 +38,39 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
errno=0; /* Linux doesn't reset this */ errno=0; /* Linux doesn't reset this */
#endif #endif
#ifndef HAVE_PREAD #ifndef HAVE_PREAD
off_t old_offset;
pthread_mutex_lock(&my_file_info[Filedes].mutex); pthread_mutex_lock(&my_file_info[Filedes].mutex);
readbytes= (uint) -1; /*
error= (lseek(Filedes, offset, MY_SEEK_SET) == -1L || As we cannot change the file pointer, we save the old position,
(readbytes = (uint) read(Filedes, Buffer, Count)) != Count); 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); pthread_mutex_unlock(&my_file_info[Filedes].mutex);
#else #else
error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count); error=((readbytes = (uint) pread(Filedes, Buffer, Count, offset)) != Count);
my_errno= errno;
#endif #endif
if (error) if (error || readbytes != Count)
{ {
my_errno=errno;
DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d", DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
readbytes,Count,Filedes,my_errno)); readbytes,Count,Filedes,my_errno));
#ifdef THREAD #ifdef THREAD
...@@ -89,17 +111,40 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, ...@@ -89,17 +111,40 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
for (;;) for (;;)
{ {
#ifndef HAVE_PREAD #ifndef HAVE_PREAD
int error; int error= 0;
off_t old_offset;
writenbytes= (uint) -1; writenbytes= (uint) -1;
pthread_mutex_lock(&my_file_info[Filedes].mutex); 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); pthread_mutex_unlock(&my_file_info[Filedes].mutex);
if (error)
if (!error && writenbytes == Count)
break; break;
#else #else
if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count) if ((writenbytes = (uint) pwrite(Filedes, Buffer, Count,offset)) == Count)
break; break;
my_errno= errno;
#endif #endif
if ((int) writenbytes != -1) if ((int) writenbytes != -1)
{ /* Safegueard */ { /* Safegueard */
...@@ -108,7 +153,6 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset, ...@@ -108,7 +153,6 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
Count-=writenbytes; Count-=writenbytes;
offset+=writenbytes; offset+=writenbytes;
} }
my_errno=errno;
DBUG_PRINT("error",("Write only %d bytes",writenbytes)); DBUG_PRINT("error",("Write only %d bytes",writenbytes));
#ifndef NO_BACKGROUND #ifndef NO_BACKGROUND
#ifdef THREAD #ifdef THREAD
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment