16 #include "mysys_priv.h"
17 #include "mysys_err.h"
21 #if defined (HAVE_PREAD) && !defined(_WIN32)
48 size_t my_pread(File Filedes, uchar *
Buffer,
size_t Count, my_off_t
offset,
53 #if !defined (HAVE_PREAD) && !defined (_WIN32)
56 DBUG_ENTER(
"my_pread");
57 DBUG_PRINT(
"my",(
"fd: %d Seek: %llu Buffer: %p Count: %lu MyFlags: %d",
58 Filedes, (ulonglong)offset, Buffer, (ulong)Count, MyFlags));
62 #if !defined (HAVE_PREAD) && !defined (_WIN32)
65 error= (lseek(Filedes, offset, MY_SEEK_SET) == (my_off_t) -1 ||
66 (readbytes= read(Filedes, Buffer, Count)) != Count);
73 readbytes= my_win_pread(Filedes, Buffer, Count, offset);
75 readbytes= pread(Filedes, Buffer, Count, offset);
77 error= (readbytes != Count);
81 my_errno= errno ? errno : -1;
82 if (errno == 0 || (readbytes != (
size_t) -1 &&
83 (MyFlags & (MY_NABP | MY_FNABP))))
84 my_errno= HA_ERR_FILE_TOO_SHORT;
86 DBUG_PRINT(
"warning",(
"Read only %d bytes off %u from %d, errno: %d",
87 (
int) readbytes, (uint) Count,Filedes,my_errno));
89 if ((readbytes == 0 || readbytes == (
size_t) -1) && errno == EINTR)
91 DBUG_PRINT(
"debug", (
"my_pread() was interrupted and returned %d",
96 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
98 char errbuf[MYSYS_STRERROR_SIZE];
99 if (readbytes == (
size_t) -1)
100 my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),
101 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
102 else if (MyFlags & (MY_NABP | MY_FNABP))
103 my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),
104 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
106 if (readbytes == (
size_t) -1 || (MyFlags & (MY_FNABP | MY_NABP)))
107 DBUG_RETURN(MY_FILE_ERROR);
109 if (MyFlags & (MY_NABP | MY_FNABP))
111 DBUG_RETURN(readbytes);
137 size_t my_pwrite(File Filedes,
const uchar *Buffer,
size_t Count,
138 my_off_t offset, myf MyFlags)
140 size_t writtenbytes, written;
143 DBUG_ENTER(
"my_pwrite");
144 DBUG_PRINT(
"my",(
"fd: %d Seek: %llu Buffer: %p Count: %lu MyFlags: %d",
145 Filedes, offset, Buffer, (ulong)Count, MyFlags));
151 #if !defined (HAVE_PREAD) && !defined (_WIN32)
153 writtenbytes= (size_t) -1;
155 error= (lseek(Filedes, offset, MY_SEEK_SET) != (my_off_t) -1 &&
156 (writtenbytes= write(Filedes, Buffer, Count)) == Count);
160 #elif defined (_WIN32)
161 writtenbytes= my_win_pwrite(Filedes, Buffer, Count, offset);
163 writtenbytes= pwrite(Filedes, Buffer, Count, offset);
165 if(writtenbytes == Count)
168 if (writtenbytes != (
size_t) -1)
170 written+= writtenbytes;
171 Buffer+= writtenbytes;
172 Count-= writtenbytes;
173 offset+= writtenbytes;
175 DBUG_PRINT(
"error",(
"Write only %u bytes", (uint) writtenbytes));
176 #ifndef NO_BACKGROUND
178 if (my_thread_var->abort)
179 MyFlags&= ~ MY_WAIT_IF_FULL;
181 if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
182 (MyFlags & MY_WAIT_IF_FULL))
184 wait_for_free_space(my_filename(Filedes), errors);
188 if ((writtenbytes && writtenbytes != (
size_t) -1) || my_errno == EINTR)
191 if (MyFlags & (MY_NABP | MY_FNABP))
193 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
195 char errbuf[MYSYS_STRERROR_SIZE];
196 my_error(EE_WRITE, MYF(ME_BELL | ME_WAITTANG), my_filename(Filedes),
197 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
199 DBUG_RETURN(MY_FILE_ERROR);
204 DBUG_EXECUTE_IF(
"check", my_seek(Filedes, -1, SEEK_SET, MYF(0)););
205 if (MyFlags & (MY_NABP | MY_FNABP))
207 DBUG_RETURN(writtenbytes+written);