Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita0bf250

Browse files
committed
The attached patch fixes a number of issues related to compiling the
clientutilities (libpq.dll and psql.exe) for win32 (missing defines,adjustments toincludes, 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. Alsocompiles clean and passes all regression tests (regular and contrib)under Linux.In addition to a review by the usual suspects, it would be verydesirable for someone well versed in the peculiarities of win32 to takea look.Joe Conway
1 parentd4eae72 commita0bf250

File tree

16 files changed

+94
-64
lines changed

16 files changed

+94
-64
lines changed

‎src/backend/libpq/md5.c

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.18 2002/09/04 20:31:19 momjian Exp $
17+
* $Header: /cvsroot/pgsql/src/backend/libpq/md5.c,v 1.19 2002/10/03 17:09:41 momjian Exp $
1818
*/
1919

2020

@@ -26,10 +26,19 @@
2626
*can be compiled stand-alone.
2727
*/
2828

29-
#ifndefMD5_ODBC
29+
#if ! defined(MD5_ODBC)&& ! defined(FRONTEND)
3030
#include"postgres.h"
3131
#include"libpq/crypt.h"
32-
#else
32+
#endif
33+
34+
#ifdefFRONTEND
35+
#include"postgres_fe.h"
36+
#ifndefWIN32
37+
#include"libpq/crypt.h"
38+
#endif/* WIN32 */
39+
#endif/* FRONTEND */
40+
41+
#ifdefMD5_ODBC
3342
#include"md5.h"
3443
#endif
3544

‎src/bin/psql/command.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.81 2002/09/22 20:57:21 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/command.c,v 1.82 2002/10/03 17:09:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"command.h"
@@ -23,6 +23,7 @@
2323
#include<win32.h>
2424
#include<io.h>
2525
#include<fcntl.h>
26+
#include<direct.h>
2627
#endif
2728

2829
#include"libpq-fe.h"
@@ -1163,7 +1164,7 @@ scan_option(char **string, enum option_type type, char *quote, bool semicolon)
11631164
returnNULL;
11641165
}
11651166

1166-
if (i<token_len-1)
1167+
if (i<(int)token_len-1)
11671168
return_val[i+1]='\0';
11681169
}
11691170

@@ -1240,7 +1241,7 @@ unescape(const unsigned char *source, size_t len)
12401241
exit(EXIT_FAILURE);
12411242
}
12421243

1243-
for (p=source;p-source<len&&*p;p+=PQmblen(p,pset.encoding))
1244+
for (p=source;p-source<(int)len&&*p;p+=PQmblen(p,pset.encoding))
12441245
{
12451246
if (esc)
12461247
{
@@ -1278,7 +1279,7 @@ unescape(const unsigned char *source, size_t len)
12781279
char*end;
12791280

12801281
l=strtol(p,&end,0);
1281-
c=l;
1282+
c=(char)l;
12821283
p=end-1;
12831284
break;
12841285
}

‎src/bin/psql/common.c

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.45 2002/09/14 19:46:01 tgl Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/common.c,v 1.46 2002/10/03 17:09:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99

1010
#include"common.h"
1111

1212
#include<errno.h>
1313
#include<stdarg.h>
14-
#include<sys/time.h>
1514
#ifndefHAVE_STRDUP
1615
#include<strdup.h>
1716
#endif
1817
#include<signal.h>
1918
#ifndefWIN32
19+
#include<sys/time.h>
2020
#include<unistd.h>/* for write() */
2121
#include<setjmp.h>
2222
#else
2323
#include<io.h>/* for _write() */
2424
#include<win32.h>
25+
#include<sys/timeb.h>/* for _ftime() */
2526
#endif
2627

2728
#include"libpq-fe.h"
@@ -295,9 +296,13 @@ SendQuery(const char *query)
295296
boolsuccess= false;
296297
PGresult*results;
297298
PGnotify*notify;
299+
#ifndefWIN32
298300
structtimevalbefore,
299301
after;
300-
structtimezonetz;
302+
#else
303+
struct_timebbefore,
304+
after;
305+
#endif
301306

302307
if (!pset.db)
303308
{
@@ -327,11 +332,21 @@ SendQuery(const char *query)
327332
}
328333

329334
cancelConn=pset.db;
335+
336+
#ifndefWIN32
337+
if (pset.timing)
338+
gettimeofday(&before,NULL);
339+
results=PQexec(pset.db,query);
340+
if (pset.timing)
341+
gettimeofday(&after,NULL);
342+
#else
330343
if (pset.timing)
331-
gettimeofday(&before,&tz);
344+
_ftime(&before);
332345
results=PQexec(pset.db,query);
333346
if (pset.timing)
334-
gettimeofday(&after,&tz);
347+
_ftime(&after);
348+
#endif
349+
335350
if (PQresultStatus(results)==PGRES_COPY_IN)
336351
copy_in_state= true;
337352
/* keep cancel connection for copy out state */
@@ -463,8 +478,13 @@ SendQuery(const char *query)
463478

464479
/* Possible microtiming output */
465480
if (pset.timing&&success)
481+
#ifndefWIN32
466482
printf(gettext("Time: %.2f ms\n"),
467483
((after.tv_sec-before.tv_sec)*1000000.0+after.tv_usec-before.tv_usec) /1000.0);
484+
#else
485+
printf(gettext("Time: %.2f ms\n"),
486+
((after.time-before.time)*1000.0+after.millitm-before.millitm));
487+
#endif
468488

469489
returnsuccess;
470490
}

