1
/* Copyright (C) 2000 MySQL AB
3
This program is free software; you can redistribute it and/or modify
4
it under the terms of the GNU General Public License as published by
5
the Free Software Foundation; version 2 of the License.
7
This program is distributed in the hope that it will be useful,
8
but WITHOUT ANY WARRANTY; without even the implied warranty of
9
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10
GNU General Public License for more details.
12
You should have received a copy of the GNU General Public License
13
along with this program; if not, write to the Free Software
14
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
16
#include "mysys_priv.h"
17
#include "mysys_err.h"
21
/* Write a chunk of bytes to a file */
23
size_t my_write(int Filedes, const uchar *Buffer, size_t Count, myf MyFlags)
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));
32
/* The behavior of write(fd, buf, 0) is not portable */
38
if ((writenbytes= write(Filedes, Buffer, Count)) == Count)
40
if (writenbytes != (size_t) -1)
47
DBUG_PRINT("error",("Write only %ld bytes, error: %d",
48
(long) writenbytes, my_errno));
51
if (my_thread_var->abort)
52
MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */
54
if ((my_errno == ENOSPC || my_errno == EDQUOT) &&
55
(MyFlags & MY_WAIT_IF_FULL))
57
wait_for_free_space(my_filename(Filedes), errors);
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 */
81
if (MyFlags & (MY_NABP | MY_FNABP))
83
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
85
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
86
my_filename(Filedes),my_errno);
88
DBUG_RETURN(MY_FILE_ERROR); /* Error on read */
91
break; /* Return bytes written */
93
if (MyFlags & (MY_NABP | MY_FNABP))
94
DBUG_RETURN(0); /* Want only errors */
95
DBUG_RETURN(writenbytes+written);