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
/* USE_MY_STREAM isn't set because we can't thrust my_fclose! */
18
#include "mysys_priv.h"
19
#include "mysys_err.h"
26
#define ftell(A) ftello(A)
27
#define fseek(A,B,C) fseeko((A),(B),(C))
32
Write a chunk of bytes to a stream
35
stream File descriptor
36
Buffer Buffer to write from
37
Count Number of bytes to write
38
MyFlags Flags on what to do on error
42
# Number of bytes written
45
size_t my_fwrite(FILE *stream, const unsigned char *Buffer, size_t Count, myf MyFlags)
47
size_t writtenbytes =0;
49
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
53
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
56
seekptr= ftell(stream);
60
if ((written = (size_t) fwrite((char*) Buffer,sizeof(char),
61
Count, stream)) != Count)
64
if (written != (size_t) -1)
68
writtenbytes+=written;
74
my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
78
#if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
79
if (my_thread_var->abort)
80
MyFlags&= ~ MY_WAIT_IF_FULL; /* End if aborted by user */
81
if ((errno == ENOSPC || errno == EDQUOT) &&
82
(MyFlags & MY_WAIT_IF_FULL))
84
if (!(errors++ % MY_WAIT_GIVE_USER_A_MESSAGE))
85
my_error(EE_DISK_FULL,MYF(ME_BELL | ME_NOREFRESH),
86
"[stream]",my_errno,MY_WAIT_FOR_USER_TO_FIX_PANIC);
87
sleep(MY_WAIT_FOR_USER_TO_FIX_PANIC);
88
my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
92
if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP)))
94
if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
96
my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
97
my_filename(fileno(stream)),errno);
99
writtenbytes= (size_t) -1; /* Return that we got error */
103
if (MyFlags & (MY_NABP | MY_FNABP))
104
writtenbytes= 0; /* Everything OK */
106
writtenbytes+= written;
109
return(writtenbytes);
113
/* Seek to position in file */
115
my_off_t my_fseek(FILE *stream, my_off_t pos, int whence, myf)
117
return(fseeko(stream, (off_t) pos, whence) ?
118
MY_FILEPOS_ERROR : (my_off_t) ftell(stream));