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))
45 size_t my_fread(FILE *stream, uchar *
Buffer,
size_t Count, myf MyFlags)
48 DBUG_ENTER(
"my_fread");
49 DBUG_PRINT(
"my",(
"stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
50 (
long) stream, (
long) Buffer, (uint) Count, MyFlags));
52 if ((readbytes= fread(Buffer,
sizeof(
char), Count, stream)) != Count)
54 DBUG_PRINT(
"error",(
"Read only %d bytes", (
int) readbytes));
55 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
59 char errbuf[MYSYS_STRERROR_SIZE];
60 my_error(EE_READ, MYF(ME_BELL+ME_WAITTANG),
61 my_filename(my_fileno(stream)),
62 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
65 if (MyFlags & (MY_NABP | MY_FNABP))
67 char errbuf[MYSYS_STRERROR_SIZE];
68 my_error(EE_EOFERR, MYF(ME_BELL+ME_WAITTANG),
69 my_filename(my_fileno(stream)), errno,
70 my_strerror(errbuf,
sizeof(errbuf), errno));
73 my_errno=errno ? errno : -1;
74 if (ferror(stream) || MyFlags & (MY_NABP | MY_FNABP))
75 DBUG_RETURN((
size_t) -1);
77 if (MyFlags & (MY_NABP | MY_FNABP))
79 DBUG_RETURN(readbytes);
97 size_t my_fwrite(FILE *stream,
const uchar *Buffer,
size_t Count, myf MyFlags)
99 size_t writtenbytes =0;
101 #if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
104 DBUG_ENTER(
"my_fwrite");
105 DBUG_PRINT(
"my",(
"stream: 0x%lx Buffer: 0x%lx Count: %u MyFlags: %d",
106 (
long) stream, (
long) Buffer, (uint) Count, MyFlags));
108 #if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
111 seekptr= ftell(stream);
115 if ((written = (
size_t) fwrite((
char*) Buffer,
sizeof(
char),
116 Count, stream)) != Count)
118 DBUG_PRINT(
"error",(
"Write only %d bytes", (
int) writtenbytes));
120 if (written != (
size_t) -1)
124 writtenbytes+=written;
130 (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
134 #if !defined(NO_BACKGROUND) && defined(USE_MY_STREAM)
135 if (my_thread_var->abort)
136 MyFlags&= ~ MY_WAIT_IF_FULL;
138 if ((errno == ENOSPC || errno == EDQUOT) &&
139 (MyFlags & MY_WAIT_IF_FULL))
141 wait_for_free_space(
"[stream]", errors);
143 (void) my_fseek(stream,seekptr,MY_SEEK_SET,MYF(0));
147 if (ferror(stream) || (MyFlags & (MY_NABP | MY_FNABP)))
149 if (MyFlags & (MY_WME | MY_FAE | MY_FNABP))
151 char errbuf[MYSYS_STRERROR_SIZE];
152 my_error(EE_WRITE, MYF(ME_BELL+ME_WAITTANG),
153 my_filename(my_fileno(stream)),
154 errno, my_strerror(errbuf,
sizeof(errbuf), errno));
156 writtenbytes= (size_t) -1;
160 if (MyFlags & (MY_NABP | MY_FNABP))
163 writtenbytes+= written;
166 DBUG_RETURN(writtenbytes);
172 my_off_t my_fseek(FILE *stream, my_off_t pos,
int whence,
173 myf MyFlags __attribute__((unused)))
175 DBUG_ENTER(
"my_fseek");
176 DBUG_PRINT(
"my",(
"stream: 0x%lx pos: %lu whence: %d MyFlags: %d",
177 (
long) stream, (
long) pos, whence, MyFlags));
178 DBUG_RETURN(fseek(stream, (off_t) pos, whence) ?
179 MY_FILEPOS_ERROR : (my_off_t) ftell(stream));
185 my_off_t my_ftell(FILE *stream, myf MyFlags __attribute__((unused)))
188 DBUG_ENTER(
"my_ftell");
189 DBUG_PRINT(
"my",(
"stream: 0x%lx MyFlags: %d", (
long) stream, MyFlags));
191 DBUG_PRINT(
"exit",(
"ftell: %lu",(ulong) pos));
192 DBUG_RETURN((my_off_t) pos);
197 int my_fileno(FILE *f)
200 return my_win_fileno(f);