The attached patch fixes a number of issues related to compiling the
authorBruce Momjian
Thu, 3 Oct 2002 17:09:42 +0000 (17:09 +0000)
committerBruce Momjian
Thu, 3 Oct 2002 17:09:42 +0000 (17:09 +0000)
client
utilities (libpq.dll and psql.exe) for win32 (missing defines,
adjustments to
includes, pedantic casting, non-existent functions) per:
   http://developer.postgresql.org/docs/postgres/install-win32.html.

It compiles cleanly under Windows 2000 using Visual Studio .net. Also
compiles clean and passes all regression tests (regular and contrib)
under Linux.

In addition to a review by the usual suspects, it would be very
desirable for  someone well versed in the peculiarities of win32 to take
a look.

Joe Conway

16 files changed:
src/backend/libpq/md5.c
src/bin/psql/command.c
src/bin/psql/common.c
src/bin/psql/copy.c
src/bin/psql/large_obj.c
src/bin/psql/mbprint.c
src/bin/psql/print.c
src/include/pg_config.h.win32
src/interfaces/libpq/fe-connect.c
src/interfaces/libpq/fe-misc.c
src/interfaces/libpq/fe-print.c
src/interfaces/libpq/libpq-int.h
src/interfaces/libpq/libpqdll.def
src/interfaces/libpq/pqexpbuffer.c
src/interfaces/libpq/win32.h
src/utils/Makefile

index 5c12e70c7f03f25599df2fa44cf11b9b19ffa9e9..dbf639fc74fc536a1ada30306bd5733f53d95aec 100644 (file)
@@ -14,7 +14,7 @@
  * Portions Copyright (c) 1994, Regents of the University of California
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.18 2002/09/04 20:31:19 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.19 2002/10/03 17:09:41 momjian Exp $
  */
 
 
  * can be compiled stand-alone.
  */
 
-#ifndef MD5_ODBC
+#if ! defined(MD5_ODBC) && ! defined(FRONTEND)
 #include "postgres.h"
 #include "libpq/crypt.h"
-#else
+#endif
+
+#ifdef FRONTEND
+#include "postgres_fe.h"
+#ifndef WIN32
+#include "libpq/crypt.h"
+#endif /* WIN32 */
+#endif /* FRONTEND */
+
+#ifdef MD5_ODBC
 #include "md5.h"
 #endif
 
index 32a94bad7f6336dc5f80339e9f9360c148a68a35..a9477c68ed90cf3f00e53371848fec05e1e0fe82 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.81 2002/09/22 20:57:21 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.82 2002/10/03 17:09:41 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "command.h"
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #endif
 
 #include "libpq-fe.h"
@@ -1163,7 +1164,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
                        return NULL;
                    }
 
-                   if (i < token_len - 1)
+                   if (i < (int) token_len - 1)
                        return_val[i + 1] = '\0';
                }
 
@@ -1240,7 +1241,7 @@ unescape(const unsigned char *source, size_t len)
        exit(EXIT_FAILURE);
    }
 
-   for (p = source; p - source < len && *p; p += PQmblen(p, pset.encoding))
+   for (p = source; p - source < (int) len && *p; p += PQmblen(p, pset.encoding))
    {
        if (esc)
        {
@@ -1278,7 +1279,7 @@ unescape(const unsigned char *source, size_t len)
                        char       *end;
 
                        l = strtol(p, &end, 0);
-                       c = l;
+                       c = (char) l;
                        p = end - 1;
                        break;
                    }
index a636372b0298ca75a76b63202a992e96a6e8bc30..c451640ee0d87eff755681c4bc53d610216222ff 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.45 2002/09/14 19:46:01 tgl Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.46 2002/10/03 17:09:41 momjian Exp $
  */
 #include "postgres_fe.h"
 
 
 #include 
 #include 
-#include 
 #ifndef HAVE_STRDUP
 #include 
 #endif
 #include 
 #ifndef WIN32
+#include 
 #include                 /* for write() */
 #include 
 #else
 #include                     /* for _write() */
 #include 
+#include          /* for _ftime() */
 #endif
 
 #include "libpq-fe.h"
@@ -295,9 +296,13 @@ SendQuery(const char *query)
    bool        success = false;
    PGresult   *results;
    PGnotify   *notify;
+#ifndef WIN32
    struct timeval before,
                after;
-   struct timezone tz;
+#else
+   struct _timeb before,
+               after;
+#endif
 
    if (!pset.db)
    {
@@ -327,11 +332,21 @@ SendQuery(const char *query)
    }
 
    cancelConn = pset.db;
+
+#ifndef WIN32
+   if (pset.timing)
+       gettimeofday(&before, NULL);
+   results = PQexec(pset.db, query);
+   if (pset.timing)
+       gettimeofday(&after, NULL);
+#else
    if (pset.timing)
-       gettimeofday(&before, &tz);
+       _ftime(&before);
    results = PQexec(pset.db, query);
    if (pset.timing)
-       gettimeofday(&after, &tz);
+       _ftime(&after);
+#endif
+
    if (PQresultStatus(results) == PGRES_COPY_IN)
        copy_in_state = true;
    /* keep cancel connection for copy out state */
@@ -463,8 +478,13 @@ SendQuery(const char *query)
 
    /* Possible microtiming output */
    if (pset.timing && success)
+#ifndef WIN32
        printf(gettext("Time: %.2f ms\n"),
               ((after.tv_sec - before.tv_sec) * 1000000.0 + after.tv_usec - before.tv_usec) / 1000.0);
+#else
+       printf(gettext("Time: %.2f ms\n"),
+              ((after.time - before.time) * 1000.0 + after.millitm - before.millitm));
+#endif
 
    return success;
 }
