13
13
along with this program; if not, write to the Free Software
14
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18
#include "drizzled/internal/my_sys.h"
19
#include "drizzled/internal/thread_var.h"
20
#include "drizzled/error.h"
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
28
21
/* Write a chunk of bytes to a file */
30
size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags)
23
size_t my_write(int Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
32
25
size_t writenbytes, written;
27
DBUG_ENTER("my_write");
28
DBUG_PRINT("my",("Fd: %d Buffer: 0x%lx Count: %lu MyFlags: %d",
29
Filedes, (long) Buffer, (ulong) Count, MyFlags));
34
30
errors=0; written=0;
36
32
/* The behavior of write(fd, buf, 0) is not portable */
37
33
if (unlikely(!Count))
42
38
if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
47
43
Buffer+=writenbytes;
48
44
Count-=writenbytes;
47
DBUG_PRINT("error",("Write only %ld bytes, error: %d",
48
(long) writenbytes, my_errno));
50
if (my_thread_var->abort)
51
MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */
52
if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
53
(MyFlags & MY_WAIT_IF_FULL))
55
if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
56
my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
57
my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
58
VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
62
if ((writenbytes == 0 || writenbytes == (size_t) -1))
64
if (my_errno == EINTR)
66
DBUG_PRINT("debug", ("my_write() was interrupted and returned %ld",
68
continue; /* Interrupted */
71
if (!writenbytes && !errors++) /* Retry once */
73
/* We may come here if the file quota is exeeded */
74
errno=EFBIG; /* Assume this is the error */
51
81
if (MyFlags & (MY_NABP | MY_FNABP))
53
83
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
55
85
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
86
my_filename(Filedes),my_errno);
58
return(MY_FILE_ERROR); /* Error on read */
88
DBUG_RETURN(MY_FILE_ERROR); /* Error on read */
61
91
break; /* Return bytes written */
63
93
if (MyFlags & (MY_NABP | MY_FNABP))
64
return(0); /* Want only errors */
65
return(writenbytes+written);
94
DBUG_RETURN(0); /* Want only errors */
95
DBUG_RETURN(writenbytes+written);
68
} /* namespace internal */
69
} /* namespace drizzled */