@@ -24,7 +24,7 @@ static bool init_line_buffer(LINE_BUFFER *buffer,File file,ulong size,
24
24
ulong max_size);
25
25
static bool init_line_buffer_from_string (LINE_BUFFER *buffer,char * str);
26
26
static size_t fill_buffer (LINE_BUFFER *buffer);
27
- static char *intern_read_line (LINE_BUFFER *buffer, ulong *out_length, bool *truncated );
27
+ static char *intern_read_line (LINE_BUFFER *buffer, ulong *out_length);
28
28
29
29
30
30
LINE_BUFFER *batch_readline_init (ulong max_size,FILE *file)
@@ -42,13 +42,12 @@ LINE_BUFFER *batch_readline_init(ulong max_size,FILE *file)
42
42
}
43
43
44
44
45
- char *batch_readline (LINE_BUFFER *line_buff, bool *truncated )
45
+ char *batch_readline (LINE_BUFFER *line_buff)
46
46
{
47
47
char *pos;
48
48
ulong out_length;
49
- DBUG_ASSERT (truncated != NULL );
50
49
51
- if (!(pos=intern_read_line (line_buff,&out_length, truncated )))
50
+ if (!(pos=intern_read_line (line_buff, &out_length)))
52
51
return 0 ;
53
52
if (out_length && pos[out_length-1 ] == ' \n ' )
54
53
if (--out_length && pos[out_length-1 ] == ' \r ' ) /* Remove '\n' */
@@ -162,7 +161,10 @@ static size_t fill_buffer(LINE_BUFFER *buffer)
162
161
if (!(buffer->buffer = (char *) my_realloc (buffer->buffer ,
163
162
buffer->bufread +1 ,
164
163
MYF (MY_WME | MY_FAE))))
165
- return (uint ) -1 ;
164
+ {
165
+ buffer->error = my_errno;
166
+ return (size_t ) -1 ;
167
+ }
166
168
buffer->start_of_line =buffer->buffer +start_offset;
167
169
buffer->end =buffer->buffer +bufbytes;
168
170
}
@@ -177,7 +179,10 @@ static size_t fill_buffer(LINE_BUFFER *buffer)
177
179
/* Read in new stuff. */
178
180
if ((read_count= my_read (buffer->file , (uchar*) buffer->end , read_count,
179
181
MYF (MY_WME))) == MY_FILE_ERROR)
182
+ {
183
+ buffer->error = my_errno;
180
184
return (size_t ) -1 ;
185
+ }
181
186
182
187
DBUG_PRINT (" fill_buff" , (" Got %lu bytes" , (ulong) read_count));
183
188
@@ -198,8 +203,7 @@ static size_t fill_buffer(LINE_BUFFER *buffer)
198
203
}
199
204
200
205
201
-
202
- char *intern_read_line (LINE_BUFFER *buffer, ulong *out_length, bool *truncated)
206
+ char *intern_read_line (LINE_BUFFER *buffer, ulong *out_length)
203
207
{
204
208
char *pos;
205
209
size_t length;
@@ -214,22 +218,25 @@ char *intern_read_line(LINE_BUFFER *buffer, ulong *out_length, bool *truncated)
214
218
if (pos == buffer->end )
215
219
{
216
220
/*
217
- fill_buffer() can return 0 either on EOF in which case we abort
218
- or when the internal buffer has hit the size limit. In the latter case
219
- return what we have read so far and signal string truncation.
221
+ fill_buffer() can return NULL on EOF (in which case we abort),
222
+ on error, or when the internal buffer has hit the size limit.
223
+ In the latter case return what we have read so far and signal
224
+ string truncation.
220
225
*/
221
- if (!(length=fill_buffer (buffer)) || length == ( uint ) - 1 )
226
+ if (!(length= fill_buffer (buffer)))
222
227
{
223
228
if (buffer->eof )
224
229
DBUG_RETURN (0 );
225
230
}
231
+ else if (length == (size_t ) -1 )
232
+ DBUG_RETURN (NULL );
226
233
else
227
234
continue ;
228
235
pos--; /* break line here */
229
- * truncated= 1 ;
236
+ buffer-> truncated = 1 ;
230
237
}
231
238
else
232
- * truncated= 0 ;
239
+ buffer-> truncated = 0 ;
233
240
buffer->end_of_line =pos+1 ;
234
241
*out_length=(ulong) (pos + 1 - buffer->eof - buffer->start_of_line );
235
242
DBUG_RETURN (buffer->start_of_line );
0 commit comments