33
33
*
34
34
*/
35
35
char *
36
- slurpFile (const char * datadir ,const char * path ,size_t * filesize )
36
+ slurpFile (const char * datadir ,const char * path ,size_t * filesize , bool safe )
37
37
{
38
38
int fd ;
39
39
char * buffer ;
@@ -43,20 +43,35 @@ slurpFile(const char *datadir, const char *path, size_t *filesize)
43
43
snprintf (fullpath ,sizeof (fullpath ),"%s/%s" ,datadir ,path );
44
44
45
45
if ((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
+ }
48
53
49
54
if (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
+ }
52
62
53
63
len = statbuf .st_size ;
54
64
55
65
buffer = pg_malloc (len + 1 );
56
66
57
67
if (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
+ }
60
75
61
76
close (fd );
62
77