--- contrib/tsearch2/stopword.c.orig Tue Aug 7 11:31:48 2007 +++ contrib/tsearch2/stopword.c Tue Aug 7 12:00:12 2007 @@ -4,6 +4,11 @@ */ #include "postgres.h" +#include +#include +#include +#include + #include "common.h" #include "dict.h" #include "ts_locale.h" @@ -35,17 +40,18 @@ if (in && VARSIZE(in) - VARHDRSZ > 0) { char *filename = to_absfilename(text2char(in)); - FILE *hin; + int fd = -1; char buf[STOPBUFLEN], *pbuf; int reallen = 0; - if ((hin = fopen(filename, "r")) == NULL) - ereport(ERROR, - (errcode(ERRCODE_CONFIG_FILE_ERROR), - errmsg("could not open file \"%s\": %m", - filename))); + if ( -1 == ( fd = open( filename, O_RDONLY ) ) ) + { + char *errbuff = strerror(errno); + ereport(ERROR, (errcode(ERRCODE_SUCCESSFUL_COMPLETION), + errmsg("%s.%i: Could not load %s. %s", __FILE__, __LINE__, filename, errbuff))); + } - while (fgets(buf, STOPBUFLEN, hin)) + while ( read(fd, buf, STOPBUFLEN ) ) { buf[strlen(buf) - 1] = '\0'; pg_verifymbstr(buf, strlen(buf), false); @@ -61,7 +67,7 @@ if (!tmp) { freestoplist(s); - fclose(hin); + close(fd); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); @@ -80,7 +86,7 @@ if (!stop[s->len]) { freestoplist(s); - fclose(hin); + close(fd); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); @@ -88,7 +94,7 @@ (s->len)++; } - fclose(hin); + close(fd); pfree(filename); } s->stop = stop;