The attached patch fixes a number of issues related to compiling the

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
This commit is contained in:
Bruce Momjian 2002-10-03 17:09:42 +00:00
parent d4eae72513
commit a0bf2503ea
16 changed files with 94 additions and 64 deletions

View 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 $
*/
@ -26,10 +26,19 @@
* 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

View 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 <win32.h>
#include <io.h>
#include <fcntl.h>
#include <direct.h>
#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;
}

View 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"
@ -11,17 +11,18 @@
#include <errno.h>
#include <stdarg.h>
#include <sys/time.h>
#ifndef HAVE_STRDUP
#include <strdup.h>
#endif
#include <signal.h>
#ifndef WIN32
#include <sys/time.h>
#include <unistd.h> /* for write() */
#include <setjmp.h>
#else
#include <io.h> /* for _write() */
#include <win32.h>
#include <sys/timeb.h> /* 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, &tz);
gettimeofday(&before, NULL);
results = PQexec(pset.db, query);
if (pset.timing)
gettimeofday(&after, &tz);
gettimeofday(&after, NULL);
#else
if (pset.timing)
_ftime(&before);
results = PQexec(pset.db, query);
if (pset.timing)
_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;
}

View 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;

View 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)

View 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;

View 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]);

View 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 <windows.h>
#endif
#endif /* pg_config_h_win32__ */

View 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 <errno.h>
#include <ctype.h>
#include <time.h>
#include <unistd.h>
#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(&current_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);

View 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);

View 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

View 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 $
*
*-------------------------------------------------------------------------
*/
@ -21,8 +21,10 @@
#define LIBPQ_INT_H
#include <time.h>
#include <sys/time.h>
#include <sys/types.h>
#ifndef WIN32
#include <sys/time.h>
#endif
#if defined(WIN32) && (!defined(ssize_t))
typedef int ssize_t; /* ssize_t doesn't exist in VC (atleast

View 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

View 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;

View 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

View 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