16 #include "mysys_priv.h"
17 #include "mysys_err.h"
23 size_t my_write(File Filedes,
const uchar *
Buffer,
size_t Count, myf MyFlags)
25 size_t writtenbytes, written;
27 DBUG_ENTER(
"my_write");
28 DBUG_PRINT(
"my",(
"fd: %d Buffer: %p Count: %lu MyFlags: %d",
29 Filedes, Buffer, (ulong) Count, MyFlags));
30 errors= 0; written= 0;
36 DBUG_EXECUTE_IF (
"simulate_no_free_space_error",
37 { DBUG_SET(
"+d,simulate_file_write_error");});
41 writtenbytes= my_win_write(Filedes, Buffer, Count);
43 writtenbytes= write(Filedes, Buffer, Count);
45 DBUG_EXECUTE_IF(
"simulate_file_write_error",
48 writtenbytes= (size_t) -1;
50 if (writtenbytes == Count)
52 if (writtenbytes != (
size_t) -1)
54 written+= writtenbytes;
55 Buffer+= writtenbytes;
59 DBUG_PRINT(
"error",(
"Write only %ld bytes, error: %d",
60 (
long) writtenbytes, my_errno));
62 if (my_thread_var->abort)
63 MyFlags&= ~ MY_WAIT_IF_FULL;
65 if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
66 (MyFlags & MY_WAIT_IF_FULL))
68 wait_for_free_space(my_filename(Filedes), errors);
70 DBUG_EXECUTE_IF(
"simulate_no_free_space_error",
71 { DBUG_SET(
"-d,simulate_file_write_error");});
75 if ((writtenbytes == 0 || writtenbytes == (
size_t) -1))
77 if (my_errno == EINTR)
79 DBUG_PRINT(
"debug", (
"my_write() was interrupted and returned %ld",
80 (
long) writtenbytes));
84 if (!writtenbytes && !errors++)
94 if (MyFlags & (MY_NABP | MY_FNABP))
96 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
98 char errbuf[MYSYS_STRERROR_SIZE];
99 my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), my_filename(Filedes),
100 my_errno, my_strerror(errbuf,
sizeof(errbuf), my_errno));
102 DBUG_RETURN(MY_FILE_ERROR);
107 if (MyFlags & (MY_NABP | MY_FNABP))
109 DBUG_RETURN(writtenbytes+written);