--- contrib/tsearch2/dict_syn.c.orig Tue Aug 7 11:31:33 2007 +++ contrib/tsearch2/dict_syn.c Tue Aug 7 11:54:05 2007 @@ -7,6 +7,10 @@ #include "postgres.h" #include +#include +#include +#include +#include #include "dict.h" #include "common.h" @@ -64,7 +68,7 @@ text *in; DictSyn *d; int cur = 0; - FILE *fin; + int fd = -1; char *filename; char buf[SYNBUFLEN]; char *starti, @@ -85,23 +89,24 @@ filename = text2char(in); PG_FREE_IF_COPY(in, 0); - if ((fin = fopen(filename, "r")) == NULL) - ereport(ERROR, - (errcode_for_file_access(), - 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))); + } d = (DictSyn *) malloc(sizeof(DictSyn)); if (!d) { - fclose(fin); + close(fd); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); } memset(d, 0, sizeof(DictSyn)); - while (fgets(buf, SYNBUFLEN, fin)) + while ( read(fd, buf, SYNBUFLEN ) ) { slen = strlen(buf) - 1; buf[slen] = '\0'; @@ -113,7 +118,7 @@ d->syn = (Syn *) realloc(d->syn, sizeof(Syn) * d->len); if (!d->syn) { - fclose(fin); + close(fd); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); @@ -136,7 +141,7 @@ d->syn[cur].out = strdup(lowerstr(starto)); if (!(d->syn[cur].in && d->syn[cur].out)) { - fclose(fin); + close(fd); ereport(ERROR, (errcode(ERRCODE_OUT_OF_MEMORY), errmsg("out of memory"))); @@ -145,7 +150,7 @@ cur++; } - fclose(fin); + close(fd); d->len = cur; if (cur > 1)