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

Commitc765b4b

Browse files
committed
Hello!
Through some minor changes, I have been able to compile the libpqclient libraries on the Win32 platform. Since the libpq communicationspart has been rewritten, this has become much easier. Enclosed isa patch that will allow at least Microsoft Visual C++ to compilelibpq into both a static and a dynamic library. I will take a lookat porting the psql frontend as well, but I figured it was a goodidea to send in these patches first - so no major changes are doneto the files before it gets applied (if it does).Regards, Magnus Hagander
1 parentd5283cc commitc765b4b

File tree

12 files changed

+334
-12
lines changed

12 files changed

+334
-12
lines changed

‎src/include/postgres.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1995, Regents of the University of California
88
*
9-
* $Id: postgres.h,v 1.16 1998/04/26 04:08:18 momjian Exp $
9+
* $Id: postgres.h,v 1.17 1998/07/03 04:24:10 momjian Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -37,7 +37,9 @@
3737
#definePOSTGRES_H
3838

3939
#include"postgres_ext.h"
40+
#ifndefWIN32
4041
#include"config.h"
42+
#endif
4143
#include"c.h"
4244
#include"utils/elog.h"
4345
#include"utils/palloc.h"

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.17 1998/06/15 19:30:22 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-auth.c,v 1.18 1998/07/03 04:24:11 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -24,6 +24,9 @@
2424
*
2525
*
2626
*/
27+
#ifdefWIN32
28+
#include"win32.h"
29+
#else
2730
#include<stdio.h>
2831
#include<string.h>
2932
#include<sys/param.h>/* for MAXHOSTNAMELEN on most */
@@ -33,6 +36,7 @@
3336
#endif
3437
#include<unistd.h>
3538
#include<pwd.h>
39+
#endif/* WIN32 */
3640

3741
#include"postgres.h"
3842

@@ -600,10 +604,18 @@ fe_getauthname(char *PQerrormsg)
600604
#endif
601605
caseSTARTUP_MSG:
602606
{
607+
#ifdefWIN32
608+
charusername[128];
609+
DWORDnamesize=sizeof(username)-1;
610+
611+
if (GetUserName(username,&namesize))
612+
name=username;
613+
#else
603614
structpasswd*pw=getpwuid(geteuid());
604615

605616
if (pw)
606617
name=pw->pw_name;
618+
#endif
607619
}
608620
break;
609621
default:

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

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.69 1998/06/21 16:39:11 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.70 1998/07/03 04:24:12 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -407,6 +407,7 @@ connectDB(PGconn *conn)
407407
family,
408408
len;
409409
charberesp;
410+
inton=1;
410411

411412
/*
412413
* Initialize the startup packet.
@@ -456,8 +457,11 @@ connectDB(PGconn *conn)
456457
conn->raddr.in.sin_port=htons((unsigned short) (portno));
457458
len=sizeof(structsockaddr_in);
458459
}
460+
#ifndefWIN32
459461
else
460462
len=UNIXSOCK_PATH(conn->raddr.un,portno);
463+
#endif
464+
461465

462466
/* Connect to the server */
463467
if ((conn->sock=socket(family,SOCK_STREAM,0))<0)
@@ -482,7 +486,11 @@ connectDB(PGconn *conn)
482486
* We need nonblocking I/O, and we don't want delay of outgoing data.
483487
*/
484488

489+
#ifndefWIN32
485490
if (fcntl(conn->sock,F_SETFL,O_NONBLOCK)<0)
491+
#else
492+
if (ioctlsocket(conn->sock,FIONBIO,&on)!=0)
493+
#endif
486494
{
487495
(void)sprintf(conn->errorMessage,
488496
"connectDB() -- fcntl() failed: errno=%d\n%s\n",
@@ -493,7 +501,6 @@ connectDB(PGconn *conn)
493501
if (family==AF_INET)
494502
{
495503
structprotoent*pe;
496-
inton=1;
497504

498505
pe=getprotobyname("TCP");
499506
if (pe==NULL)
@@ -503,11 +510,18 @@ connectDB(PGconn *conn)
503510
gotoconnect_errReturn;
504511
}
505512
if (setsockopt(conn->sock,pe->p_proto,TCP_NODELAY,
506-
&on,sizeof(on))<0)
513+
#ifdefWIN32
514+
(char*)
515+
#endif
516+
&on,
517+
sizeof(on))<0)
507518
{
508519
(void)sprintf(conn->errorMessage,
509520
"connectDB() -- setsockopt failed: errno=%d\n%s\n",
510521
errno,strerror(errno));
522+
#ifdefWIN32
523+
printf("Winsock error: %i\n",WSAGetLastError());
524+
#endif
511525
gotoconnect_errReturn;
512526
}
513527
}
@@ -666,7 +680,11 @@ connectDB(PGconn *conn)
666680
connect_errReturn:
667681
if (conn->sock >=0)
668682
{
683+
#ifdefWIN32
684+
closesocket(conn->sock);
685+
#else
669686
close(conn->sock);
687+
#endif
670688
conn->sock=-1;
671689
}
672690
returnCONNECTION_BAD;
@@ -742,7 +760,11 @@ freePGconn(PGconn *conn)
742760
return;
743761
PQclearAsyncResult(conn);/* deallocate result and curTuple */
744762
if (conn->sock >=0)
745-
close(conn->sock);/* shouldn't happen, but... */
763+
#ifdefWIN32
764+
closesocket(conn->sock);
765+
#else
766+
close(conn->sock);
767+
#endif
746768
if (conn->pghost)
747769
free(conn->pghost);
748770
if (conn->pgport)
@@ -783,6 +805,7 @@ closePGconn(PGconn *conn)
783805
* If connection is already gone, that's cool. No reason for kernel
784806
* to kill us when we try to write to it. So ignore SIGPIPE signals.
785807
*/
808+
#ifndefWIN32
786809
#if defined(USE_POSIX_SIGNALS)
787810
structsigactionignore_action;
788811
structsigactionoldaction;
@@ -806,13 +829,18 @@ closePGconn(PGconn *conn)
806829

