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

Function my_pread

mysys/my_pread.c:48–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46*/
47
48size_t my_pread(File Filedes, uchar *Buffer, size_t Count, my_off_t offset,
49 myf MyFlags)
50{
51 size_t readbytes;
52 size_t total_readbytes= 0;
53 int error= 0;
54#if !defined (HAVE_PREAD) && !defined (_WIN32)
55 int save_errno;
56#endif
57 DBUG_ENTER("my_pread");
58 DBUG_PRINT("my",("fd: %d Seek: %llu Buffer: %p Count: %lu MyFlags: %d",
59 Filedes, (ulonglong)offset, Buffer, (ulong)Count, MyFlags));
60 for (;;)
61 {
62 errno= 0; /* Linux, Windows don't reset this on EOF/success */
63#if !defined (HAVE_PREAD) && !defined (_WIN32)
64 mysql_mutex_lock(&my_file_info[Filedes].mutex);
65 readbytes= (uint) -1;
66 error= (lseek(Filedes, offset, MY_SEEK_SET) == (my_off_t) -1 ||
67 (readbytes= read(Filedes, Buffer, Count)) != Count);
68 save_errno= errno;
69 mysql_mutex_unlock(&my_file_info[Filedes].mutex);
70 if (error)
71 errno= save_errno;
72#else
73#if defined(_WIN32)
74 readbytes= my_win_pread(Filedes, Buffer, Count, offset);
75#else
76 readbytes= pread(Filedes, Buffer, Count, offset);
77#endif
78 error= (readbytes != Count);
79#endif
80 if (readbytes > 0)
81 total_readbytes+= readbytes;
82
83 if(error)
84 {
85 if (readbytes > 0 && readbytes < Count && errno == 0)
86 {
87 /*
88 pread() may return less bytes than requested even if enough bytes are
89 available according to the Linux man page.
90 This makes determining the end-of-file condition a bit harder.
91 We just do another pread() call to see if more bytes can be read,
92 since all my_pread() users expect it to always return all available
93 bytes. For end-of-file 0 bytes is returned. This can never be the case
94 for a partial read, since according to the man page, -1 is returned
95 with errno set to EINTR if no data has been read.
96 */
97 Buffer+= readbytes;
98 offset+= readbytes;
99 Count-= readbytes;
100
101 continue;
102 }
103
104 my_errno= errno ? errno : -1;
105 if (errno == 0 || (readbytes != (size_t) -1 &&

Callers 3

read_blockFunction · 0.85
key_cache_readFunction · 0.85
inline_mysql_file_preadFunction · 0.85

Calls 4

my_win_preadFunction · 0.85
my_errorFunction · 0.85
my_filenameFunction · 0.85
my_strerrorFunction · 0.85

Tested by

no test coverage detected