1
by brian
clean slate |
1 |
/* Copyright (C) 2000 MySQL AB
|
2 |
||
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.
|
|
6 |
||
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.
|
|
11 |
||
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 */
|
|
15 |
||
16 |
#include "mysys_priv.h" |
|
17 |
#include "mysys_err.h" |
|
18 |
#include <errno.h> |
|
19 |
||
20 |
||
21 |
/* Write a chunk of bytes to a file */
|
|
22 |
||
481
by Brian Aker
Remove all of uchar. |
23 |
size_t my_write(int Filedes, const unsigned char *Buffer, size_t Count, myf MyFlags) |
1
by brian
clean slate |
24 |
{
|
25 |
size_t writenbytes, written; |
|
482
by Brian Aker
Remove uint. |
26 |
uint32_t errors; |
1
by brian
clean slate |
27 |
errors=0; written=0; |
28 |
||
29 |
/* The behavior of write(fd, buf, 0) is not portable */
|
|
30 |
if (unlikely(!Count)) |
|
51.3.15
by Jay Pipes
Phase 3 removal of DBUG in mysys |
31 |
return(0); |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
32 |
|
1
by brian
clean slate |
33 |
for (;;) |
34 |
{
|
|
35 |
if ((writenbytes= write(Filedes, Buffer, Count)) == Count) |
|
36 |
break; |
|
37 |
if (writenbytes != (size_t) -1) |
|
38 |
{ /* Safeguard */ |
|
39 |
written+=writenbytes; |
|
40 |
Buffer+=writenbytes; |
|
41 |
Count-=writenbytes; |
|
42 |
}
|
|
43 |
my_errno=errno; |
|
44 |
#ifndef NO_BACKGROUND
|
|
45 |
if (my_thread_var->abort) |
|
46 |
MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */ |
|
47 |
if ((my_errno == ENOSPC || my_errno == EDQUOT) && |
|
48 |
(MyFlags & MY_WAIT_IF_FULL)) |
|
49 |
{
|
|
50 |
if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE)) |
|
51 |
my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH), |
|
52 |
my_filename(Filedes),my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC); |
|
398.1.10
by Monty Taylor
Actually removed VOID() this time. |
53 |
sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC); |
1
by brian
clean slate |
54 |
continue; |
55 |
}
|
|
56 |
||
57 |
if ((writenbytes == 0 || writenbytes == (size_t) -1)) |
|
58 |
{
|
|
59 |
if (my_errno == EINTR) |
|
60 |
{
|
|
61 |
continue; /* Interrupted */ |
|
62 |
}
|
|
63 |
||
64 |
if (!writenbytes && !errors++) /* Retry once */ |
|
65 |
{
|
|
66 |
/* We may come here if the file quota is exeeded */
|
|
67 |
errno=EFBIG; /* Assume this is the error */ |
|
68 |
continue; |
|
69 |
}
|
|
70 |
}
|
|
71 |
else
|
|
72 |
continue; /* Retry */ |
|
73 |
#endif
|
|
74 |
if (MyFlags & (MY_NABP | MY_FNABP)) |
|
75 |
{
|
|
76 |
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP)) |
|
77 |
{
|
|
78 |
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG), |
|
79 |
my_filename(Filedes),my_errno); |
|
80 |
}
|
|
51.3.15
by Jay Pipes
Phase 3 removal of DBUG in mysys |
81 |
return(MY_FILE_ERROR); /* Error on read */ |
1
by brian
clean slate |
82 |
}
|
83 |
else
|
|
84 |
break; /* Return bytes written */ |
|
85 |
}
|
|
86 |
if (MyFlags & (MY_NABP | MY_FNABP)) |
|
51.3.15
by Jay Pipes
Phase 3 removal of DBUG in mysys |
87 |
return(0); /* Want only errors */ |
88 |
return(writenbytes+written); |
|
1
by brian
clean slate |
89 |
} /* my_write */ |