In the spirit of TODO item
authorBruce Momjian
Thu, 11 Nov 1999 00:10:14 +0000 (00:10 +0000)
committerBruce Momjian
Thu, 11 Nov 1999 00:10:14 +0000 (00:10 +0000)
* Add use of 'const' for varibles in source tree
(which is misspelled, btw.)
I went through the front-end libpq code and did so. This affects in
particular the various accessor functions (such as PQdb() and
PQgetvalue()) as well as, by necessity, the internal helpers they use.

I have been really thorough in that regard, perhaps some people will find
it annoying that things like
char * foo = PQgetvalue(res, 0, 0)
will generate a warning. On the other hand it _should_ generate one. This
is no real compatibility break, although a few clients will have to be
fixed to suppress warnings. (Which again would be in the spirit of the
above TODO.)

In addition I replaced some int's by size_t's and removed some warnings
(and generated some new ones -- grmpf!). Also I rewrote PQoidStatus (so it
actually honors the const!) and supplied a new function PQoidValue that
returns a proper Oid type. This is only front-end stuff, none of the
communicaton stuff was touched.

The psql patch also adds some new consts to honor the new libpq situation,
as well as fixes a fatal condition that resulted when using the -V
(--version) option and there is no database listening.

So, to summarize, the psql you should definitely put in (with or without
the libpq). If you think I went too far with the const-mania in libpq, let
me know and I'll make adjustments. If you approve it, I will also update
the docs.

        -Peter

--
Peter Eisentraut                  Sernanders vaeg 10:115

12 files changed:
src/bin/psql/command.c
src/bin/psql/describe.c
src/bin/psql/print.c
src/bin/psql/print.h
src/bin/psql/startup.c
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-exec.c
src/interfaces/libpq/fe-lobj.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-print.c
src/interfaces/libpq/libpq-fe.h
src/interfaces/libpq/libpq-int.h

index 29df2792625b09a2875325a95a2988a3bf240cd8..986ee365a527e0aea7023af715aad1af98992f3a 100644 (file)
@@ -828,7 +828,7 @@ do_connect(const char *new_dbname, const char *new_user, PsqlSettings *pset)
    PGconn     *oldconn = pset->db;
    const char *dbparam = NULL;
    const char *userparam = NULL;
-   char       *pwparam = NULL;
+   const char *pwparam = NULL;
    char       *prompted_password = NULL;
    char       *prompted_user = NULL;
    bool        need_pass;
index 58534e257513b62f67f746afd8386dd705db1e09..5e40779cd160f010eec321472ccea5540ce40287 100644 (file)
@@ -519,8 +519,8 @@ describeTableDetails(const char *name, PsqlSettings *pset)
    printTableOpt myopt = pset->popt.topt;
    bool        description = GetVariableBool(pset->vars, "description");
    int         i;
-   char       *view_def = NULL;
-   char       *headers[5];
+   const char     *view_def = NULL;
+   const char *headers[5];
    char      **cells = NULL;
    char       *title = NULL;
    char      **footers = NULL;
@@ -587,11 +587,10 @@ describeTableDetails(const char *name, PsqlSettings *pset)
    for (i = 0; i < PQntuples(res); i++)
    {
        int4        attypmod = atoi(PQgetvalue(res, i, 3));
-       char       *attype = PQgetvalue(res, i, 1);
+       const char     *attype = PQgetvalue(res, i, 1);
 
        /* Name */
-       cells[i * cols + 0] = PQgetvalue(res, i, 0);    /* don't free this
-                                                        * afterwards */
+       cells[i * cols + 0] = (char*)PQgetvalue(res, i, 0); /* don't free this afterwards */
 
        /* Type */
        cells[i * cols + 1] = xmalloc(NAMEDATALEN + 16);
@@ -609,7 +608,7 @@ describeTableDetails(const char *name, PsqlSettings *pset)
 
        /* Info */
        cells[i * cols + 2] = xmalloc(128 + 128);       /* I'm cutting off the
-                                                        * default string at 128 */
+                                    * 'default' string at 128 */
        cells[i * cols + 2][0] = '\0';
        if (strcmp(PQgetvalue(res, i, 4), "t") == 0)
            strcat(cells[i * cols + 2], "not null");
@@ -633,7 +632,7 @@ describeTableDetails(const char *name, PsqlSettings *pset)
 
        /* Description */
        if (description)
-           cells[i * cols + 3] = PQgetvalue(res, i, 7);
+           cells[i * cols + 3] = (char*)PQgetvalue(res, i, 7);
    }
 
    /* Make title */
@@ -685,7 +684,7 @@ describeTableDetails(const char *name, PsqlSettings *pset)
 
 
    myopt.tuples_only = false;
-   printTable(title, headers, cells, footers, "llll", &myopt, pset->queryFout);
+   printTable(title, headers, (const char**)cells, (const char**)footers, "llll", &myopt, pset->queryFout);
 
    /* clean up */
    free(title);
index 5c6525b6f3336ad1ea605510d377506be6e88d82..90b4f59d61221ac77f59849af0f68dba339c2195 100644 (file)
 
 
 static void
