3333 *
3434 */
3535char *
36- slurpFile (const char * datadir ,const char * path ,size_t * filesize )
36+ slurpFile (const char * datadir ,const char * path ,size_t * filesize , bool safe )
3737{
3838int fd ;
3939char * buffer ;
@@ -43,20 +43,35 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
4343snprintf (fullpath ,sizeof (fullpath ),"%s/%s" ,datadir ,path );
4444
4545if ((fd = open (fullpath ,O_RDONLY |PG_BINARY ,0 ))== -1 )
46- elog (ERROR ,"could not open file \"%s\" for reading: %s" ,
47- fullpath ,strerror (errno ));
46+ {
47+ if (safe )
48+ return NULL ;
49+ else
50+ elog (ERROR ,"could not open file \"%s\" for reading: %s" ,
51+ fullpath ,strerror (errno ));
52+ }
4853
4954if (fstat (fd ,& statbuf )< 0 )
50- elog (ERROR ,"could not open file \"%s\" for reading: %s" ,
51- fullpath ,strerror (errno ));
55+ {
56+ if (safe )
57+ return NULL ;
58+ else
59+ elog (ERROR ,"could not open file \"%s\" for reading: %s" ,
60+ fullpath ,strerror (errno ));
61+ }
5262
5363len = statbuf .st_size ;
5464
5565buffer = pg_malloc (len + 1 );
5666
5767if (read (fd ,buffer ,len )!= len )
58- elog (ERROR ,"could not read file \"%s\": %s\n" ,
59- fullpath ,strerror (errno ));
68+ {
69+ if (safe )
70+ return NULL ;
71+ else
72+ elog (ERROR ,"could not read file \"%s\": %s\n" ,
73+ fullpath ,strerror (errno ));
74+ }
6075
6176close (fd );
6277