MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / my_read

Function my_read

mysys/my_read.c:36–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

34*/
35
36size_t my_read(File Filedes, uchar *Buffer, size_t Count, myf MyFlags)
37{
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));
42 save_count= Count;
43
44 for (;;)
45 {
46 errno= 0; /* Linux, Windows don't reset this on EOF/success */
47#ifdef _WIN32
48 readbytes= my_win_read(Filedes, Buffer, Count);
49#else
50 readbytes= read(Filedes, Buffer, Count);
51#endif
52 DBUG_EXECUTE_IF ("simulate_file_read_error",
53 {
54 errno= ENOSPC;
55 readbytes= (size_t) -1;
56 DBUG_SET("-d,simulate_file_read_error");
57 DBUG_SET("-d,simulate_my_b_fill_error");
58 });
59
60 if (readbytes != Count)
61 {
62 my_errno= errno;
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,
68 my_errno));
69
70 if ((readbytes == 0 || (int) readbytes == -1) && errno == EINTR)
71 {
72 DBUG_PRINT("debug", ("my_read() was interrupted and returned %ld",
73 (long) readbytes));
74 continue; /* Interrupted */
75 }
76
77 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
78 {
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));
86 }
87 if (readbytes == (size_t) -1 ||
88 ((MyFlags & (MY_FNABP | MY_NABP)) && !(MyFlags & MY_FULL_IO)))
89 DBUG_RETURN(MY_FILE_ERROR); /* Return with error */
90 if (readbytes != (size_t) -1 && (MyFlags & MY_FULL_IO))
91 {
92 Buffer+= readbytes;
93 Count-= readbytes;

Callers 6

get_passwordFunction · 0.85
symdirgetFunction · 0.85
my_b_fillFunction · 0.85
my_copyFunction · 0.85
fill_buffer_retainingFunction · 0.85
inline_mysql_file_readFunction · 0.85

Calls 4

my_win_readFunction · 0.85
my_errorFunction · 0.85
my_filenameFunction · 0.85
my_strerrorFunction · 0.85

Tested by

no test coverage detected