diff options
Diffstat (limited to 'src/backend/libpq')
| -rw-r--r-- | src/backend/libpq/pqcomm.c | 26 | ||||
| -rw-r--r-- | src/backend/libpq/pqformat.c | 29 |
2 files changed, 21 insertions, 34 deletions
diff --git a/src/backend/libpq/pqcomm.c b/src/backend/libpq/pqcomm.c index 5e129bc56f..1d57415860 100644 --- a/src/backend/libpq/pqcomm.c +++ b/src/backend/libpq/pqcomm.c @@ -28,7 +28,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pqcomm.c,v 1.81 1999/07/23 03:00:10 tgl Exp $ + * $Id: pqcomm.c,v 1.82 1999/08/31 04:26:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -526,38 +526,32 @@ pq_getbytes(char *s, size_t len) /* -------------------------------- * pq_getstring - get a null terminated string from connection * + * The return value is placed in an expansible StringInfo. + * Note that space allocation comes from the current memory context! + * * NOTE: this routine does not do any MULTIBYTE conversion, * even though it is presumably useful only for text, because * no code in this module should depend on MULTIBYTE mode. * See pq_getstr in pqformat.c for that. * - * FIXME: we ought to use an expansible StringInfo buffer, - * rather than dropping data if the message is too long. - * * returns 0 if OK, EOF if trouble * -------------------------------- */ int -pq_getstring(char *s, size_t len) +pq_getstring(StringInfo s) { int c; - /* - * Keep on reading until we get the terminating '\0', discarding any - * bytes we don't have room for. - */ + /* Reset string to empty */ + s->len = 0; + s->data[0] = '\0'; + /* Read until we get the terminating '\0' */ while ((c = pq_getbyte()) != EOF && c != '\0') { - if (len > 1) - { - *s++ = c; - len--; - } + appendStringInfoChar(s, c); } - *s = '\0'; - if (c == EOF) return EOF; diff --git a/src/backend/libpq/pqformat.c b/src/backend/libpq/pqformat.c index e5da571886..1cc715b92a 100644 --- a/src/backend/libpq/pqformat.c +++ b/src/backend/libpq/pqformat.c @@ -15,7 +15,7 @@ * * Copyright (c) 1994, Regents of the University of California * - * $Id: pqformat.c,v 1.7 1999/07/17 20:17:03 momjian Exp $ + * $Id: pqformat.c,v 1.8 1999/08/31 04:26:37 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -290,37 +290,30 @@ pq_getint(int *result, int b) /* -------------------------------- * pq_getstr - get a null terminated string from connection * - * FIXME: we ought to use an expansible StringInfo buffer, - * rather than dropping data if the message is too long. + * The return value is placed in an expansible StringInfo. + * Note that space allocation comes from the current memory context! * * returns 0 if OK, EOF if trouble * -------------------------------- */ int -pq_getstr(char *s, int maxlen) +pq_getstr(StringInfo s) { int c; - #ifdef MULTIBYTE char *p; - #endif - c = pq_getstring(s, maxlen); + c = pq_getstring(s); #ifdef MULTIBYTE - p = (char *) pg_client_to_server((unsigned char *) s, strlen(s)); - if (p != s) /* actual conversion has been done? */ + p = (char *) pg_client_to_server((unsigned char *) s->data, s->len); + if (p != s->data) /* actual conversion has been done? */ { - int newlen = strlen(p); - - if (newlen < maxlen) - strcpy(s, p); - else - { - strncpy(s, p, maxlen); - s[maxlen - 1] = '\0'; - } + /* reset s to empty, and append the new string p */ + s->len = 0; + s->data[0] = '\0'; + appendBinaryStringInfo(s, p, strlen(p)); } #endif |
