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
if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
58
my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
59
my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
60
VOID(sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC));
64
if ((writenbytes == 0 || writenbytes == (size_t) -1))
66
if (my_errno == EINTR)
68
DBUG_PRINT("debug", ("my_write() was interrupted and returned %ld",
70
continue; /* Interrupted */
73
if (!writenbytes && !errors++) /* Retry once */
75
/* We may come here if the file quota is exeeded */
76
errno=EFBIG; /* Assume this is the error */
83
if (MyFlags & (MY_NABP | MY_FNABP))
85
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
87
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
88
my_filename(Filedes),my_errno);
90
DBUG_RETURN(MY_FILE_ERROR); /* Error on read */
93
break; /* Return bytes written */
95
if (MyFlags & (MY_NABP | MY_FNABP))
96
DBUG_RETURN(0); /* Want only errors */
97
DBUG_RETURN(writenbytes+written);