807830
signal(SIGPIPE,oldsignal);
808831
#endif
832+
#endif/* Win32 uses no signals at all */
809833
}
810834

811835
/*
812836
* Close the connection, reset all transient state, flush I/O buffers.
813837
*/
814838
if (conn->sock >=0)
839+
#ifdefWIN32
840+
closesocket(conn->sock);
841+
#else
815842
close(conn->sock);
843+
#endif
816844
conn->sock=-1;
817845
conn->status=CONNECTION_BAD;/* Well, not really _bad_ - just
818846
* absent */

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.54 1998/06/16 07:29:48 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-exec.c,v 1.55 1998/07/03 04:24:13 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
14+
#ifdefWIN32
15+
#include"win32.h"
16+
#endif
1417
#include<stdlib.h>
1518
#include<stdio.h>
1619
#include<string.h>

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,16 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.13 1998/06/15 19:30:26 momjian Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-lobj.c,v 1.14 1998/07/03 04:24:14 momjian Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
14+
#ifdefWIN32
15+
#include"win32.h"
16+
#include<io.h>
17+
#else
1418
#include<unistd.h>
19+
#endif
1520
#include<stdio.h>
1621
#include<string.h>
1722
#include<fcntl.h>

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
*
2525
*
2626
* IDENTIFICATION
27-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.15 1998/06/15 19:30:26 momjian Exp $
27+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-misc.c,v 1.16 1998/07/03 04:24:14 momjian Exp $
2828
*
2929
*-------------------------------------------------------------------------
3030
*/
@@ -34,10 +34,14 @@
3434
#include<string.h>
3535
#include<errno.h>
3636
#include<time.h>
37+
#ifdefWIN32
38+
#include"win32.h"
39+
#else
3740
#include<sys/time.h>
3841
#if !defined(NO_UNISTD_H)
3942
#include<unistd.h>
4043
#endif
44+
#endif/* WIN32 */
4145
#include<sys/types.h>/* for fd_set stuff */
4246
#ifdefHAVE_SYS_SELECT_H
4347
#include<sys/select.h>
@@ -412,7 +416,11 @@ pqReadData(PGconn *conn)
412416
" before or while processing the request.\n");
413417
conn->status=CONNECTION_BAD;/* No more connection to
414418
* backend */
419+
#ifdefWIN32
420+
closesocket(conn->sock);
421+
#else
415422
close(conn->sock);
423+
#endif
416424
conn->sock=-1;
417425

418426
return-1;

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

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,24 +9,31 @@
99
* didn't really belong there.
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.5 1998/06/16 07:29:49 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.6 1998/07/03 04:24:15 momjian Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
16+
#ifdefWIN32
17+
#include"win32.h"
18+
#endif
1619
#include<postgres.h>
1720
#include<stdlib.h>
1821
#include<stdio.h>
1922
#include<signal.h>
2023
#include<string.h>
24+
#ifndefWIN32
2125
#include<unistd.h>
2226
#include<sys/ioctl.h>
27+
#endif
2328
#include"libpq/pqsignal.h"
2429
#include"libpq-fe.h"
30+
#ifndefWIN32
2531
#ifndefHAVE_TERMIOS_H
2632
#include<sys/termios.h>
2733
#else
2834
#include<termios.h>
2935
#endif
36+
#endif/* WIN32 */
3037

3138
#ifdefMB
3239
#include"regex/pg_wchar.h"
@@ -143,9 +150,13 @@ PQprint(FILE *fout,
143150

144151
if (fout==NULL)
145152
fout=stdout;
146-
if (po->pager&&fout==stdout&&
153+
if (po->pager&&fout==stdout
154+
#ifndefWIN32
155+
&&
147156
isatty(fileno(stdin))&&
148-
isatty(fileno(stdout)))
157+
isatty(fileno(stdout))
158+
#endif
159+
)
149160
{
150161
/* try to pipe to the pager program if possible */
151162
#ifdefTIOCGWINSZ
@@ -174,11 +185,17 @@ PQprint(FILE *fout,
174185
- (po->header!=0)*2/* row count and newline */
175186
)))
176187
{
188+
#ifdefWIN32
189+
fout=_popen(pagerenv,"w");
190+
#else
177191
fout=popen(pagerenv,"w");
192+
#endif
178193
if (fout)
179194
{
180195
usePipe=1;
196+
#ifndefWIN32
181197
pqsignal(SIGPIPE,SIG_IGN);
198+
#endif
182199
}
183200
else
184201
fout=stdout;
@@ -289,8 +306,12 @@ PQprint(FILE *fout,
289306
free(fieldNames);
290307
if (usePipe)
291308
{
309+
#ifdefWIN32
310+
_pclose(fout);
311+
#else
292312
pclose(fout);
293313
pqsignal(SIGPIPE,SIG_DFL);
314+
#endif
294315
}
295316
if (po->html3&& !po->expanded)
296317
fputs("</table>\n",fout);

‎src/interfaces/libpq/libpqdll.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#defineWIN32_LEAN_AND_MEAN
2+
#include<windows.h>
3+
BOOLWINAPIDllMain(HINSTANCEhinstDLL,DWORDfdwReason,
4+
LPVOIDlpReserved ){
5+
return (TRUE);
6+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp