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

Function my_fwrite

mysys/my_fstream.c:97–168  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

95*/
96
97size_t my_fwrite(FILE *stream, const uchar *Buffer, size_t Count, myf MyFlags)
98{
99 size_t writtenbytes =0;
100 my_off_t seekptr;
101#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
102 uint errors;
103#endif
104 DBUG_ENTER("my_fwrite");
105 DBUG_PRINT("my",("stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
106 (long) stream, (long) Buffer, (uint) Count, MyFlags));
107 DBUG_EXECUTE_IF("simulate_fwrite_error", DBUG_RETURN(-1););
108
109#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
110 errors=0;
111#endif
112 seekptr= ftell(stream);
113 for (;;)
114 {
115 size_t written;
116 if ((written = (size_t) fwrite((char*) Buffer,sizeof(char),
117 Count, stream)) != Count)
118 {
119 DBUG_PRINT("error",("Write only %d bytes", (int) writtenbytes));
120 my_errno=errno;
121 if (written != (size_t) -1)
122 {
123 seekptr+=written;
124 Buffer+=written;
125 writtenbytes+=written;
126 Count-=written;
127 }
128#ifdef EINTR
129 if (errno == EINTR)
130 {
131 (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
132 continue;
133 }
134#endif
135#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
136 if (my_thread_var->abort)
137 MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */
138
139 if ((errno == ENOSPC || errno == EDQUOT) &&
140 (MyFlags & MY_WAIT_IF_FULL))
141 {
142 wait_for_free_space("[stream]", errors);
143 errors++;
144 (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
145 continue;
146 }
147#endif
148 if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP)))
149 {
150 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
151 {
152 char errbuf[MYSYS_STRERROR_SIZE];
153 my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
154 my_filename(my_fileno(stream)),

Callers 4

my_b_copy_to_fileFunction · 0.85
convert_pipeFunction · 0.85
create_sys_filesFunction · 0.85
inline_mysql_file_fwriteFunction · 0.85

Calls 6

my_fseekFunction · 0.85
wait_for_free_spaceFunction · 0.85
my_errorFunction · 0.85
my_filenameFunction · 0.85
my_filenoFunction · 0.85
my_strerrorFunction · 0.85

Tested by

no test coverage detected