summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
Diffstat (limited to 'mysys')
-rw-r--r--mysys/CMakeLists.txt2
-rw-r--r--mysys/Makefile.am2
-rw-r--r--mysys/charset.c15
-rwxr-xr-xmysys/make-ccc2
-rw-r--r--mysys/mf_iocache.c108
-rw-r--r--mysys/my_chsize.c6
-rw-r--r--mysys/my_lock.c39
-rw-r--r--mysys/my_lread.c53
-rw-r--r--mysys/my_lwrite.c46
-rw-r--r--mysys/my_pread.c12
-rw-r--r--mysys/my_quick.c26
-rw-r--r--mysys/my_read.c9
-rw-r--r--mysys/my_seek.c35
-rw-r--r--mysys/my_write.c20
14 files changed, 228 insertions, 147 deletions
diff --git a/mysys/CMakeLists.txt b/mysys/CMakeLists.txt
index 4aa99a70121..7b362b4c1f9 100644
--- a/mysys/CMakeLists.txt
+++ b/mysys/CMakeLists.txt
@@ -20,7 +20,7 @@ ADD_LIBRARY(mysys array.c charset-def.c charset.c checksum.c default.c default_m
my_clock.c my_compress.c my_conio.c my_copy.c my_crc32.c my_create.c my_delete.c
my_div.c my_error.c my_file.c my_fopen.c my_fstream.c my_gethostbyname.c
my_gethwaddr.c my_getopt.c my_getsystime.c my_getwd.c my_handler.c my_init.c
- my_lib.c my_lock.c my_lockmem.c my_lread.c my_lwrite.c my_malloc.c my_messnc.c
+ my_lib.c my_lock.c my_lockmem.c my_malloc.c my_messnc.c
my_mkdir.c my_mmap.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c
my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_sleep.c
my_static.c my_symlink.c my_symlink2.c my_sync.c my_thr_init.c my_wincond.c
diff --git a/mysys/Makefile.am b/mysys/Makefile.am
index b209d64e78f..79d79d41c34 100644
--- a/mysys/Makefile.am
+++ b/mysys/Makefile.am
@@ -43,7 +43,7 @@ libmysys_a_SOURCES = my_init.c my_getwd.c mf_getdate.c my_mmap.c \
tree.c trie.c list.c hash.c array.c string.c typelib.c \
my_copy.c my_append.c my_lib.c \
my_delete.c my_rename.c my_redel.c \
- my_chsize.c my_lread.c my_lwrite.c my_clock.c \
+ my_chsize.c my_clock.c \
my_quick.c my_lockmem.c my_static.c \
my_sync.c my_getopt.c my_mkdir.c \
default_modify.c default.c \
diff --git a/mysys/charset.c b/mysys/charset.c
index 64b15fab0c2..d10a580ae4e 100644
--- a/mysys/charset.c
+++ b/mysys/charset.c
@@ -312,7 +312,7 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
{
char *buf;
int fd;
- uint len;
+ uint len, tmp_len;
MY_STAT stat_info;
if (!my_stat(filename, &stat_info, MYF(myflags)) ||
@@ -321,12 +321,11 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
return TRUE;
if ((fd=my_open(filename,O_RDONLY,myflags)) < 0)
- {
- my_free(buf,myflags);
- return TRUE;
- }
- len=read(fd,buf,len);
+ goto error;
+ tmp_len=my_read(fd, buf, len, myflags);
my_close(fd,myflags);
+ if (tmp_len != len)
+ goto error;
if (my_parse_charset_xml(buf,len,add_collation))
{
@@ -340,6 +339,10 @@ static my_bool my_read_charset_file(const char *filename, myf myflags)
my_free(buf, myflags);
return FALSE;
+
+error:
+ my_free(buf, myflags);
+ return TRUE;
}
diff --git a/mysys/make-ccc b/mysys/make-ccc
index 9c54185682a..b34bd80e1d1 100755
--- a/mysys/make-ccc
+++ b/mysys/make-ccc
@@ -1,4 +1,4 @@
rm -f .deps/* raid.o mf_iocache.o libmysys.a
-ccc -DDEFAULT_BASEDIR="\"/usr/local/mysql\"" -DDATADIR="\"/usr/local/mysql/var\"" -DHAVE_CONFIG_H -I./../include -I../include -I.. -DDBUG_OFF -fast -O3 -fomit-frame-pointer -c array.c checksum.c default.c errors.c getopt.c getopt1.c getvar.c hash.c list.c mf_brkhant.c mf_cache.c mf_casecnv.c mf_dirname.c mf_fn_ext.c mf_format.c mf_getdate.c mf_keycache.c mf_loadpath.c mf_pack.c mf_pack2.c mf_path.c mf_qsort.c mf_qsort2.c mf_radix.c mf_reccache.c mf_same.c mf_sort.c mf_soundex.c mf_stripp.c mf_unixpath.c mf_wcomp.c mf_wfile.c mulalloc.c my_alarm.c my_alloc.c my_append.c my_chsize.c my_clock.c my_compress.c my_copy.c my_create.c my_delete.c my_div.c my_error.c my_fopen.c my_fstream.c my_getwd.c my_init.c my_lib.c my_lockmem.c my_lread.c my_lwrite.c my_malloc.c my_messnc.c my_mkdir.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_static.c my_tempnam.c my_thr_init.c my_write.c ptr_cmp.c queues.c safemalloc.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c
+ccc -DDEFAULT_BASEDIR="\"/usr/local/mysql\"" -DDATADIR="\"/usr/local/mysql/var\"" -DHAVE_CONFIG_H -I./../include -I../include -I.. -DDBUG_OFF -fast -O3 -fomit-frame-pointer -c array.c checksum.c default.c errors.c getopt.c getopt1.c getvar.c hash.c list.c mf_brkhant.c mf_cache.c mf_casecnv.c mf_dirname.c mf_fn_ext.c mf_format.c mf_getdate.c mf_keycache.c mf_loadpath.c mf_pack.c mf_pack2.c mf_path.c mf_qsort.c mf_qsort2.c mf_radix.c mf_reccache.c mf_same.c mf_sort.c mf_soundex.c mf_stripp.c mf_unixpath.c mf_wcomp.c mf_wfile.c mulalloc.c my_alarm.c my_alloc.c my_append.c my_chsize.c my_clock.c my_compress.c my_copy.c my_create.c my_delete.c my_div.c my_error.c my_fopen.c my_fstream.c my_getwd.c my_init.c my_lib.c my_lockmem.c my_malloc.c my_messnc.c my_mkdir.c my_net.c my_once.c my_open.c my_pread.c my_pthread.c my_quick.c my_read.c my_realloc.c my_redel.c my_rename.c my_seek.c my_static.c my_tempnam.c my_thr_init.c my_write.c ptr_cmp.c queues.c safemalloc.c string.c thr_alarm.c thr_lock.c thr_mutex.c thr_rwlock.c tree.c typelib.c
make raid.o mf_iocache.o my_lock.o
ar -cr libmysys.a array.o raid.o mf_iocache.o my_lock.o
diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c
index b1cf940d70d..249eaf48ad2 100644
--- a/mysys/mf_iocache.c
+++ b/mysys/mf_iocache.c
@@ -332,7 +332,11 @@ my_bool reinit_io_cache(IO_CACHE *info, enum cache_type type,
{
info->read_end=info->write_pos;
info->end_of_file=my_b_tell(info);
- info->seek_not_done=1;
+ /*
+ Trigger a new seek only if we have a valid
+ file handle.
+ */
+ info->seek_not_done= (info->file != -1);
}
else if (type == WRITE_CACHE)
{
@@ -441,11 +445,24 @@ int _my_b_read(register IO_CACHE *info, byte *Buffer, uint Count)
/* pos_in_file always point on where info->buffer was read */
pos_in_file=info->pos_in_file+(uint) (info->read_end - info->buffer);
+
+ /*
+ Whenever a function which operates on IO_CACHE flushes/writes
+ some part of the IO_CACHE to disk it will set the property
+ "seek_not_done" to indicate this to other functions operating
+ on the IO_CACHE.
+ */
if (info->seek_not_done)
- { /* File touched, do seek */
- VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
+ {
+ if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))
+ == MY_FILEPOS_ERROR)
+ {
+ info->error= -1;
+ DBUG_RETURN(1);
+ }
info->seek_not_done=0;
}
+
diff_length=(uint) (pos_in_file & (IO_SIZE-1));
if (Count >= (uint) (IO_SIZE+(IO_SIZE-diff_length)))
{ /* Fill first intern buffer */
@@ -946,8 +963,22 @@ int _my_b_read_r(register IO_CACHE *cache, byte *Buffer, uint Count)
len= 0;
else
{
- if (cache->seek_not_done) /* File touched, do seek */
- VOID(my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0)));
+ /*
+ Whenever a function which operates on IO_CACHE flushes/writes
+ some part of the IO_CACHE to disk it will set the property
+ "seek_not_done" to indicate this to other functions operating
+ on the IO_CACHE.
+ */
+ if (cache->seek_not_done)
+ {
+ if (my_seek(cache->file, pos_in_file, MY_SEEK_SET, MYF(0))
+ == MY_FILEPOS_ERROR)
+ {
+ cache->error= -1;
+ unlock_io_cache(cache);
+ DBUG_RETURN(1);
+ }
+ }
len= (int) my_read(cache->file, cache->buffer, length, cache->myflags);
}
DBUG_PRINT("io_cache_share", ("read %d bytes", len));
@@ -1049,11 +1080,16 @@ static void copy_to_read_buffer(IO_CACHE *write_cache,
/*
- Do sequential read from the SEQ_READ_APPEND cache
- we do this in three stages:
+ Do sequential read from the SEQ_READ_APPEND cache.
+
+ We do this in three stages:
- first read from info->buffer
- then if there are still data to read, try the file descriptor
- afterwards, if there are still data to read, try append buffer
+
+ RETURNS
+ 0 Success
+ 1 Failed to read
*/
int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count)
@@ -1081,7 +1117,13 @@ int _my_b_seq_read(register IO_CACHE *info, byte *Buffer, uint Count)
With read-append cache we must always do a seek before we read,
because the write could have moved the file pointer astray
*/
- VOID(my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0)));
+ if (my_seek(info->file,pos_in_file,MY_SEEK_SET,MYF(0))
+ == MY_FILEPOS_ERROR)
+ {
+ info->error= -1;
+ unlock_append_buffer(info);
+ return (1);
+ }
info->seek_not_done=0;
diff_length=(uint) (pos_in_file & (IO_SIZE-1));
@@ -1197,6 +1239,21 @@ read_append_buffer:
#ifdef HAVE_AIOWAIT
+/*
+ Read from the IO_CACHE into a buffer and feed asynchronously
+ from disk when needed.
+
+ SYNOPSIS
+ _my_b_async_read()
+ info IO_CACHE pointer
+ Buffer Buffer to retrieve count bytes from file
+ Count Number of bytes to read into Buffer
+
+ RETURN VALUE
+ -1 An error has occurred; my_errno is set.
+ 0 Success
+ 1 An error has occurred; IO_CACHE to error state.
+*/
int _my_b_async_read(register IO_CACHE *info, byte *Buffer, uint Count)
{
uint length,read_length,diff_length,left_length,use_length,org_Count;
@@ -1287,13 +1344,20 @@ int _my_b_async_read(register IO_CACHE *info, byte *Buffer, uint Count)
info->error=(int) (read_length+left_length);
return 1;
}
- VOID(my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0)));
+
+ if (my_seek(info->file,next_pos_in_file,MY_SEEK_SET,MYF(0))
+ == MY_FILEPOS_ERROR)
+ {
+ info->error= -1;
+ return (1);
+ }
+
read_length=IO_SIZE*2- (uint) (next_pos_in_file & (IO_SIZE-1));
if (Count < read_length)
{ /* Small block, read to cache */
if ((read_length=my_read(info->file,info->request_pos,
read_length, info->myflags)) == (uint) -1)
- return info->error= -1;
+ return info->error= -1;
use_length=min(Count,read_length);
memcpy(Buffer,info->request_pos,(size_t) use_length);
info->read_pos=info->request_pos+Count;
@@ -1380,7 +1444,15 @@ int _my_b_get(IO_CACHE *info)
return (int) (uchar) buff;
}
- /* Returns != 0 if error on write */
+/*
+ Write a byte buffer to IO_CACHE and flush to disk
+ if IO_CACHE is full.
+
+ RETURN VALUE
+ 1 On error on write
+ 0 On success
+ -1 On error; my_errno contains error code.
+*/
int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count)
{
@@ -1404,8 +1476,18 @@ int _my_b_write(register IO_CACHE *info, const byte *Buffer, uint Count)
{ /* Fill first intern buffer */
length=Count & (uint) ~(IO_SIZE-1);
if (info->seek_not_done)
- { /* File touched, do seek */
- VOID(my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0)));
+ {
+ /*
+ Whenever a function which operates on IO_CACHE flushes/writes
+ some part of the IO_CACHE to disk it will set the property
+ "seek_not_done" to indicate this to other functions operating
+ on the IO_CACHE.
+ */
+ if (my_seek(info->file,info->pos_in_file,MY_SEEK_SET,MYF(0)))
+ {
+ info->error= -1;
+ return (1);
+ }
info->seek_not_done=0;
}
if (my_write(info->file,Buffer,(uint) length,info->myflags | MY_NABP))
diff --git a/mysys/my_chsize.c b/mysys/my_chsize.c
index fe0d0ffa607..4b26085c870 100644
--- a/mysys/my_chsize.c
+++ b/mysys/my_chsize.c
@@ -86,7 +86,11 @@ int my_chsize(File fd, my_off_t newlength, int filler, myf MyFlags)
Fill space between requested length and true length with 'filler'
We should never come here on any modern machine
*/
- VOID(my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE)));
+ if (my_seek(fd, newlength, MY_SEEK_SET, MYF(MY_WME+MY_FAE))
+ == MY_FILEPOS_ERROR)
+ {
+ goto err;
+ }
swap_variables(my_off_t, newlength, oldsize);
#endif
}
diff --git a/mysys/my_lock.c b/mysys/my_lock.c
index 919727e03d6..e32807004e8 100644
--- a/mysys/my_lock.c
+++ b/mysys/my_lock.c
@@ -30,7 +30,14 @@
#include <nks/fsio.h>
#endif
- /* Lock a part of a file */
+/*
+ Lock a part of a file
+
+ RETURN VALUE
+ 0 Success
+ -1 An error has occured and 'my_errno' is set
+ to indicate the actual error code.
+*/
int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
myf MyFlags)
@@ -94,10 +101,22 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
#elif defined(HAVE_LOCKING)
/* Windows */
{
- my_bool error;
+ my_bool error= FALSE;
pthread_mutex_lock(&my_file_info[fd].mutex);
- if (MyFlags & MY_SEEK_NOT_DONE)
- VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)));
+ if (MyFlags & MY_SEEK_NOT_DONE)
+ {
+ if( my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
+ == MY_FILEPOS_ERROR )
+ {
+ /*
+ If my_seek fails my_errno will already contain an error code;
+ just unlock and return error code.
+ */
+ DBUG_PRINT("error",("my_errno: %d (%d)",my_errno,errno));
+ pthread_mutex_unlock(&my_file_info[fd].mutex);
+ DBUG_RETURN(-1);
+ }
+ }
error= locking(fd,locktype,(ulong) length) && errno != EINVAL;
pthread_mutex_unlock(&my_file_info[fd].mutex);
if (!error)
@@ -135,7 +154,17 @@ int my_lock(File fd, int locktype, my_off_t start, my_off_t length,
}
#else
if (MyFlags & MY_SEEK_NOT_DONE)
- VOID(my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE)));
+ {
+ if (my_seek(fd,start,MY_SEEK_SET,MYF(MyFlags & ~MY_SEEK_NOT_DONE))
+ == MY_FILEPOS_ERROR)
+ {
+ /*
+ If an error has occured in my_seek then we will already
+ have an error code in my_errno; Just return error code.
+ */
+ DBUG_RETURN(-1);
+ }
+ }
if (lockf(fd,locktype,length) != -1)
DBUG_RETURN(0);
#endif /* HAVE_FCNTL */
diff --git a/mysys/my_lread.c b/mysys/my_lread.c
deleted file mode 100644
index 601d772b844..00000000000
--- a/mysys/my_lread.c
+++ /dev/null
@@ -1,53 +0,0 @@
-/* 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 "mysys_priv.h"
-#include "mysys_err.h"
-
- /* Read a chunk of bytes from a file */
-
-uint32 my_lread(int Filedes, byte *Buffer, uint32 Count, myf MyFlags)
- /* File descriptor */
- /* Buffer must be at least count bytes */
- /* Max number of bytes returnd */
- /* Flags on what to do on error */
-{
- uint32 readbytes;
- DBUG_ENTER("my_lread");
- DBUG_PRINT("my",("Fd: %d Buffer: %ld Count: %ld MyFlags: %d",
- Filedes, Buffer, Count, MyFlags));
-
- /* Temp hack to get count to int32 while read wants int */
- if ((readbytes = (uint32) read(Filedes, Buffer, (uint) Count)) != Count)
- {
- my_errno=errno;
- if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
- {
- if (readbytes == MY_FILE_ERROR)
- my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
- my_filename(Filedes),errno);
- else
- if (MyFlags & (MY_NABP | MY_FNABP))
- my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
- my_filename(Filedes),errno);
- }
- if (readbytes == MY_FILE_ERROR || MyFlags & (MY_NABP | MY_FNABP))
- DBUG_RETURN((uint32) -1); /* Return med felkod */
- }
- if (MyFlags & (MY_NABP | MY_FNABP))
- DBUG_RETURN(0); /* Ok vid l{sning */
- DBUG_RETURN(readbytes);
-} /* my_lread */
diff --git a/mysys/my_lwrite.c b/mysys/my_lwrite.c
deleted file mode 100644
index 3b9afdbd71f..00000000000
--- a/mysys/my_lwrite.c
+++ /dev/null
@@ -1,46 +0,0 @@
-/* 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 "mysys_priv.h"
-#include "mysys_err.h"
-
- /* Write a chunk of bytes to a file */
-
-uint32 my_lwrite(int Filedes, const byte *Buffer, uint32 Count, myf MyFlags)
-{
- uint32 writenbytes;
- DBUG_ENTER("my_lwrite");
- DBUG_PRINT("my",("Fd: %d Buffer: 0x%lx Count: %ld MyFlags: %d",
- Filedes, Buffer, Count, MyFlags));
-
- /* Temp hack to get count to int32 while write wants int */
- if ((writenbytes = (uint32) write(Filedes, Buffer, (uint) Count)) != Count)
- {
- my_errno=errno;
- if (writenbytes == (uint32) -1 || MyFlags & (MY_NABP | MY_FNABP))
- {
- if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
- {
- my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
- my_filename(Filedes),errno);
- }
- DBUG_RETURN((uint32) -1); /* Return med felkod */
- }
- }
- if (MyFlags & (MY_NABP | MY_FNABP))
- DBUG_RETURN(0); /* Ok vid l{sning */
- DBUG_RETURN(writenbytes);
-} /* my_lwrite */
diff --git a/mysys/my_pread.c b/mysys/my_pread.c
index 978366e57e5..45a4a363c0a 100644
--- a/mysys/my_pread.c
+++ b/mysys/my_pread.c
@@ -75,8 +75,12 @@ uint my_pread(File Filedes, byte *Buffer, uint Count, my_off_t offset,
DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
readbytes,Count,Filedes,my_errno));
#ifdef THREAD
- if (readbytes == 0 && errno == EINTR)
- continue; /* Interrupted */
+ if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
+ {
+ DBUG_PRINT("debug", ("my_pread() was interrupted and returned %d",
+ (int) readbytes));
+ continue; /* Interrupted */
+ }
#endif
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
{
@@ -170,8 +174,8 @@ uint my_pwrite(int Filedes, const byte *Buffer, uint Count, my_off_t offset,
VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
continue;
}
- if ((writenbytes == 0 && my_errno == EINTR) ||
- (writenbytes > 0 && (uint) writenbytes != (uint) -1))
+ if ((writenbytes > 0 && (uint) writenbytes != (uint) -1) ||
+ my_errno == EINTR)
continue; /* Retry */
#endif
if (MyFlags & (MY_NABP | MY_FNABP))
diff --git a/mysys/my_quick.c b/mysys/my_quick.c
index 44ed3fc0b2c..ffc8160c371 100644
--- a/mysys/my_quick.c
+++ b/mysys/my_quick.c
@@ -26,6 +26,14 @@ uint my_quick_read(File Filedes,byte *Buffer,uint Count,myf MyFlags)
if ((readbytes = (uint) read(Filedes, Buffer, Count)) != Count)
{
+#ifndef DBUG_OFF
+ if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
+ {
+ DBUG_PRINT("error", ("my_quick_read() was interrupted and returned %d"
+ ". This function does not retry the read!",
+ (int) readbytes));
+ }
+#endif
my_errno=errno;
return readbytes;
}
@@ -35,8 +43,24 @@ uint my_quick_read(File Filedes,byte *Buffer,uint Count,myf MyFlags)
uint my_quick_write(File Filedes,const byte *Buffer,uint Count)
{
- if ((uint) write(Filedes,Buffer,Count) != Count)
+#ifndef DBUG_OFF
+ uint writtenbytes;
+#endif
+
+ if ((
+#ifndef DBUG_OFF
+ writtenbytes =
+#endif
+ (uint) write(Filedes,Buffer,Count)) != Count)
{
+#ifndef DBUG_OFF
+ if ((writtenbytes == 0 || (int) writtenbytes == -1) && errno == EINTR)
+ {
+ DBUG_PRINT("error", ("my_quick_write() was interrupted and returned %d"
+ ". This function does not retry the write!",
+ (int) writtenbytes));
+ }
+#endif
my_errno=errno;
return (uint) -1;
}
diff --git a/mysys/my_read.c b/mysys/my_read.c
index 2e23f2175f8..8b88e483fef 100644
--- a/mysys/my_read.c
+++ b/mysys/my_read.c
@@ -51,10 +51,11 @@ uint my_read(File Filedes, byte *Buffer, uint Count, myf MyFlags)
DBUG_PRINT("warning",("Read only %ld bytes off %ld from %d, errno: %d",
readbytes, Count, Filedes, my_errno));
#ifdef THREAD
- if ((int) readbytes <= 0 && errno == EINTR)
- {
- DBUG_PRINT("debug", ("my_read() was interrupted and returned %d", (int) readbytes));
- continue; /* Interrupted */
+ if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
+ {
+ DBUG_PRINT("debug", ("my_read() was interrupted and returned %d",
+ (int) readbytes));
+ continue; /* Interrupted */
}
#endif
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
diff --git a/mysys/my_seek.c b/mysys/my_seek.c
index e5b1905e551..269d1a65b31 100644
--- a/mysys/my_seek.c
+++ b/mysys/my_seek.c
@@ -16,8 +16,30 @@
#include "mysys_priv.h"
- /* Seek to position in file */
- /*ARGSUSED*/
+/*
+ Seek to a position in a file.
+
+ ARGUMENTS
+ File fd The file descriptor
+ my_off_t pos The expected position (absolute or relative)
+ int whence A direction parameter and one of
+ {SEEK_SET, SEEK_CUR, SEEK_END}
+ myf MyFlags Not used.
+
+ DESCRIPTION
+ The my_seek function is a wrapper around the system call lseek and
+ repositions the offset of the file descriptor fd to the argument
+ offset according to the directive whence as follows:
+ SEEK_SET The offset is set to offset bytes.
+ SEEK_CUR The offset is set to its current location plus offset bytes
+ SEEK_END The offset is set to the size of the file plus offset bytes
+
+ RETURN VALUE
+ my_off_t newpos The new position in the file.
+ MY_FILEPOS_ERROR An error was encountered while performing
+ the seek. my_errno is set to indicate the
+ actual error.
+*/
my_off_t my_seek(File fd, my_off_t pos, int whence,
myf MyFlags __attribute__((unused)))
@@ -29,8 +51,13 @@ my_off_t my_seek(File fd, my_off_t pos, int whence,
whence, MyFlags));
DBUG_ASSERT(pos != MY_FILEPOS_ERROR); /* safety check */
- if (-1 != fd)
- newpos=lseek(fd, pos, whence);
+ /*
+ Make sure we are using a valid file descriptor!
+ */
+ DBUG_ASSERT(fd != -1);
+
+ newpos= lseek(fd, pos, whence);
+
if (newpos == (os_off_t) -1)
{
my_errno=errno;
diff --git a/mysys/my_write.c b/mysys/my_write.c
index 4e8369480b3..ae8cb4ab02b 100644
--- a/mysys/my_write.c
+++ b/mysys/my_write.c
@@ -57,18 +57,24 @@ uint my_write(int Filedes, const byte *Buffer, uint Count, myf MyFlags)
VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
continue;
}
- if (!writenbytes)
+
+ if ((writenbytes == 0 || (int) writenbytes == -1))
{
- /* We may come here on an interrupt or if the file quote is exeeded */
if (my_errno == EINTR)
- continue;
- if (!errors++) /* Retry once */
{
- errno=EFBIG; /* Assume this is the error */
- continue;
+ DBUG_PRINT("debug", ("my_write() was interrupted and returned %d",
+ (int) writenbytes));
+ continue; /* Interrupted */
+ }
+
+ if (!writenbytes && !errors++) /* Retry once */
+ {
+ /* We may come here if the file quota is exeeded */
+ errno=EFBIG; /* Assume this is the error */
+ continue;
}
}
- else if ((uint) writenbytes != (uint) -1)
+ else
continue; /* Retry */
#endif
if (MyFlags & (MY_NABP | MY_FNABP))