-print_unaligned_text(const char *title, char **headers, char **cells, char **footers,
+print_unaligned_text(const char *title, const char * const * headers,
+            const char * const * cells, const char * const * footers,
                     const char *opt_fieldsep, bool opt_barebones,
                     FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
-   char      **ptr;
+   const char * const * ptr;
 
    if (!opt_fieldsep)
        opt_fieldsep = "";
@@ -80,14 +81,15 @@ print_unaligned_text(const char *title, char **headers, char **cells, char **foo
 
 
 static void
-print_unaligned_vertical(const char *title, char **headers, char **cells, char **footers,
+print_unaligned_vertical(const char *title, const char * const * headers,
+            const char * const * cells, const char * const * footers,
                         const char *opt_fieldsep, bool opt_barebones,
                         FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
    unsigned int record = 1;
-   char      **ptr;
+   const char * const * ptr;
 
    if (!opt_fieldsep)
        opt_fieldsep = "";
@@ -167,8 +169,9 @@ _print_horizontal_line(const unsigned int col_count, const unsigned int *widths,
 
 
 static void
-print_aligned_text(const char *title, char **headers, char **cells, char **footers,
-const char *opt_align, bool opt_barebones, unsigned short int opt_border,
+print_aligned_text(const char *title, const char * const * headers,
+          const char * const * cells, const char * const * footers,
+          const char *opt_align, bool opt_barebones, unsigned short int opt_border,
                   FILE *fout)
 {
    unsigned int col_count = 0;
@@ -176,7 +179,7 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
                tmp;
    unsigned int *widths,
                total_w;
-   char      **ptr;
+   const char * const * ptr;
 
    /* count columns */
    for (ptr = headers; *ptr; ptr++)
@@ -308,13 +311,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
 
 
 static void
-print_aligned_vertical(const char *title, char **headers, char **cells, char **footers,
+print_aligned_vertical(const char *title, const char * const * headers,
+              const char * const * cells, const char * const * footers,
                       bool opt_barebones, unsigned short int opt_border,
                       FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int record = 1;
-   char      **ptr;
+   const char * const *ptr;
    unsigned int i,
                tmp,
                hwidth = 0,
@@ -471,14 +475,15 @@ html_escaped_print(const char *in, FILE *fout)
 
 
 static void
-print_html_text(const char *title, char **headers, char **cells, char **footers,
-const char *opt_align, bool opt_barebones, unsigned short int opt_border,
-               char *opt_table_attr,
+print_html_text(const char *title, const char * const * headers,
+       const char * const * cells, const char * const * footers,
+       const char *opt_align, bool opt_barebones, unsigned short int opt_border,
+       const char *opt_table_attr,
                FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
-   char      **ptr;
+   const char * const *ptr;
 
    fprintf(fout, "
    if (opt_table_attr)
@@ -544,15 +549,16 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
 
 
 static void
-print_html_vertical(const char *title, char **headers, char **cells, char **footers,
-const char *opt_align, bool opt_barebones, unsigned short int opt_border,
-                   char *opt_table_attr,
+print_html_vertical(const char *title, const char * const * headers,
+           const char * const * cells, const char * const * footers,
+           const char *opt_align, bool opt_barebones, unsigned short int opt_border,
+           const char *opt_table_attr,
                    FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
    unsigned int record = 1;
-   char      **ptr;
+   const char * const *ptr;
 
    fprintf(fout, "
    if (opt_table_attr)
@@ -652,14 +658,15 @@ latex_escaped_print(const char *in, FILE *fout)
 
 
 static void
-print_latex_text(const char *title, char **headers, char **cells, char **footers,
-const char *opt_align, bool opt_barebones, unsigned short int opt_border,
+print_latex_text(const char *title, const char * const * headers,
+        const char * const * cells, const char * const * footers,
+        const char *opt_align, bool opt_barebones, unsigned short int opt_border,
                 FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
    const char *cp;
-   char      **ptr;
+   const char * const *ptr;
 
 
    /* print title */
@@ -747,13 +754,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
 
 
 static void
-print_latex_vertical(const char *title, char **headers, char **cells, char **footers,
-const char *opt_align, bool opt_barebones, unsigned short int opt_border,
+print_latex_vertical(const char *title, const char * const * headers,
+            const char * const * cells, const char * const * footers,
+            const char *opt_align, bool opt_barebones, unsigned short int opt_border,
                     FILE *fout)
 {
    unsigned int col_count = 0;
    unsigned int i;
-   char      **ptr;
+   const char * const *ptr;
    unsigned int record = 1;
 
    (void) opt_align;           /* currently unused parameter */
@@ -833,11 +841,14 @@ const char *opt_align, bool opt_barebones, unsigned short int opt_border,
 
 
 void
-printTable(const char *title, char **headers, char **cells, char **footers,
+printTable(const char *title,
+      const char * const * headers,
+      const char * const * cells,
+      const char * const * footers,
           const char *align,
           const printTableOpt * opt, FILE *fout)
 {
-   char       *default_footer[] = {NULL};
+   const char *default_footer[] = {NULL};
    unsigned short int border = opt->border;
    FILE       *pager = NULL,
               *output;
@@ -868,7 +879,7 @@ printTable(const char *title, char **headers, char **cells, char **footers,
        unsigned int col_count = 0,
                    row_count = 0,
                    lines;
-       char      **ptr;
+       const char * const *ptr;
        int         result;
        struct winsize screen_size;
 
@@ -952,11 +963,11 @@ printTable(const char *title, char **headers, char **cells, char **footers,
 
 
 void
-printQuery(PGresult *result, const printQueryOpt * opt, FILE *fout)
+printQuery(const PGresult *result, const printQueryOpt * opt, FILE *fout)
 {
    int         nfields;
-   char      **headers;
-   char      **cells;
+   const char **headers;
+   const char **cells;
    char      **footers;
    char       *align;
    int         i;
@@ -1043,8 +1054,9 @@ printQuery(PGresult *result, const printQueryOpt * opt, FILE *fout)
 
    /* call table printer */
 
-   printTable(opt->title, headers, cells, footers ? footers : opt->footers, align,
-              &opt->topt, fout);
+   printTable(opt->title, headers, cells,
+          footers ? (const char * const *)footers : (const char * const *)(opt->footers),
+          align, &opt->topt, fout);
 
    free(headers);
    free(cells);
index 64d0271f505e6eb6febaff32cd3000c4927e5579..5b1c7671b11385a98633db84aea5322de463f6a9 100644 (file)
@@ -44,7 +44,8 @@ typedef struct _printTableOpt
  * - align is an 'l' or an 'r' for every column, if the output format needs it.
  *  (You must specify this long enough. Otherwise anything could happen.)
 */
-void printTable(const char *title, char **headers, char **cells, char **footers,
+void printTable(const char *title, const char * const * headers,
+       const char * const * cells, const char * const * footers,
           const char *align,
           const printTableOpt * opt, FILE *fout);
 
@@ -66,7 +67,7 @@ typedef struct _printQueryOpt
  * It calls the printTable above with all the things set straight.
  */
 void
-           printQuery(PGresult *result, const printQueryOpt * opt, FILE *fout);
+printQuery(const PGresult *result, const printQueryOpt * opt, FILE *fout);
 
 
 #endif  /* PRINT_H */
index c94f2526b336d54cdd0e6ad97be48e98c494b886..1a1688f081e6b1a9d5e80ad991b89377d044ff91 100644 (file)
 
 
 static void
-           process_psqlrc(PsqlSettings *pset);
+process_psqlrc(PsqlSettings *pset);
 
 static void
-           showVersion(PsqlSettings *pset, bool verbose);
+showVersion(PsqlSettings *pset);
 
 
 /* Structures to pass information between the option parsing routine
@@ -68,7 +68,7 @@ struct adhoc_opts
 };
 
 static void
-           parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * options);
+parse_options(int argc, char *argv[], PsqlSettings *pset, struct adhoc_opts * options);
 
 
 
@@ -152,7 +152,7 @@ main(int argc, char **argv)
    free(username);
    free(password);
 
-   if (PQstatus(settings.db) == CONNECTION_BAD)
+   if (PQstatus(settings.db) == CONNECTION_BAD && options.action != ACT_SHOW_VER)
    {
        fprintf(stderr, "Connection to database '%s' failed.\n%s\n", PQdb(settings.db), PQerrorMessage(settings.db));
        PQfinish(settings.db);
@@ -169,7 +169,7 @@ main(int argc, char **argv)
 
    if (options.action == ACT_SHOW_VER)
    {
-       showVersion(&settings, true);
+       showVersion(&settings);
        PQfinish(settings.db);
        exit(EXIT_SUCCESS);
    }
@@ -177,11 +177,8 @@ main(int argc, char **argv)
 
    if (!GetVariable(settings.vars, "quiet") && !settings.notty && !options.action)
    {
-       puts("Welcome to psql, the PostgreSQL interactive terminal.\n");
-
-       //showVersion(&settings, false);
-
-       puts("Type:  \\copyright for distribution terms\n"
+       puts("Welcome to psql, the PostgreSQL interactive terminal.\n\n"
+            "Type:  \\copyright for distribution terms\n"
             "       \\h for help with SQL commands\n"
             "       \\? for help on internal slash commands\n"
             "       \\g or terminate with semicolon to execute query\n"
@@ -509,28 +506,22 @@ process_psqlrc(PsqlSettings *pset)
  * or a mismatch was detected.
  */
 static void
-showVersion(PsqlSettings *pset, bool verbose)
+showVersion(PsqlSettings *pset)
 {
-   PGresult   *res;
-   char       *versionstr = NULL;
+   PGresult   *res = NULL;
+   const char *versionstr = NULL;
    long int    release = 0,
                version = 0,
                subversion = 0;
 
    /* get backend version */
+   if (pset->db && PQstatus(pset->db) == CONNECTION_OK) {
    res = PSQLexec(pset, "SELECT version()");
    if (PQresultStatus(res) == PGRES_TUPLES_OK)
        versionstr = PQgetvalue(res, 0, 0);
-
-   if (!verbose)
-   {
-       if (versionstr)
-           puts(versionstr);
-       PQclear(res);
-       return;
    }
 
-   if (strncmp(versionstr, "PostgreSQL ", 11) == 0)
+   if (versionstr && strncmp(versionstr, "PostgreSQL ", 11) == 0)
    {
        char       *tmp;
 
@@ -539,9 +530,9 @@ showVersion(PsqlSettings *pset, bool verbose)
        subversion = strtol(tmp + 1, &tmp, 10);
    }
 
-   printf("Server: %s\npsql", versionstr ? versionstr : "(could not connected)");
+   printf("Server: %s\npsql", versionstr ? versionstr : "(could not connect)");
 
-   if (strcmp(versionstr, PG_VERSION_STR) != 0)
+   if (!versionstr || strcmp(versionstr, PG_VERSION_STR) != 0)
        printf(&PG_VERSION_STR[strcspn(PG_VERSION_STR, " ")]);
    printf(" (" __DATE__ " " __TIME__ ")");
 
@@ -569,10 +560,11 @@ showVersion(PsqlSettings *pset, bool verbose)
 
    puts("");
 
-   if (release < 6 || (release == 6 && version < 5))
+   if (versionstr && (release < 6 || (release == 6 && version < 5)))
        puts("\nWarning: The server you are connected to is potentially too old for this client\n"
             "version. You should ideally be using clients and servers from the same\n"
             "distribution.");
 
+   if (res)
    PQclear(res);
 }
index 5057beaa4da7d4997a0f367a4f4551308e0bcc48..7e2fb4437975807ccfbc8a5d8321c75a613d1b77 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.105 1999/11/05 06:43:45 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.106 1999/11/11 00:10:13 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -141,7 +141,7 @@ static struct EnvironmentOptions
        "PGGEQO", "geqo"
    },
    {
-       NULL
+       NULL, NULL
    }
 };
 
@@ -1453,56 +1453,56 @@ conninfo_free()
 }
 
 /* =========== accessor functions for PGconn ========= */
-char *
-PQdb(PGconn *conn)
+const char *
+PQdb(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->dbName;
 }
 
-char *
-PQuser(PGconn *conn)
+const char *
+PQuser(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->pguser;
 }
 
-char *
-PQpass(PGconn *conn)
+const char *
+PQpass(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->pgpass;
 }
 
-char *
-PQhost(PGconn *conn)
+const char *
+PQhost(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->pghost;
 }
 
-char *
-PQport(PGconn *conn)
+const char *
+PQport(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->pgport;
 }
 
-char *
-PQtty(PGconn *conn)
+const char *
+PQtty(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
    return conn->pgtty;
 }
 
-char *
-PQoptions(PGconn *conn)
+const char *
+PQoptions(const PGconn *conn)
 {
    if (!conn)
        return (char *) NULL;
@@ -1510,15 +1510,15 @@ PQoptions(PGconn *conn)
 }
 
 ConnStatusType
-PQstatus(PGconn *conn)
+PQstatus(const PGconn *conn)
 {
    if (!conn)
        return CONNECTION_BAD;
    return conn->status;
 }
 
-char *
-PQerrorMessage(PGconn *conn)
+const char *
+PQerrorMessage(const PGconn *conn)
 {
    static char noConn[] = "PQerrorMessage: conn pointer is NULL\n";
 
@@ -1528,7 +1528,7 @@ PQerrorMessage(PGconn *conn)
 }
 
 int
-PQsocket(PGconn *conn)
+PQsocket(const PGconn *conn)
 {
    if (!conn)
        return -1;
@@ -1536,7 +1536,7 @@ PQsocket(PGconn *conn)
 }
 
 int
-PQbackendPID(PGconn *conn)
+PQbackendPID(const PGconn *conn)
 {
    if (!conn || conn->status != CONNECTION_OK)
        return 0;
index 24fe9860ebbd65df2fe0b2523d4f491862f216c8..e6fb7e9ee7f8f201f2951372e0887600765b9be7 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.85 1999/08/31 01:37:36 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.86 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -179,7 +179,7 @@ PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status)
  * be allocated on any byte boundary.
  */
 void *
-pqResultAlloc(PGresult *res, int nBytes, int isBinary)
+pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary)
 {
    char       *space;
    PGresult_data *block;
@@ -882,7 +882,7 @@ getAnotherTuple(PGconn *conn, int binary)
    char        std_bitmap[64]; /* used unless it doesn't fit */
    char       *bitmap = std_bitmap;
    int         i;
-   int         nbytes;         /* the number of bytes in bitmap  */
+   size_t      nbytes;         /* the number of bytes in bitmap  */
    char        bmap;           /* One byte of the bitmap */
    int         bitmap_index;   /* Its index */
    int         bitcnt;         /* number of bits examined in current byte */
@@ -1495,7 +1495,7 @@ PQfn(PGconn *conn,
     int *result_buf,
     int *actual_result_len,
     int result_is_int,
-    PQArgBlock *args,
+    const PQArgBlock *args,
     int nargs)
 {
    bool        needInput = false;
@@ -1674,7 +1674,7 @@ PQfn(PGconn *conn,
 /* ====== accessor funcs for PGresult ======== */
 
 ExecStatusType
-PQresultStatus(PGresult *res)
+PQresultStatus(const PGresult *res)
 {
    if (!res)
        return PGRES_NONFATAL_ERROR;
@@ -1684,14 +1684,13 @@ PQresultStatus(PGresult *res)
 const char *
 PQresStatus(ExecStatusType status)
 {
-   if (((int) status) < 0 ||
-       ((int) status) >= (sizeof(pgresStatus) / sizeof(pgresStatus[0])))
+   if ((int)status < 0 || (size_t)status >= sizeof pgresStatus / sizeof pgresStatus[0])
        return "Invalid ExecStatusType code";
    return pgresStatus[status];
 }
 
 const char *
-PQresultErrorMessage(PGresult *res)
+PQresultErrorMessage(const PGresult *res)
 {
    if (!res || !res->errMsg)
        return "";
@@ -1699,7 +1698,7 @@ PQresultErrorMessage(PGresult *res)
 }
 
 int
-PQntuples(PGresult *res)
+PQntuples(const PGresult *res)
 {
    if (!res)
        return 0;
@@ -1707,7 +1706,7 @@ PQntuples(PGresult *res)
 }
 
 int
-PQnfields(PGresult *res)
+PQnfields(const PGresult *res)
 {
    if (!res)
        return 0;
@@ -1715,7 +1714,7 @@ PQnfields(PGresult *res)
 }
 
 int
-PQbinaryTuples(PGresult *res)
+PQbinaryTuples(const PGresult *res)
 {
    if (!res)
        return 0;
@@ -1728,7 +1727,7 @@ PQbinaryTuples(PGresult *res)
  */
 
 static int
-check_field_number(const char *routineName, PGresult *res, int field_num)
+check_field_number(const char *routineName, const PGresult *res, int field_num)
 {
    char noticeBuf[128];
 
@@ -1749,7 +1748,7 @@ check_field_number(const char *routineName, PGresult *res, int field_num)
 }
 
 static int
-check_tuple_field_number(const char *routineName, PGresult *res,
+check_tuple_field_number(const char *routineName, const PGresult *res,
                         int tup_num, int field_num)
 {
    char noticeBuf[128];
@@ -1784,8 +1783,8 @@ check_tuple_field_number(const char *routineName, PGresult *res,
 /*
    returns NULL if the field_num is invalid
 */
-char *
-PQfname(PGresult *res, int field_num)
+const char *
+PQfname(const PGresult *res, int field_num)
 {
    if (!check_field_number("PQfname", res, field_num))
        return NULL;
@@ -1799,7 +1798,7 @@ PQfname(PGresult *res, int field_num)
    returns -1 on a bad field name
 */
 int
-PQfnumber(PGresult *res, const char *field_name)
+PQfnumber(const PGresult *res, const char *field_name)
 {
    int         i;
    char       *field_case;
@@ -1837,7 +1836,7 @@ PQfnumber(PGresult *res, const char *field_name)
 }
 
 Oid
-PQftype(PGresult *res, int field_num)
+PQftype(const PGresult *res, int field_num)
 {
    if (!check_field_number("PQftype", res, field_num))
        return InvalidOid;
@@ -1848,7 +1847,7 @@ PQftype(PGresult *res, int field_num)
 }
 
 int
-PQfsize(PGresult *res, int field_num)
+PQfsize(const PGresult *res, int field_num)
 {
    if (!check_field_number("PQfsize", res, field_num))
        return 0;
@@ -1859,7 +1858,7 @@ PQfsize(PGresult *res, int field_num)
 }
 
 int
-PQfmod(PGresult *res, int field_num)
+PQfmod(const PGresult *res, int field_num)
 {
    if (!check_field_number("PQfmod", res, field_num))
        return 0;
@@ -1869,8 +1868,8 @@ PQfmod(PGresult *res, int field_num)
        return 0;
 }
 
-char *
-PQcmdStatus(PGresult *res)
+const char *
+PQcmdStatus(const PGresult *res)
 {
    if (!res)
        return NULL;
@@ -1883,47 +1882,49 @@ PQcmdStatus(PGresult *res)
    if not, return ""
 */
 const char *
-PQoidStatus(PGresult *res)
+PQoidStatus(const PGresult *res)
 {
-   char       *p,
-              *e,
-              *scan;
-   int         slen,
-               olen;
+        /* 
+         * This must be enough to hold the result. Don't laugh, this is
+         * better than what this function used to do.
+         */
+        static char buf[24];
 
-   if (!res)
-       return "";
+   size_t len;
 
-   if (strncmp(res->cmdStatus, "INSERT ", 7) != 0)
+   if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
        return "";
 
-   /*----------
-    * The cmdStatus string looks like
-    *     INSERT oid count\0
-    * In order to be able to return an ordinary C string without
-    * damaging the result for PQcmdStatus or PQcmdTuples, we copy
-    * the oid part of the string to just after the null, so that
-    * cmdStatus looks like
-    *     INSERT oid count\0oid\0
-    *                       ^ our return value points here
-    * Pretty klugy eh?  This routine should've just returned an Oid value.
-    *----------
-    */
+   len = strspn(res->cmdStatus + 7, "0123456789");
+   if (len > 23)
+           len = 23;
+   strncpy(buf, res->cmdStatus + 7, len);
+   buf[23] = '\0';
 
-   slen = strlen(res->cmdStatus);
-   p = res->cmdStatus + 7;     /* where oid is now */
-   e = res->cmdStatus + slen + 1;      /* where to put the oid string */
+   return buf;
+}
 
-   for (scan = p; *scan && *scan != ' ';)
-       scan++;
-   olen = scan - p;
-   if (slen + olen + 2 > sizeof(res->cmdStatus))
-       return "";              /* something very wrong if it doesn't fit */
+/*
+  PQoidValue -
+        a perhaps preferable form of the above which just returns
+   an Oid type
+*/
+Oid
+PQoidValue(const PGresult *res)
+{
+    char * endptr = NULL;
+    long int result;
 
-   strncpy(e, p, olen);
-   e[olen] = '\0';
+    if (!res || !res->cmdStatus || strncmp(res->cmdStatus, "INSERT ", 7) != 0)
+   return InvalidOid;
 
-   return e;
+    errno = 0;
+    result = strtoul(res->cmdStatus + 7, &endptr, 10);
+
+    if (!endptr || (*endptr != ' ' && *endptr != '\0') || errno == ERANGE)
+   return InvalidOid;
+    else
+   return (Oid)result;
 }
 
 /*
@@ -1932,7 +1933,7 @@ PQoidStatus(PGresult *res)
    of inserted/affected tuples, if not, return ""
 */
 const char *
-PQcmdTuples(PGresult *res)
+PQcmdTuples(const PGresult *res)
 {
    char noticeBuf[128];
 
@@ -1943,7 +1944,7 @@ PQcmdTuples(PGresult *res)
        strncmp(res->cmdStatus, "DELETE", 6) == 0 ||
        strncmp(res->cmdStatus, "UPDATE", 6) == 0)
    {
-       char       *p = res->cmdStatus + 6;
+       const char     *p = res->cmdStatus + 6;
 
        if (*p == 0)
        {
@@ -1987,8 +1988,8 @@ PQcmdTuples(PGresult *res)
 
    if res is not binary, a null-terminated ASCII string is returned.
 */
-char *
-PQgetvalue(PGresult *res, int tup_num, int field_num)
+const char *
+PQgetvalue(const PGresult *res, int tup_num, int field_num)
 {
    if (!check_tuple_field_number("PQgetvalue", res, tup_num, field_num))
        return NULL;
@@ -2002,7 +2003,7 @@ PQgetvalue(PGresult *res, int tup_num, int field_num)
     by PQgetvalue doesn't either.)
 */
 int
-PQgetlength(PGresult *res, int tup_num, int field_num)
+PQgetlength(const PGresult *res, int tup_num, int field_num)
 {
    if (!check_tuple_field_number("PQgetlength", res, tup_num, field_num))
        return 0;
@@ -2016,7 +2017,7 @@ PQgetlength(PGresult *res, int tup_num, int field_num)
     returns the null status of a field value.
 */
 int
-PQgetisnull(PGresult *res, int tup_num, int field_num)
+PQgetisnull(const PGresult *res, int tup_num, int field_num)
 {
    if (!check_tuple_field_number("PQgetisnull", res, tup_num, field_num))
        return 1;               /* pretend it is null */
index 8793e24cf897bac7148c6cb50acacf5a8e219fb3..b443b3e531c3a2898809e458f64620a656057bc7 100644 (file)
@@ -7,7 +7,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.25 1999/08/31 01:37:36 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.26 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -127,7 +127,7 @@ lo_close(PGconn *conn, int fd)
  */
 
 int
-lo_read(PGconn *conn, int fd, char *buf, int len)
+lo_read(PGconn *conn, int fd, char *buf, size_t len)
 {
    PQArgBlock  argv[2];
    PGresult   *res;
@@ -167,7 +167,7 @@ lo_read(PGconn *conn, int fd, char *buf, int len)
  *
  */
 int
-lo_write(PGconn *conn, int fd, char *buf, int len)
+lo_write(PGconn *conn, int fd, const char *buf, size_t len)
 {
    PQArgBlock  argv[2];
    PGresult   *res;
@@ -378,7 +378,7 @@ lo_unlink(PGconn *conn, Oid lobjId)
  */
 
 Oid
-lo_import(PGconn *conn, char *filename)
+lo_import(PGconn *conn, const char *filename)
 {
    int         fd;
    int         nbytes,
@@ -451,7 +451,7 @@ lo_import(PGconn *conn, char *filename)
  * returns -1 upon failure, 1 otherwise
  */
 int
-lo_export(PGconn *conn, Oid lobjId, char *filename)
+lo_export(PGconn *conn, Oid lobjId, const char *filename)
 {
    int         fd;
    int         nbytes,
@@ -522,7 +522,7 @@ lo_initialize(PGconn *conn)
    PGresult   *res;
    PGlobjfuncs *lobjfuncs;
    int         n;
-   char       *fname;
+   const char     *fname;
    Oid         foid;
 
    /* ----------------
index 9c87a9301865e23eb72029cce6991196048a1ea9..d29277bf2004276bfaab4b9515848d347b81ed00 100644 (file)
@@ -24,7 +24,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.31 1999/09/27 03:13:16 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.32 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -82,9 +82,9 @@ pqGetc(char *result, PGconn *conn)
    with buffering
  */
 static int
-pqPutBytes(const char *s, int nbytes, PGconn *conn)
+pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
 {
-   int         avail = conn->outBufSize - conn->outCount;
+   size_t avail = Max(conn->outBufSize - conn->outCount, 0);
 
    while (nbytes > avail)
    {
@@ -157,7 +157,7 @@ pqPuts(const char *s, PGconn *conn)
    get a string of exactly len bytes in buffer s, no null termination
 */
 int
-pqGetnchar(char *s, int len, PGconn *conn)
+pqGetnchar(char *s, size_t len, PGconn *conn)
 {
    if (len < 0 || len > conn->inEnd - conn->inCursor)
        return EOF;
@@ -168,7 +168,7 @@ pqGetnchar(char *s, int len, PGconn *conn)
    conn->inCursor += len;
 
    if (conn->Pfdebug)
-       fprintf(conn->Pfdebug, "From backend (%d)> %.*s\n", len, len, s);
+       fprintf(conn->Pfdebug, "From backend (%d)> %.*s\n", len, (int)len, s);
 
    return 0;
 }
@@ -178,13 +178,13 @@ pqGetnchar(char *s, int len, PGconn *conn)
    send a string of exactly len bytes, no null termination needed
 */
 int
-pqPutnchar(const char *s, int len, PGconn *conn)
+pqPutnchar(const char *s, size_t len, PGconn *conn)
 {
    if (pqPutBytes(s, len, conn))
        return EOF;
 
    if (conn->Pfdebug)
-       fprintf(conn->Pfdebug, "To backend> %.*s\n", len, s);
+       fprintf(conn->Pfdebug, "To backend> %.*s\n", (int)len, s);
 
    return 0;
 }
@@ -195,7 +195,7 @@ pqPutnchar(const char *s, int len, PGconn *conn)
    to local byte order
 */
 int
-pqGetInt(int *result, int bytes, PGconn *conn)
+pqGetInt(int *result, size_t bytes, PGconn *conn)
 {
    uint16      tmp2;
    uint32      tmp4;
@@ -236,7 +236,7 @@ pqGetInt(int *result, int bytes, PGconn *conn)
    to network byte order.
 */
 int
-pqPutInt(int value, int bytes, PGconn *conn)
+pqPutInt(int value, size_t bytes, PGconn *conn)
 {
    uint16      tmp2;
    uint32      tmp4;
index 02f3455dcbcbe947f4071acc4410083dd096002e..522e1c57006eb3fc8517e4db8880fa703ece057d 100644 (file)
@@ -9,7 +9,7 @@
  * didn't really belong there.
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.27 1999/08/31 01:37:37 tgl Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.28 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -50,16 +50,16 @@ static struct winsize
 #endif
 
 
-static void do_field(PQprintOpt *po, PGresult *res,
+static void do_field(const PQprintOpt *po, const PGresult *res,
         const int i, const int j, const int fs_len,
         char **fields,
-        const int nFields, char **fieldNames,
+        const int nFields, const char **fieldNames,
         unsigned char *fieldNotNum, int *fieldMax,
         const int fieldMaxLen, FILE *fout);
-static char *do_header(FILE *fout, PQprintOpt *po, const int nFields,
-         int *fieldMax, char **fieldNames, unsigned char *fieldNotNum,
-         const int fs_len, PGresult *res);
-static void output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
+static char *do_header(FILE *fout, const PQprintOpt *po, const int nFields,
+         int *fieldMax, const char **fieldNames, unsigned char *fieldNotNum,
+         const int fs_len, const PGresult *res);
+static void output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
           unsigned char *fieldNotNum, int *fieldMax, char *border,
           const int row_index);
 static void fill(int length, int max, char filler, FILE *fp);
@@ -79,8 +79,8 @@ static void fill(int length, int max, char filler, FILE *fp);
 
 void
 PQprint(FILE *fout,
-       PGresult *res,
-       PQprintOpt *po)
+   const PGresult *res,
+   const PQprintOpt *po)
 {
    int         nFields;
 
@@ -95,7 +95,7 @@ PQprint(FILE *fout,
        unsigned char *fieldNotNum = NULL;
        char       *border = NULL;
        char      **fields = NULL;
-       char      **fieldNames;
+       const char    **fieldNames;
        int         fieldMaxLen = 0;
        int         numFieldName;
        int         fs_len = strlen(po->fieldSep);
@@ -105,7 +105,7 @@ PQprint(FILE *fout,
        char       *pagerenv;
 
        nTups = PQntuples(res);
-       if (!(fieldNames = (char **) calloc(nFields, sizeof(char *))))
+       if (!(fieldNames = (const char **) calloc(nFields, sizeof(char *))))
        {
            perror("calloc");
            exit(1);
@@ -127,7 +127,7 @@ PQprint(FILE *fout,
        for (j = 0; j < nFields; j++)
        {
            int         len;
-           char       *s = (j < numFieldName && po->fieldName[j][0]) ?
+           const char     *s = (j < numFieldName && po->fieldName[j][0]) ?
            po->fieldName[j] : PQfname(res, j);
 
            fieldNames[j] = s;
@@ -218,7 +218,7 @@ PQprint(FILE *fout,
 
                for (j = 0; j < nFields; j++)
                {
-                   char       *s = fieldNames[j];
+                   const char     *s = fieldNames[j];
 
                    fputs(s, fout);
                    len += strlen(s) + fs_len;
@@ -317,12 +317,12 @@ PQprint(FILE *fout,
  */
 
 void
-PQdisplayTuples(PGresult *res,
-               FILE *fp,       /* where to send the output */
-               int fillAlign,  /* pad the fields with spaces */
-               const char *fieldSep,   /* field separator */
-               int printHeader,/* display headers? */
-               int quiet
+PQdisplayTuples(const PGresult *res,
+       FILE *fp,       /* where to send the output */
+       int fillAlign,  /* pad the fields with spaces */
+       const char *fieldSep,   /* field separator */
+       int printHeader,/* display headers? */
+       int quiet
 )
 {
 #define DEFAULT_FIELD_SEP " "
@@ -414,12 +414,12 @@ PQdisplayTuples(PGresult *res,
  *
  */
 void
-PQprintTuples(PGresult *res,
-             FILE *fout,       /* output stream */
-             int PrintAttNames,/* print attribute names or not */
-             int TerseOutput,  /* delimiter bars or not? */
-             int colWidth      /* width of column, if 0, use variable
-                                * width */
+PQprintTuples(const PGresult *res,
+         FILE *fout,       /* output stream */
+         int PrintAttNames,/* print attribute names or not */
+         int TerseOutput,  /* delimiter bars or not? */
+         int colWidth      /* width of column, if 0, use variable
+                    * width */
 )
 {
    int         nFields;
@@ -475,7 +475,7 @@ PQprintTuples(PGresult *res,
        {
            for (j = 0; j < nFields; j++)
            {
-               char       *pval = PQgetvalue(res, i, j);
+               const char     *pval = PQgetvalue(res, i, j);
 
                fprintf(fout, formatString,
                        TerseOutput ? "" : "|",
@@ -498,7 +498,7 @@ PQprintTuples(PGresult *res,
  * the backend is assumed.
  */
 int
-PQmblen(unsigned char *s)
+PQmblen(const unsigned char *s)
 {
    char       *str;
    int         encoding = -1;
@@ -515,7 +515,7 @@ PQmblen(unsigned char *s)
 
 /* Provide a default definition in case someone calls it anyway */
 int
-PQmblen(unsigned char *s)
+PQmblen(const unsigned char *s)
 {
    return 1;
 }
@@ -523,15 +523,15 @@ PQmblen(unsigned char *s)
 #endif  /* MULTIBYTE */
 
 static void
-do_field(PQprintOpt *po, PGresult *res,
+do_field(const PQprintOpt *po, const PGresult *res,
         const int i, const int j, const int fs_len,
         char **fields,
-        const int nFields, char **fieldNames,
+        const int nFields, char const **fieldNames,
         unsigned char *fieldNotNum, int *fieldMax,
         const int fieldMaxLen, FILE *fout)
 {
 
-   char       *pval,
+   const char     *pval,
               *p;
    int         plen;
    bool        skipit;
@@ -641,9 +641,9 @@ do_field(PQprintOpt *po, PGresult *res,
 
 
 static char *
-do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
-         char **fieldNames, unsigned char *fieldNotNum,
-         const int fs_len, PGresult *res)
+do_header(FILE *fout, const PQprintOpt *po, const int nFields, int *fieldMax,
+         const char **fieldNames, unsigned char *fieldNotNum,
+         const int fs_len, const PGresult *res)
 {
 
    int         j;              /* for loop index */
@@ -697,7 +697,7 @@ do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
        fputs(po->fieldSep, fout);
    for (j = 0; j < nFields; j++)
    {
-       char       *s = PQfname(res, j);
+       const char     *s = PQfname(res, j);
 
        if (po->html3)
        {
@@ -729,7 +729,7 @@ do_header(FILE *fout, PQprintOpt *po, const int nFields, int *fieldMax,
 
 
 static void
-output_row(FILE *fout, PQprintOpt *po, const int nFields, char **fields,
+output_row(FILE *fout, const PQprintOpt *po, const int nFields, char **fields,
           unsigned char *fieldNotNum, int *fieldMax, char *border,
           const int row_index)
 {
index 9b4cf2894b619eedb834c3b859d5bb17b7214ad7..b1c97e046a60ec93439798182fd063bd3a4279d0 100644 (file)
@@ -6,7 +6,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-fe.h,v 1.51 1999/10/26 04:49:00 momjian Exp $
+ * $Id: libpq-fe.h,v 1.52 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -176,17 +176,17 @@ extern        "C"
    extern int  PQrequestCancel(PGconn *conn);
 
    /* Accessor functions for PGconn objects */
-   extern char *PQdb(PGconn *conn);
-   extern char *PQuser(PGconn *conn);
-   extern char *PQpass(PGconn *conn);
-   extern char *PQhost(PGconn *conn);
-   extern char *PQport(PGconn *conn);
-   extern char *PQtty(PGconn *conn);
-   extern char *PQoptions(PGconn *conn);
-   extern ConnStatusType PQstatus(PGconn *conn);
-   extern char *PQerrorMessage(PGconn *conn);
-   extern int  PQsocket(PGconn *conn);
-   extern int  PQbackendPID(PGconn *conn);
+   extern const char *PQdb(const PGconn *conn);
+   extern const char *PQuser(const PGconn *conn);
+   extern const char *PQpass(const PGconn *conn);
+   extern const char *PQhost(const PGconn *conn);
+   extern const char *PQport(const PGconn *conn);
+   extern const char *PQtty(const PGconn *conn);
+   extern const char *PQoptions(const PGconn *conn);
+   extern ConnStatusType PQstatus(const PGconn *conn);
+   extern const char *PQerrorMessage(const PGconn *conn);
+   extern int  PQsocket(const PGconn *conn);
+   extern int  PQbackendPID(const PGconn *conn);
 
    /* Enable/disable tracing */
    extern void PQtrace(PGconn *conn, FILE *debug_port);
@@ -221,31 +221,32 @@ extern        "C"
     * use
     */
    extern PGresult *PQfn(PGconn *conn,
-                                     int fnid,
-                                     int *result_buf,
-                                     int *result_len,
-                                     int result_is_int,
-                                     PQArgBlock *args,
-                                     int nargs);
+                 int fnid,
+                 int *result_buf,
+                 int *result_len,
+                 int result_is_int,
+                 const PQArgBlock *args,
+                 int nargs);
 
    /* Accessor functions for PGresult objects */
-   extern ExecStatusType PQresultStatus(PGresult *res);
+   extern ExecStatusType PQresultStatus(const PGresult *res);
    extern const char *PQresStatus(ExecStatusType status);
-   extern const char *PQresultErrorMessage(PGresult *res);
-   extern int  PQntuples(PGresult *res);
-   extern int  PQnfields(PGresult *res);
-   extern int  PQbinaryTuples(PGresult *res);
-   extern char *PQfname(PGresult *res, int field_num);
-   extern int  PQfnumber(PGresult *res, const char *field_name);
-   extern Oid  PQftype(PGresult *res, int field_num);
-   extern int  PQfsize(PGresult *res, int field_num);
-   extern int  PQfmod(PGresult *res, int field_num);
-   extern char *PQcmdStatus(PGresult *res);
-   extern const char *PQoidStatus(PGresult *res);
-   extern const char *PQcmdTuples(PGresult *res);
-   extern char *PQgetvalue(PGresult *res, int tup_num, int field_num);
-   extern int  PQgetlength(PGresult *res, int tup_num, int field_num);
-   extern int  PQgetisnull(PGresult *res, int tup_num, int field_num);
+   extern const char *PQresultErrorMessage(const PGresult *res);
+   extern int  PQntuples(const PGresult *res);
+   extern int  PQnfields(const PGresult *res);
+   extern int  PQbinaryTuples(const PGresult *res);
+   extern const char *PQfname(const PGresult *res, int field_num);
+   extern int  PQfnumber(const PGresult *res, const char *field_name);
+   extern Oid  PQftype(const PGresult *res, int field_num);
+   extern int  PQfsize(const PGresult *res, int field_num);
+   extern int  PQfmod(const PGresult *res, int field_num);
+   extern const char *PQcmdStatus(const PGresult *res);
+        extern const char *PQoidStatus(const PGresult *res); /* old and ugly */
+        extern Oid PQoidValue(const PGresult *res); /* new and improved */
+   extern const char *PQcmdTuples(const PGresult *res);
+   extern const char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
+   extern int  PQgetlength(const PGresult *res, int tup_num, int field_num);
+   extern int  PQgetisnull(const PGresult *res, int tup_num, int field_num);
 
    /* Delete a PGresult */
    extern void PQclear(PGresult *res);
@@ -260,47 +261,47 @@ extern        "C"
 /* === in fe-print.c === */
 
    extern void PQprint(FILE *fout,     /* output stream */
-                                   PGresult *res,
-                                   PQprintOpt *ps);    /* option structure */
+               const PGresult *res,
+               const PQprintOpt *ps);  /* option structure */
 
    /*
     * PQdisplayTuples() is a better version of PQprintTuples(), but both
     * are obsoleted by PQprint().
     */
-   extern void PQdisplayTuples(PGresult *res,
-                                           FILE *fp,   /* where to send the
-                                                        * output */
-                                           int fillAlign,      /* pad the fields with
-                                                                * spaces */
-                                           const char *fieldSep,       /* field separator */
-                                           int printHeader,    /* display headers? */
-                                           int quiet);
-
-   extern void PQprintTuples(PGresult *res,
-                                         FILE *fout,   /* output stream */
-                                         int printAttName,     /* print attribute names
-                                                                * or not */
-                                         int terseOutput,      /* delimiter bars or
-                                                                * not? */
-                                         int width);   /* width of column, if
-                                                        * 0, use variable width */
+   extern void PQdisplayTuples(const PGresult *res,
+                   FILE *fp,   /* where to send the
+                        * output */
+                   int fillAlign,      /* pad the fields with
+                                * spaces */
+                   const char *fieldSep,       /* field separator */
+                   int printHeader,    /* display headers? */
+                   int quiet);
+
+   extern void PQprintTuples(const PGresult *res,
+                 FILE *fout,   /* output stream */
+                 int printAttName,     /* print attribute names
+                                * or not */
+                 int terseOutput,      /* delimiter bars or
+                                * not? */
+                 int width);   /* width of column, if
+                        * 0, use variable width */
 
    /* Determine length of multibyte encoded char at *s */
-   extern int  PQmblen(unsigned char *s);
+   extern int  PQmblen(const unsigned char *s);
 
 /* === in fe-lobj.c === */
 
    /* Large-object access routines */
    extern int  lo_open(PGconn *conn, Oid lobjId, int mode);
    extern int  lo_close(PGconn *conn, int fd);
-   extern int  lo_read(PGconn *conn, int fd, char *buf, int len);
-   extern int  lo_write(PGconn *conn, int fd, char *buf, int len);
+   extern int  lo_read(PGconn *conn, int fd, char *buf, size_t len);
+   extern int  lo_write(PGconn *conn, int fd, const char *buf, size_t len);
    extern int  lo_lseek(PGconn *conn, int fd, int offset, int whence);
    extern Oid  lo_creat(PGconn *conn, int mode);
    extern int  lo_tell(PGconn *conn, int fd);
    extern int  lo_unlink(PGconn *conn, Oid lobjId);
-   extern Oid  lo_import(PGconn *conn, char *filename);
-   extern int  lo_export(PGconn *conn, Oid lobjId, char *filename);
+   extern Oid  lo_import(PGconn *conn, const char *filename);
+   extern int  lo_export(PGconn *conn, Oid lobjId, const char *filename);
 
 #ifdef __cplusplus
 };
index 2b3db3fe7fd3d8eaa7a44308efb4a9c59e475aac..7323e9fe065db71d8f429b29c0706bbfdc444a78 100644 (file)
@@ -11,7 +11,7 @@
  *
  * Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-int.h,v 1.12 1999/09/27 03:13:16 momjian Exp $
+ * $Id: libpq-int.h,v 1.13 1999/11/11 00:10:14 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -247,7 +247,7 @@ extern int  pqPacketSend(PGconn *conn, const char *buf, size_t len);
 /* === in fe-exec.c === */
 
 extern void pqSetResultError(PGresult *res, const char *msg);
-extern void *pqResultAlloc(PGresult *res, int nBytes, int isBinary);
+extern void *pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary);
 extern char *pqResultStrdup(PGresult *res, const char *str);
 extern void pqClearAsyncResult(PGconn *conn);
 
@@ -261,10 +261,10 @@ extern void pqClearAsyncResult(PGconn *conn);
 extern int pqGetc(char *result, PGconn *conn);
 extern int pqGets(PQExpBuffer buf, PGconn *conn);
 extern int pqPuts(const char *s, PGconn *conn);
-extern int pqGetnchar(char *s, int len, PGconn *conn);
-extern int pqPutnchar(const char *s, int len, PGconn *conn);
-extern int pqGetInt(int *result, int bytes, PGconn *conn);
-extern int pqPutInt(int value, int bytes, PGconn *conn);
+extern int pqGetnchar(char *s, size_t len, PGconn *conn);
+extern int pqPutnchar(const char *s, size_t len, PGconn *conn);
+extern int pqGetInt(int *result, size_t bytes, PGconn *conn);
+extern int pqPutInt(int value, size_t bytes, PGconn *conn);
 extern int pqReadData(PGconn *conn);
 extern int pqFlush(PGconn *conn);
 extern int pqWait(int forRead, int forWrite, PGconn *conn);