(fd,n)
| 964 | */ |
| 965 | |
| 966 | static int fill_buffer_retaining(fd,n) |
| 967 | File fd; |
| 968 | int n; |
| 969 | { |
| 970 | int i; |
| 971 | |
| 972 | /* See if we need to grow the buffer. */ |
| 973 | if ((int) bufalloc - n <= bufread) |
| 974 | { |
| 975 | while ((int) bufalloc - n <= bufread) |
| 976 | { |
| 977 | bufalloc *= 2; |
| 978 | bufread *= 2; |
| 979 | } |
| 980 | buffer = my_realloc(buffer, bufalloc+1, MYF(MY_WME)); |
| 981 | if (! buffer) |
| 982 | return(-1); |
| 983 | } |
| 984 | |
| 985 | /* Shift stuff down. */ |
| 986 | bmove(buffer,buffer+bufbytes-n,(uint) n); |
| 987 | bufbytes = n; |
| 988 | |
| 989 | if (my_eof) |
| 990 | return 0; |
| 991 | |
| 992 | /* Read in new stuff. */ |
| 993 | if ((i=(int) my_read(fd, (uchar*) buffer + bufbytes, |
| 994 | (size_t) bufread, MYF(MY_WME))) < 0) |
| 995 | return -1; |
| 996 | |
| 997 | /* Kludge to pretend every nonempty file ends with a newline. */ |
| 998 | if (i == 0 && bufbytes > 0 && buffer[bufbytes - 1] != '\n') |
| 999 | { |
| 1000 | my_eof = i = 1; |
| 1001 | buffer[bufbytes] = '\n'; |
| 1002 | } |
| 1003 | |
| 1004 | bufbytes += i; |
| 1005 | return i; |
| 1006 | } |
| 1007 | |
| 1008 | /* Return 0 if convert is ok */ |
| 1009 | /* Global variable update is set if something was changed */ |
no test coverage detected