‎src/bin/psql/copy.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.25 2002/09/22 20:57:21 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/copy.c,v 1.26 2002/10/03 17:09:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"copy.h"
@@ -28,6 +28,8 @@
2828

2929
#ifdefWIN32
3030
#definestrcasecmp(x,y) stricmp(x,y)
31+
#define__S_ISTYPE(mode,mask)(((mode) & S_IFMT) == (mask))
32+
#defineS_ISDIR(mode) __S_ISTYPE((mode), S_IFDIR)
3133
#endif
3234

3335
boolcopy_in_state;

‎src/bin/psql/large_obj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000-2002 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.21 2002/09/04 20:31:36 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/large_obj.c,v 1.22 2002/10/03 17:09:41 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"large_obj.h"
@@ -196,7 +196,7 @@ do_lo_import(const char *filename_arg, const char *comment_arg)
196196
{
197197
char*cmdbuf;
198198
char*bufptr;
199-
intslen=strlen(comment_arg);
199+
size_tslen=strlen(comment_arg);
200200

201201
cmdbuf=malloc(slen*2+256);
202202
if (!cmdbuf)

‎src/bin/psql/mbprint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.4 2002/08/27 20:16:48 petere Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/mbprint.c,v 1.5 2002/10/03 17:09:42 momjian Exp $
77
*/
88

99
#include"postgres_fe.h"
@@ -202,7 +202,7 @@ mb_utf_wcswidth(unsigned char *pwcs, size_t len)
202202
for (;*pwcs&&len>0;pwcs+=l)
203203
{
204204
l=pg_utf_mblen(pwcs);
205-
if ((len<l)|| ((w=ucs_wcwidth(utf2ucs(pwcs)))<0))
205+
if ((len<(size_t)l)|| ((w=ucs_wcwidth(utf2ucs(pwcs)))<0))
206206
returnwidth;
207207
len-=l;
208208
width+=w;

‎src/bin/psql/print.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*
44
* Copyright 2000 by PostgreSQL Global Development Group
55
*
6-
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.31 2002/09/01 23:30:46 momjian Exp $
6+
* $Header: /cvsroot/pgsql/src/bin/psql/print.c,v 1.32 2002/10/03 17:09:42 momjian Exp $
77
*/
88
#include"postgres_fe.h"
99
#include"print.h"
@@ -282,7 +282,7 @@ print_aligned_text(const char *title, const char *const * headers,
282282
{
283283
inttlen;
284284

285-
if ((tlen=pg_wcswidth((unsignedchar*)title,strlen(title))) >=total_w)
285+
if ((unsignedint) (tlen=pg_wcswidth((unsignedchar*)title,strlen(title))) >=total_w)
286286
fprintf(fout,"%s\n",title);
287287
else
288288
fprintf(fout,"%-*s%s\n", (int) (total_w-tlen) /2,"",title);
@@ -1184,8 +1184,8 @@ printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout)
11841184
footers ? (constchar*const*)footers : (constchar*const*) (opt->footers),
11851185
align,&opt->topt,fout);
11861186

1187-
free(headers);
1188-
free(cells);
1187+
free((void*)headers);
1188+
free((void*)cells);
11891189
if (footers)
11901190
{
11911191
free(footers[0]);

‎src/include/pg_config.h.win32

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#define MAXPGPATH 1024
1818

19+
#define INDEX_MAX_KEYS 32
20+
1921
#define HAVE_ATEXIT
2022
#define HAVE_MEMMOVE
2123

@@ -50,4 +52,8 @@
5052

5153
#endif
5254

55+
#ifndef __CYGWIN__
56+
#include <windows.h>
57+
#endif
58+
5359
#endif /* pg_config_h_win32__ */

‎src/interfaces/libpq/fe-connect.c

Lines changed: 15 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.205 2002/09/22 20:57:21 petere Exp $
11+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.206 2002/10/03 17:09:42 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -21,7 +21,6 @@
2121
#include<errno.h>
2222
#include<ctype.h>
2323
#include<time.h>
24-
#include<unistd.h>
2524

2625
#include"libpq-fe.h"
2726
#include"libpq-int.h"
@@ -1053,10 +1052,10 @@ connectDBComplete(PGconn *conn)
10531052
{
10541053
PostgresPollingStatusTypeflag=PGRES_POLLING_WRITING;
10551054

1056-
structtimevalremains,
1057-
*rp=NULL,
1058-
finish_time,
1059-
start_time;
1055+
time_tfinish_time=0,
1056+
current_time;
1057+
structtimevalremains,
1058+
*rp=NULL;
10601059

10611060
if (conn==NULL||conn->status==CONNECTION_BAD)
10621061
return0;
@@ -1074,19 +1073,13 @@ connectDBComplete(PGconn *conn)
10741073
}
10751074
remains.tv_usec=0;
10761075
rp=&remains;
1076+
1077+
/* calculate the finish time based on start + timeout */
1078+
finish_time=time((time_t*)NULL)+remains.tv_sec;
10771079
}
10781080

10791081
while (rp==NULL||remains.tv_sec>0||remains.tv_usec>0)
10801082
{
1081-
/*
1082-
* If connecting timeout is set, get current time.
1083-
*/
1084-
if (rp!=NULL&&gettimeofday(&start_time,NULL)==-1)
1085-
{
1086-
conn->status=CONNECTION_BAD;
1087-
return0;
1088-
}
1089-
10901083
/*
10911084
* Wait, if necessary.Note that the initial state (just after
10921085
* PQconnectStart) is to wait for the socket to select for
@@ -1128,26 +1121,18 @@ connectDBComplete(PGconn *conn)
11281121
flag=PQconnectPoll(conn);
11291122

11301123
/*
1131-
* If connecting timeout is set, calculateremain time.
1124+
* If connecting timeout is set, calculateremaining time.
11321125
*/
11331126
if (rp!=NULL)
11341127
{
1135-
if (gettimeofday(&finish_time,NULL)==-1)
1128+
if (time(&current_time)==-1)
11361129
{
11371130
conn->status=CONNECTION_BAD;
11381131
return0;
11391132
}
1140-
if ((finish_time.tv_usec-=start_time.tv_usec)<0)
1141-
{
1142-
remains.tv_sec++;
1143-
finish_time.tv_usec+=1000000;
1144-
}
1145-
if ((remains.tv_usec-=finish_time.tv_usec)<0)
1146-
{
1147-
remains.tv_sec--;
1148-
remains.tv_usec+=1000000;
1149-
}
1150-
remains.tv_sec-=finish_time.tv_sec-start_time.tv_sec;
1133+
1134+
remains.tv_sec=finish_time-current_time;
1135+
remains.tv_usec=0;
11511136
}
11521137
}
11531138
conn->status=CONNECTION_BAD;
@@ -2946,6 +2931,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
29462931
returnNULL;
29472932
}
29482933

2934+
#ifndefWIN32
29492935
/* If password file is insecure, alert the user and ignore it. */
29502936
if (stat_buf.st_mode& (S_IRWXG |S_IRWXO))
29512937
{
@@ -2955,6 +2941,7 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
29552941
free(pgpassfile);
29562942
returnNULL;
29572943
}
2944+
#endif
29582945

29592946
fp=fopen(pgpassfile,"r");
29602947
free(pgpassfile);

‎src/interfaces/libpq/fe-misc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.79 2002/09/04 20:31:47 momjian Exp $
28+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.80 2002/10/03 17:09:42 momjian Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -150,9 +150,9 @@ pqPutBytes(const char *s, size_t nbytes, PGconn *conn)
150150
* try to grow the buffer. FIXME: The new size could be
151151
* chosen more intelligently.
152152
*/
153-
size_tbuflen=conn->outCount+nbytes;
153+
size_tbuflen=(size_t)conn->outCount+nbytes;
154154

155-
if (buflen>conn->outBufSize)
155+
if (buflen>(size_t)conn->outBufSize)
156156
{
157157
char*newbuf=realloc(conn->outBuffer,buflen);
158158

@@ -240,7 +240,7 @@ pqPuts(const char *s, PGconn *conn)
240240
int
241241
pqGetnchar(char*s,size_tlen,PGconn*conn)
242242
{
243-
if (len<0||len>conn->inEnd-conn->inCursor)
243+
if (len<0||len>(size_t) (conn->inEnd-conn->inCursor))
244244
returnEOF;
245245

246246
memcpy(s,conn->inBuffer+conn->inCursor,len);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp