MCPcopy Create free account
hub / github.com/Meituan-Dianping/SQLAdvisor / fill_buffer_retaining

Function fill_buffer_retaining

extra/replace.c:966–1006  ·  view source on GitHub ↗
(fd,n)

Source from the content-addressed store, hash-verified

964*/
965
966static int fill_buffer_retaining(fd,n)
967File fd;
968int 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 */

Callers 1

convert_pipeFunction · 0.85

Calls 2

my_reallocFunction · 0.85
my_readFunction · 0.85

Tested by

no test coverage detected