index 74394d219bf961f10e9490e9d07ec5c66673542a..926641f5f412dbe8321f3ac7b43b73a92eccaefd 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.25 2002/09/22 20:57:21 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.26 2002/10/03 17:09:41 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "copy.h"
@@ -28,6 +28,8 @@
 
 #ifdef WIN32
 #define strcasecmp(x,y) stricmp(x,y)
+#define    __S_ISTYPE(mode, mask)  (((mode) & S_IFMT) == (mask))
+#define    S_ISDIR(mode)    __S_ISTYPE((mode), S_IFDIR)
 #endif
 
 bool       copy_in_state;
index 2bca9da05e16eeecd6fcb9f7ab8bc7ff34bf4432..9bf51622cc465265e3977a9cce6db21918f32e3f 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000-2002 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.21 2002/09/04 20:31:36 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.22 2002/10/03 17:09:41 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "large_obj.h"
@@ -196,7 +196,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
    {
        char       *cmdbuf;
        char       *bufptr;
-       int         slen = strlen(comment_arg);
+       size_t      slen = strlen(comment_arg);
 
        cmdbuf = malloc(slen * 2 + 256);
        if (!cmdbuf)
index dcd305d921293b88a23dd67397a82cacafe12a22..c91b71c9c5beafe846ac9299b83163491b6b0084 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.4 2002/08/27 20:16:48 petere Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.5 2002/10/03 17:09:42 momjian Exp $
  */
 
 #include "postgres_fe.h"
@@ -202,7 +202,7 @@ mb_utf_wcswidth(unsigned char *pwcs, size_t len)
    for (; *pwcs && len > 0; pwcs += l)
    {
        l = pg_utf_mblen(pwcs);
-       if ((len < l) || ((w = ucs_wcwidth(utf2ucs(pwcs))) < 0))
+       if ((len < (size_t) l) || ((w = ucs_wcwidth(utf2ucs(pwcs))) < 0))
            return width;
        len -= l;
        width += w;
index 3aefbb5b4c2dd82e7b54b88dabd64998d3f0e6a4..f74fedce079f43706ec887cbaafc66097969a58e 100644 (file)
@@ -3,7 +3,7 @@
  *
  * Copyright 2000 by PostgreSQL Global Development Group
  *
- * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.31 2002/09/01 23:30:46 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.32 2002/10/03 17:09:42 momjian Exp $
  */
 #include "postgres_fe.h"
 #include "print.h"
@@ -282,7 +282,7 @@ print_aligned_text(const char *title, const char *const * headers,
    {
        int         tlen;
 
-       if ((tlen = pg_wcswidth((unsigned char *) title, strlen(title))) >= total_w)
+       if ((unsigned int) (tlen = pg_wcswidth((unsigned char *) title, strlen(title))) >= total_w)
            fprintf(fout, "%s\n", title);
        else
            fprintf(fout, "%-*s%s\n", (int) (total_w - tlen) / 2, "", title);
@@ -1184,8 +1184,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
               footers ? (const char *const *) footers : (const char *const *) (opt->footers),
               align, &opt->topt, fout);
 
-   free(headers);
-   free(cells);
+   free((void *) headers);
+   free((void *) cells);
    if (footers)
    {
        free(footers[0]);
index 9f8fe4652282109a97a8b96f69e919e123e6db73..aaeecf5957bc316915c7b1fb1e9a2542929f79b7 100644 (file)
@@ -16,6 +16,8 @@
 
 #define MAXPGPATH 1024
 
+#define INDEX_MAX_KEYS 32
+
 #define HAVE_ATEXIT
 #define HAVE_MEMMOVE
 
@@ -50,4 +52,8 @@
 
 #endif
 
+#ifndef __CYGWIN__
+#include 
+#endif
+
 #endif /* pg_config_h_win32__ */
index a51ade9bd2a174549ba8ec2b3ba8c80cad335e72..cbb29fa4a5473797e5c997e5ccc9b690a6e466b1 100644 (file)
@@ -8,7 +8,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.205 2002/09/22 20:57:21 petere Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.206 2002/10/03 17:09:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -21,7 +21,6 @@
 #include 
 #include 
 #include 
-#include 
 
 #include "libpq-fe.h"
 #include "libpq-int.h"
@@ -1053,10 +1052,10 @@ connectDBComplete(PGconn *conn)
 {
    PostgresPollingStatusType flag = PGRES_POLLING_WRITING;
 
-   struct timeval remains,
-              *rp = NULL,
-               finish_time,
-               start_time;
+   time_t          finish_time = 0,
+                   current_time;
+   struct timeval  remains,
+                  *rp = NULL;
 
    if (conn == NULL || conn->status == CONNECTION_BAD)
        return 0;
@@ -1074,19 +1073,13 @@ connectDBComplete(PGconn *conn)
        }
        remains.tv_usec = 0;
        rp = &remains;
+
+       /* calculate the finish time based on start + timeout */
+       finish_time = time((time_t *) NULL) + remains.tv_sec;
    }
 
    while (rp == NULL || remains.tv_sec > 0 || remains.tv_usec > 0)
    {
-       /*
-        * If connecting timeout is set, get current time.
-        */
-       if (rp != NULL && gettimeofday(&start_time, NULL) == -1)
-       {
-           conn->status = CONNECTION_BAD;
-           return 0;
-       }
-
        /*
         * Wait, if necessary.  Note that the initial state (just after
         * PQconnectStart) is to wait for the socket to select for
@@ -1128,26 +1121,18 @@ connectDBComplete(PGconn *conn)
        flag = PQconnectPoll(conn);
 
        /*
-        * If connecting timeout is set, calculate remain time.
+        * If connecting timeout is set, calculate remaining time.
         */
        if (rp != NULL)
        {
-           if (gettimeofday(&finish_time, NULL) == -1)
+           if (time(¤t_time) == -1)
            {
                conn->status = CONNECTION_BAD;
                return 0;
            }
-           if ((finish_time.tv_usec -= start_time.tv_usec) < 0)
-           {
-               remains.tv_sec++;
-               finish_time.tv_usec += 1000000;
-           }
-           if ((remains.tv_usec -= finish_time.tv_usec) < 0)
-           {
-               remains.tv_sec--;
-               remains.tv_usec += 1000000;
-           }
-           remains.tv_sec -= finish_time.tv_sec - start_time.tv_sec;
+
+           remains.tv_sec = finish_time - current_time;
+           remains.tv_usec = 0;
        }
    }
    conn->status = CONNECTION_BAD;
@@ -2946,6 +2931,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
        return NULL;
    }
 
+#ifndef WIN32
    /* If password file is insecure, alert the user and ignore it. */
    if (stat_buf.st_mode & (S_IRWXG | S_IRWXO))
    {
@@ -2955,6 +2941,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
        free(pgpassfile);
        return NULL;
    }
+#endif
 
    fp = fopen(pgpassfile, "r");
    free(pgpassfile);
index 794e757d5691a681cae0cfaf6e1c9146381dfa00..ad41cf749d19bf42e1da6bd9aff14419ff155f69 100644 (file)
@@ -25,7 +25,7 @@
  *
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.79 2002/09/04 20:31:47 momjian Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.80 2002/10/03 17:09:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -150,9 +150,9 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
                 * try to grow the buffer. FIXME: The new size could be
                 * chosen more intelligently.
                 */
-               size_t      buflen = conn->outCount + nbytes;
+               size_t      buflen = (size_t) conn->outCount + nbytes;
 
-               if (buflen > conn->outBufSize)
+               if (buflen > (size_t) conn->outBufSize)
                {
                    char       *newbuf = realloc(conn->outBuffer, buflen);
 
@@ -240,7 +240,7 @@ pqPuts(const char *s, PGconn *conn)
 int
 pqGetnchar(char *s, size_t len, PGconn *conn)
 {
-   if (len < 0 || len > conn->inEnd - conn->inCursor)
+   if (len < 0 || len > (size_t) (conn->inEnd - conn->inCursor))
        return EOF;
 
    memcpy(s, conn->inBuffer + conn->inCursor, len);
index baa9700934ca609dab9913f4df4294adb9cfee4e..2dfdc5641c1bc091f8e739eb9ea41531ba230b90 100644 (file)
@@ -10,7 +10,7 @@
  * didn't really belong there.
  *
  * IDENTIFICATION
- *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.46 2002/08/29 07:22:30 ishii Exp $
+ *   $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.47 2002/10/03 17:09:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -299,7 +299,7 @@ PQprint(FILE *fout,
                    (PQntuples(res) == 1) ? "" : "s");
        free(fieldMax);
        free(fieldNotNum);
-       free(fieldNames);
+       free((void *) fieldNames);
        if (usePipe)
        {
 #ifdef WIN32
index daf2f9ae0b457a4a5a0c446e2ad178e88d6c0edf..cdf978e5b13130aaf4889d06729954265e31c96e 100644 (file)
@@ -12,7 +12,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Id: libpq-int.h,v 1.57 2002/09/04 20:31:47 momjian Exp $
+ * $Id: libpq-int.h,v 1.58 2002/10/03 17:09:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
 #define LIBPQ_INT_H
 
 #include 
-#include 
 #include 
+#ifndef WIN32
+#include 
+#endif
 
 #if defined(WIN32) && (!defined(ssize_t))
 typedef int ssize_t;           /* ssize_t doesn't exist in VC (atleast
index b75eb20fa6e5702886e4eeb313f7dfb030ad1bc9..524a7468e8a44ef7a384846c9160d2dd7e68e36b 100644 (file)
@@ -1,5 +1,4 @@
 LIBRARY LIBPQ
-DESCRIPTION "Postgres Client Access Library"
 EXPORTS
    PQconnectdb         @ 1
    PQsetdbLogin        @ 2
@@ -90,3 +89,7 @@ EXPORTS
    PQfreeNotify        @ 87
    PQescapeString      @ 88
    PQescapeBytea       @ 89
+   printfPQExpBuffer   @ 90
+   appendPQExpBuffer   @ 91
+   pg_encoding_to_char @ 92
+   pg_utf_mblen        @ 93
index 9d679bb726328707e27b9a031d26af195a545105..4bd78b18740a8040eb246f24b544e15c00afe32c 100644 (file)
@@ -17,7 +17,7 @@
  * Portions Copyright (c) 1996-2002, PostgreSQL Global Development Group
  * Portions Copyright (c) 1994, Regents of the University of California
  *
- * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.13 2002/06/20 20:29:54 momjian Exp $
+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/pqexpbuffer.c,v 1.14 2002/10/03 17:09:42 momjian Exp $
  *
  *-------------------------------------------------------------------------
  */
@@ -192,7 +192,7 @@ printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
             * actually stored, but at least one returns -1 on failure. Be
             * conservative about believing whether the print worked.
             */
-           if (nprinted >= 0 && nprinted < avail - 1)
+           if (nprinted >= 0 && nprinted < (int) avail - 1)
            {
                /* Success.  Note nprinted does not include trailing null. */
                str->len += nprinted;
@@ -240,7 +240,7 @@ appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
             * actually stored, but at least one returns -1 on failure. Be
             * conservative about believing whether the print worked.
             */
-           if (nprinted >= 0 && nprinted < avail - 1)
+           if (nprinted >= 0 && nprinted < (int) avail - 1)
            {
                /* Success.  Note nprinted does not include trailing null. */
                str->len += nprinted;
index db1aa53b24fba141408c1b2de5eb62df7376fba8..4e8a2141d5324a13c99b67c5de769f0644af45cd 100644 (file)
@@ -22,7 +22,7 @@
 /*
  * crypt not available (yet)
  */
-#define crypt(a,b) (a)
+#define crypt(a,b) ((char *) a)
 
 #undef EAGAIN                  /* doesn't apply on sockets */
 #undef EINTR
index 26273cd4bd560488adb4a403bf343b5ab2f2bb72..ef9e121c081de95ae0b2076d84a1d6c7f4cbf4bb 100644 (file)
@@ -2,7 +2,7 @@
 #
 # Makefile for utils
 #
-# $Header: /cvsroot/pgsql/src/utils/Attic/Makefile,v 1.14 2002/07/27 20:10:05 petere Exp $
+# $Header: /cvsroot/pgsql/src/utils/Attic/Makefile,v 1.15 2002/10/03 17:09:42 momjian Exp $
 #
 # dllinit.o is only built on Win32 platform.
 #
@@ -15,4 +15,4 @@ include $(top_builddir)/src/Makefile.global
 all:
 
 clean distclean maintainer-clean:
-   rm -f dllinit.o
+   rm -f dllinit.o getopt.o