16 #include "mysys_priv.h"
17 #include "mysys_err.h"
36 size_t my_read(File Filedes, uchar *
Buffer,
size_t Count, myf MyFlags)
38 size_t readbytes, save_count;
39 DBUG_ENTER(
"my_read");
40 DBUG_PRINT(
"my",(
"fd: %d Buffer: %p Count: %lu MyFlags: %d",
41 Filedes, Buffer, (ulong) Count, MyFlags));
48 readbytes= my_win_read(Filedes, Buffer, Count);
50 readbytes= read(Filedes, Buffer, Count);
52 DBUG_EXECUTE_IF (
"simulate_file_read_error",
55 readbytes= (size_t) -1;
56 DBUG_SET(
"-d,simulate_file_read_error");
57 DBUG_SET(
"-d,simulate_my_b_fill_error");
60 if (readbytes != Count)
63 if (errno == 0 || (readbytes != (
size_t) -1 &&
64 (MyFlags & (MY_NABP | MY_FNABP))))
65 my_errno= HA_ERR_FILE_TOO_SHORT;
66 DBUG_PRINT(
"warning",(
"Read only %d bytes off %lu from %d, errno: %d",
67 (
int) readbytes, (ulong) Count, Filedes,
70 if ((readbytes == 0 || (
int) readbytes == -1) && errno == EINTR)
72 DBUG_PRINT(
"debug", (
"my_read() was interrupted and returned %ld",
77 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
79 char errbuf[MYSYS_STRERROR_SIZE];
80 if (readbytes == (
size_t) -1)
81 my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),
82 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
83 else if (MyFlags & (MY_NABP | MY_FNABP))
84 my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),
85 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
87 if (readbytes == (
size_t) -1 ||
88 ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
89 DBUG_RETURN(MY_FILE_ERROR);
90 if (readbytes != (
size_t) -1 && (MyFlags & MY_FULL_IO))
98 if (MyFlags & (MY_NABP | MY_FNABP))
100 else if (MyFlags & MY_FULL_IO)
101 readbytes= save_count;
104 DBUG_RETURN(readbytes);