mirror of
https://github.com/postgres/postgres.git
synced 2025-04-22 23:02:54 +03:00
Fix use of 'char' to hold result of getc, per bug report forwarded by
Oliver Elphick. A few other minor cleanups while at it.
This commit is contained in:
parent
8ff263f362
commit
9facc585ad
@ -10,7 +10,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.78 2001/11/12 04:29:23 tgl Exp $
|
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.79 2002/01/09 19:13:40 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -111,7 +111,7 @@ next_token(FILE *fp, char *buf, const int bufsz)
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_to_eol(FILE *file)
|
read_through_eol(FILE *file)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
@ -162,7 +162,7 @@ tokenize_file(FILE *file)
|
|||||||
if (comment_ptr != NULL)
|
if (comment_ptr != NULL)
|
||||||
{
|
{
|
||||||
/* Found a comment, so skip the rest of the line */
|
/* Found a comment, so skip the rest of the line */
|
||||||
read_to_eol(file);
|
read_through_eol(file);
|
||||||
next_line = NIL;
|
next_line = NIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1159,14 +1159,12 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
|||||||
OrigCharset[MAX_TOKEN],
|
OrigCharset[MAX_TOKEN],
|
||||||
DestCharset[MAX_TOKEN],
|
DestCharset[MAX_TOKEN],
|
||||||
HostCharset[MAX_TOKEN],
|
HostCharset[MAX_TOKEN],
|
||||||
c,
|
|
||||||
eof = false,
|
|
||||||
*map_file;
|
*map_file;
|
||||||
int key = 0,
|
int key,
|
||||||
ChIndex = 0,
|
ChIndex = 0,
|
||||||
|
c,
|
||||||
i,
|
i,
|
||||||
bufsize;
|
bufsize;
|
||||||
|
|
||||||
struct CharsetItem *ChArray[MAX_CHARSETS];
|
struct CharsetItem *ChArray[MAX_CHARSETS];
|
||||||
|
|
||||||
*TableName = '\0';
|
*TableName = '\0';
|
||||||
@ -1174,27 +1172,24 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
|||||||
map_file = (char *) palloc(bufsize);
|
map_file = (char *) palloc(bufsize);
|
||||||
snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
|
snprintf(map_file, bufsize, "%s/%s", DataDir, CHARSET_FILE);
|
||||||
file = AllocateFile(map_file, PG_BINARY_R);
|
file = AllocateFile(map_file, PG_BINARY_R);
|
||||||
|
pfree(map_file);
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
{
|
||||||
/* XXX should we log a complaint? */
|
/* XXX should we log a complaint? */
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
while (!eof)
|
while ((c = getc(file)) != EOF)
|
||||||
{
|
|
||||||
c = getc(file);
|
|
||||||
ungetc(c, file);
|
|
||||||
if (c == EOF)
|
|
||||||
eof = true;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (c == '#')
|
if (c == '#')
|
||||||
read_to_eol(file);
|
read_through_eol(file);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Read the key */
|
/* Read the key */
|
||||||
|
ungetc(c, file);
|
||||||
next_token(file, buf, sizeof(buf));
|
next_token(file, buf, sizeof(buf));
|
||||||
if (buf[0] != '\0')
|
if (buf[0] != '\0')
|
||||||
{
|
{
|
||||||
|
key = 0;
|
||||||
if (strcasecmp(buf, "HostCharset") == 0)
|
if (strcasecmp(buf, "HostCharset") == 0)
|
||||||
key = KEY_HOST;
|
key = KEY_HOST;
|
||||||
if (strcasecmp(buf, "BaseCharset") == 0)
|
if (strcasecmp(buf, "BaseCharset") == 0)
|
||||||
@ -1249,20 +1244,18 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
read_to_eol(file);
|
read_through_eol(file);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FreeFile(file);
|
FreeFile(file);
|
||||||
pfree(map_file);
|
|
||||||
|
|
||||||
for (i = 0; i < ChIndex; i++)
|
for (i = 0; i < ChIndex; i++)
|
||||||
{
|
{
|
||||||
if (!strcasecmp(BaseCharset, ChArray[i]->Orig) &&
|
if (strcasecmp(BaseCharset, ChArray[i]->Orig) == 0 &&
|
||||||
!strcasecmp(HostCharset, ChArray[i]->Dest))
|
strcasecmp(HostCharset, ChArray[i]->Dest) == 0)
|
||||||
strncpy(TableName, ChArray[i]->Table, 79);
|
strncpy(TableName, ChArray[i]->Table, 79);
|
||||||
pfree((struct CharsetItem *) ChArray[i]);
|
pfree(ChArray[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
* IDENTIFICATION
|
* IDENTIFICATION
|
||||||
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.81 2001/10/25 05:49:51 momjian Exp $
|
* $Header: /cvsroot/pgsql/src/backend/utils/init/miscinit.c,v 1.82 2002/01/09 19:13:41 tgl Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -227,75 +227,80 @@ pg_convert2(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
#define MAX_TOKEN 80
|
#define MAX_TOKEN 80
|
||||||
|
|
||||||
/* Some standard C libraries, including GNU, have an isblank() function.
|
/*
|
||||||
Others, including Solaris, do not. So we have our own.
|
* Some standard C libraries, including GNU, have an isblank() function.
|
||||||
*/
|
* Others, including Solaris, do not. So we have our own.
|
||||||
|
*/
|
||||||
static bool
|
static bool
|
||||||
isblank(const char c)
|
isblank(const char c)
|
||||||
{
|
{
|
||||||
return c == ' ' || c == 9 /* tab */ ;
|
return c == ' ' || c == '\t';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Grab one token out of fp. Tokens are strings of non-blank
|
||||||
|
* characters bounded by blank characters, beginning of line, and end
|
||||||
|
* of line. Blank means space or tab. Return the token as *buf.
|
||||||
|
* Leave file positioned to character immediately after the token or
|
||||||
|
* EOF, whichever comes first. If no more tokens on line, return null
|
||||||
|
* string as *buf and position file to beginning of next line or EOF,
|
||||||
|
* whichever comes first.
|
||||||
|
*/
|
||||||
static void
|
static void
|
||||||
next_token(FILE *fp, char *buf, const int bufsz)
|
next_token(FILE *fp, char *buf, const int bufsz)
|
||||||
{
|
{
|
||||||
/*--------------------------------------------------------------------------
|
|
||||||
Grab one token out of fp. Tokens are strings of non-blank
|
|
||||||
characters bounded by blank characters, beginning of line, and end
|
|
||||||
of line. Blank means space or tab. Return the token as *buf.
|
|
||||||
Leave file positioned to character immediately after the token or
|
|
||||||
EOF, whichever comes first. If no more tokens on line, return null
|
|
||||||
string as *buf and position file to beginning of next line or EOF,
|
|
||||||
whichever comes first.
|
|
||||||
--------------------------------------------------------------------------*/
|
|
||||||
int c;
|
int c;
|
||||||
char *eb = buf + (bufsz - 1);
|
char *eb = buf + (bufsz - 1);
|
||||||
|
|
||||||
/* Move over inital token-delimiting blanks */
|
/* Move over initial token-delimiting blanks */
|
||||||
while (isblank(c = getc(fp)));
|
while ((c = getc(fp)) != EOF && isblank(c))
|
||||||
|
;
|
||||||
|
|
||||||
if (c != '\n')
|
if (c != EOF && c != '\n')
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* build a token in buf of next characters up to EOF, eol, or
|
* build a token in buf of next characters up to EOF, eol, or
|
||||||
* blank.
|
* blank. If the token gets too long, we still parse it
|
||||||
|
* correctly, but the excess characters are not stored into *buf.
|
||||||
*/
|
*/
|
||||||
while (c != EOF && c != '\n' && !isblank(c))
|
while (c != EOF && c != '\n' && !isblank(c))
|
||||||
{
|
{
|
||||||
if (buf < eb)
|
if (buf < eb)
|
||||||
*buf++ = c;
|
*buf++ = c;
|
||||||
c = getc(fp);
|
c = getc(fp);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Put back the char right after the token (putting back EOF
|
* Put back the char right after the token (critical in case it is
|
||||||
* is ok)
|
* eol, since we need to detect end-of-line at next call).
|
||||||
*/
|
*/
|
||||||
}
|
if (c != EOF)
|
||||||
ungetc(c, fp);
|
ungetc(c, fp);
|
||||||
}
|
}
|
||||||
*buf = '\0';
|
*buf = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
read_through_eol(FILE *file)
|
read_through_eol(FILE *file)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
|
|
||||||
do
|
while ((c = getc(file)) != EOF && c != '\n')
|
||||||
c = getc(file);
|
;
|
||||||
while (c != '\n' && c != EOF);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SetCharSet()
|
SetCharSet(void)
|
||||||
{
|
{
|
||||||
FILE *file;
|
FILE *file;
|
||||||
char *p,
|
char *p;
|
||||||
c,
|
|
||||||
eof = false;
|
|
||||||
char *map_file;
|
char *map_file;
|
||||||
char buf[MAX_TOKEN];
|
char buf[MAX_TOKEN];
|
||||||
int i;
|
int i,
|
||||||
|
c;
|
||||||
unsigned char FromChar,
|
unsigned char FromChar,
|
||||||
ToChar;
|
ToChar;
|
||||||
char ChTable[80];
|
char ChTable[80];
|
||||||
@ -316,30 +321,20 @@ SetCharSet()
|
|||||||
|
|
||||||
if (p && *p != '\0')
|
if (p && *p != '\0')
|
||||||
{
|
{
|
||||||
map_file = malloc(strlen(DataDir) + strlen(p) + 2);
|
map_file = palloc(strlen(DataDir) + strlen(p) + 2);
|
||||||
if (!map_file)
|
|
||||||
elog(FATAL, "out of memory");
|
|
||||||
sprintf(map_file, "%s/%s", DataDir, p);
|
sprintf(map_file, "%s/%s", DataDir, p);
|
||||||
file = AllocateFile(map_file, PG_BINARY_R);
|
file = AllocateFile(map_file, PG_BINARY_R);
|
||||||
|
pfree(map_file);
|
||||||
if (file == NULL)
|
if (file == NULL)
|
||||||
{
|
|
||||||
free(map_file);
|
|
||||||
return;
|
return;
|
||||||
}
|
while ((c = getc(file)) != EOF)
|
||||||
eof = false;
|
|
||||||
while (!eof)
|
|
||||||
{
|
|
||||||
c = getc(file);
|
|
||||||
ungetc(c, file);
|
|
||||||
if (c == EOF)
|
|
||||||
eof = true;
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
if (c == '#')
|
if (c == '#')
|
||||||
read_through_eol(file);
|
read_through_eol(file);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Read the FromChar */
|
/* Read the FromChar */
|
||||||
|
ungetc(c, file);
|
||||||
next_token(file, buf, sizeof(buf));
|
next_token(file, buf, sizeof(buf));
|
||||||
if (buf[0] != '\0')
|
if (buf[0] != '\0')
|
||||||
{
|
{
|
||||||
@ -351,14 +346,12 @@ SetCharSet()
|
|||||||
ToChar = strtoul(buf, 0, 0);
|
ToChar = strtoul(buf, 0, 0);
|
||||||
RecodeForwTable[FromChar - 128] = ToChar;
|
RecodeForwTable[FromChar - 128] = ToChar;
|
||||||
RecodeBackTable[ToChar - 128] = FromChar;
|
RecodeBackTable[ToChar - 128] = FromChar;
|
||||||
}
|
|
||||||
read_through_eol(file);
|
read_through_eol(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
FreeFile(file);
|
FreeFile(file);
|
||||||
free(map_file);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user