@ -42,7 +42,7 @@
* Portions Copyright ( c ) 1994 , Regents of the University of California
* Portions Copyright ( c ) 1994 , Regents of the University of California
* Portions taken from FreeBSD .
* Portions taken from FreeBSD .
*
*
* $ PostgreSQL : pgsql / src / bin / initdb / initdb . c , v 1.173 2009 / 09 / 01 02 : 5 4: 52 alvherre Exp $
* $ PostgreSQL : pgsql / src / bin / initdb / initdb . c , v 1.174 2009 / 09 / 02 02 : 40 : 52 tgl Exp $
*
*
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
*/
*/
@ -149,7 +149,7 @@ static char **replace_token(char **lines,
# ifndef HAVE_UNIX_SOCKETS
# ifndef HAVE_UNIX_SOCKETS
static char * * filter_lines_with_token ( char * * lines , const char * token ) ;
static char * * filter_lines_with_token ( char * * lines , const char * token ) ;
# endif
# endif
static char * * readfile ( char * path ) ;
static char * * readfile ( const char * path ) ;
static void writefile ( char * path , char * * lines ) ;
static void writefile ( char * path , char * * lines ) ;
static FILE * popen_check ( const char * command , const char * mode ) ;
static FILE * popen_check ( const char * command , const char * mode ) ;
static int mkdir_p ( char * path , mode_t omode ) ;
static int mkdir_p ( char * path , mode_t omode ) ;
@ -362,10 +362,10 @@ filter_lines_with_token(char **lines, const char *token)
* get the lines from a text file
* get the lines from a text file
*/
*/
static char * *
static char * *
readfile ( char * path )
readfile ( const char * path )
{
{
FILE * infile ;
FILE * infile ;
int maxlength = 0 ,
int maxlength = 1 ,
linelen = 0 ;
linelen = 0 ;
int nlines = 0 ;
int nlines = 0 ;
char * * result ;
char * * result ;
@ -394,26 +394,20 @@ readfile(char *path)
}
}
/* handle last line without a terminating newline (yuck) */
/* handle last line without a terminating newline (yuck) */
if ( linelen )
if ( linelen )
nlines + + ;
nlines + + ;
if ( linelen > maxlength )
if ( linelen > maxlength )
maxlength = linelen ;
maxlength = linelen ;
/* set up the result and the line buffer */
/* set up the result and the line buffer */
result = ( char * * ) pg_malloc ( ( nlines + 1 ) * sizeof ( char * ) ) ;
result = ( char * * ) pg_malloc ( ( nlines + 2 ) * sizeof ( char * ) ) ;
buffer = ( char * ) pg_malloc ( maxlength + 1 ) ;
buffer = ( char * ) pg_malloc ( maxlength + 2 ) ;
/* now reprocess the file and store the lines */
/* now reprocess the file and store the lines */
rewind ( infile ) ;
rewind ( infile ) ;
nlines = 0 ;
nlines = 0 ;
while ( fgets ( buffer , maxlength + 1 , infile ) ! = NULL )
while ( fgets ( buffer , maxlength + 1 , infile ) ! = NULL )
{
result [ nlines + + ] = xstrdup ( buffer ) ;
result [ nlines ] = xstrdup ( buffer ) ;
nlines + + ;
}
fclose ( infile ) ;
fclose ( infile ) ;
free ( buffer ) ;
free ( buffer ) ;