--- contrib/tsearch2/ispell/spell.c.orig Tue Jul 31 16:45:45 2007 +++ contrib/tsearch2/ispell/spell.c Tue Aug 7 11:47:45 2007 @@ -1,6 +1,10 @@ #include "postgres.h" #include +#include +#include +#include +#include #include "spell.h" #include "common.h" @@ -148,11 +152,16 @@ NIImportDictionary(IspellDict * Conf, const char *filename) { char str[BUFSIZ], *pstr; - FILE *dict; - - if (!(dict = fopen(filename, "r"))) + int fd = -1; + 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))); return (1); - while (fgets(str, sizeof(str), dict)) + } + + while ( read(fd, str, sizeof(str) ) ) { char *s; const char *flag; @@ -195,7 +204,7 @@ NIAddSpell(Conf, pstr, flag); pfree(pstr); } - fclose(dict); + close(fd); return (0); } @@ -428,15 +437,21 @@ int prefixes = 0; int flag = 0; char flagflags = 0; - FILE *affix; + int fd = -1; int line = 0; int oldformat = 0; - if (!(affix = fopen(filename, "r"))) + 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))); return (1); + } + Conf->compoundcontrol = '\t'; - while (fgets(str, sizeof(str), affix)) + while ( read(fd, str, sizeof(str) ) ) { line++; if ( *str == '#' || *str == '\n' ) @@ -519,7 +534,7 @@ if (oldformat) elog(ERROR, "Wrong affix file format"); - fclose(affix); + close(fd); return NIImportOOAffixes(Conf, filename); } @@ -531,7 +546,7 @@ NIAddAffix(Conf, flag, flagflags, mask, find, repl, suffixes ? FF_SUFFIX : FF_PREFIX); } - fclose(affix); + close(fd); if ( pstr ) pfree( pstr ); @@ -551,18 +566,24 @@ bool isSuffix = false; int flag = 0; char flagflags = 0; - FILE *affix; + int fd = -1; int line = 0; int scanread = 0; char scanbuf[BUFSIZ]; sprintf(scanbuf, "%%6s %%%ds %%%ds %%%ds %%%ds", BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5, BUFSIZ / 5); - if (!(affix = fopen(filename, "r"))) + 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))); return (1); + } + Conf->compoundcontrol = '\t'; - while (fgets(str, sizeof(str), affix)) + while ( read(fd, str, sizeof(str) ) ) { line++; if (*str == '\0' || t_isspace(str) || t_iseq(str, '#')) @@ -622,7 +643,7 @@ if (ptype) pfree(ptype); - fclose(affix); + close(fd); return 0; }