Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit61a07ba

Browse files
committed
Remove pgbench's hardwired limit on line length in custom script files.
pgbench formerly failed on lines longer than BUFSIZ, unexpectedlysplitting them into multiple commands. Allow it to work with anylength of input line.Sawada Masahiko
1 parentf1f21b2 commit61a07ba

File tree

1 file changed

+48
-2
lines changed

1 file changed

+48
-2
lines changed

‎contrib/pgbench/pgbench.c

Lines changed: 48 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2016,6 +2016,49 @@ process_commands(char *buf)
20162016
returnmy_commands;
20172017
}
20182018

2019+
/*
2020+
* Read a line from fd, and return it in a malloc'd buffer.
2021+
* Return NULL at EOF.
2022+
*
2023+
* The buffer will typically be larger than necessary, but we don't care
2024+
* in this program, because we'll free it as soon as we've parsed the line.
2025+
*/
2026+
staticchar*
2027+
read_line_from_file(FILE*fd)
2028+
{
2029+
chartmpbuf[BUFSIZ];
2030+
char*buf;
2031+
size_tbuflen=BUFSIZ;
2032+
size_tused=0;
2033+
2034+
buf= (char*)palloc(buflen);
2035+
buf[0]='\0';
2036+
2037+
while (fgets(tmpbuf,BUFSIZ,fd)!=NULL)
2038+
{
2039+
size_tthislen=strlen(tmpbuf);
2040+
2041+
/* Append tmpbuf to whatever we had already */
2042+
memcpy(buf+used,tmpbuf,thislen+1);
2043+
used+=thislen;
2044+
2045+
/* Done if we collected a newline */
2046+
if (thislen>0&&tmpbuf[thislen-1]=='\n')
2047+
break;
2048+
2049+
/* Else, enlarge buf to ensure we can append next bufferload */
2050+
buflen+=BUFSIZ;
2051+
buf= (char*)pg_realloc(buf,buflen);
2052+
}
2053+
2054+
if (used>0)
2055+
returnbuf;
2056+
2057+
/* Reached EOF */
2058+
free(buf);
2059+
returnNULL;
2060+
}
2061+
20192062
staticint
20202063
process_file(char*filename)
20212064
{
@@ -2024,7 +2067,7 @@ process_file(char *filename)
20242067
Command**my_commands;
20252068
FILE*fd;
20262069
intlineno;
2027-
charbuf[BUFSIZ];
2070+
char*buf;
20282071
intalloc_num;
20292072

20302073
if (num_files >=MAX_FILES)
@@ -2046,11 +2089,14 @@ process_file(char *filename)
20462089

20472090
lineno=0;
20482091

2049-
while (fgets(buf,sizeof(buf),fd)!=NULL)
2092+
while ((buf=read_line_from_file(fd))!=NULL)
20502093
{
20512094
Command*command;
20522095

20532096
command=process_commands(buf);
2097+
2098+
free(buf);
2099+
20542100
if (command==NULL)
20552101
continue;
20562102

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp