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

Commit8fc386a

Browse files
committed
Eliminate using putenv().
1 parent6095e36 commit8fc386a

File tree

4 files changed

+46
-23
lines changed

4 files changed

+46
-23
lines changed

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

Lines changed: 16 additions & 11 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.109 2000/01/14 05:33:15 tgl Exp $
10+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.110 2000/01/15 05:37:21 ishii Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -1299,7 +1299,7 @@ PQconnectPoll(PGconn *conn)
12991299
these queries. */
13001300
conn->status=CONNECTION_OK;
13011301

1302-
switch (PQsetenvPoll(conn->setenv_handle))
1302+
switch (PQsetenvPoll(conn))
13031303
{
13041304
casePGRES_POLLING_OK:/* Success */
13051305
conn->status=CONNECTION_OK;
@@ -1384,8 +1384,9 @@ PQsetenvStart(PGconn *conn)
13841384
* ----------------
13851385
*/
13861386
PostgresPollingStatusType
1387-
PQsetenvPoll(PGsetenvHandlehandle)
1387+
PQsetenvPoll(PGconn*conn)
13881388
{
1389+
PGsetenvHandlehandle=conn->setenv_handle;
13891390
#ifdefMULTIBYTE
13901391
staticconstcharenvname[]="PGCLIENTENCODING";
13911392
#endif
@@ -1470,16 +1471,12 @@ PQsetenvPoll(PGsetenvHandle handle)
14701471

14711472
encoding=PQgetvalue(handle->res,0,0);
14721473
if (!encoding)/* this should not happen */
1473-
encoding=pg_encoding_to_char(MULTIBYTE);
1474+
encoding=SQL_ASCII;
14741475

14751476
if (encoding)
14761477
{
1477-
/* set client encoding via environment variable */
1478-
char*envbuf;
1479-
1480-
envbuf= (char*)malloc(strlen(envname)+strlen(encoding)+2);
1481-
sprintf(envbuf,"%s=%s",envname,encoding);
1482-
putenv(envbuf);
1478+
/* set client encoding to pg_conn struct */
1479+
conn->client_encoding=atoi(encoding);
14831480
}
14841481
PQclear(handle->res);
14851482
/* We have to keep going in order to clear up the query */
@@ -1630,7 +1627,7 @@ PQsetenv(PGconn *conn)
16301627
return0;
16311628

16321629
for (;;) {
1633-
flag=PQsetenvPoll(handle);
1630+
flag=PQsetenvPoll(conn);
16341631
switch (flag)
16351632
{
16361633
casePGRES_POLLING_ACTIVE:
@@ -2355,6 +2352,14 @@ PQbackendPID(const PGconn *conn)
23552352
returnconn->be_pid;
23562353
}
23572354

2355+
int
2356+
PQclientencoding(constPGconn*conn)
2357+
{
2358+
if (!conn||conn->status!=CONNECTION_OK)
2359+
return-1;
2360+
returnconn->client_encoding;
2361+
}
2362+
23582363
void
23592364
PQtrace(PGconn*conn,FILE*debug_port)
23602365
{

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

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* didn't really belong there.
1010
*
1111
* IDENTIFICATION
12-
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.28 1999/11/11 00:10:14 momjian Exp $
12+
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-print.c,v 1.29 2000/01/15 05:37:21 ishii Exp $
1313
*
1414
*-------------------------------------------------------------------------
1515
*/
@@ -498,27 +498,39 @@ PQprintTuples(const PGresult *res,
498498
* the backend is assumed.
499499
*/
500500
int
501-
PQmblen(constunsignedchar*s)
501+
PQmblen(constunsignedchar*s,intencoding)
502+
{
503+
return (pg_encoding_mblen(encoding,s));
504+
}
505+
506+
/*
507+
* Get encoding id from environment variable PGCLIENTENCODING.
508+
*/
509+
int
510+
PQenv2encoding(void)
502511
{
503512
char*str;
504-
intencoding=-1;
513+
intencoding=SQL_ASCII;
505514

506515
str=getenv("PGCLIENTENCODING");
507516
if (str&&*str!='\0')
508517
encoding=pg_char_to_encoding(str);
509-
if (encoding<0)
510-
encoding=MULTIBYTE;
511-
return (pg_encoding_mblen(encoding,s));
518+
return(encoding);
512519
}
513520

514521
#else
515522

516523
/* Provide a default definition in case someone calls it anyway */
517524
int
518-
PQmblen(constunsignedchar*s)
525+
PQmblen(constunsignedchar*s,intencoding)
519526
{
520527
return1;
521528
}
529+
int
530+
PQenv2encoding(void)
531+
{
532+
return0;
533+
}
522534

523535
#endif/* MULTIBYTE */
524536

@@ -560,7 +572,7 @@ do_field(const PQprintOpt *po, const PGresult *res,
560572
charch='0';
561573

562574
#ifdefMULTIBYTE
563-
for (p=pval;*p;p+=PQmblen(p))
575+
for (p=pval;*p;p+=PQmblen(p,PQclientencoding(res->conn)))
564576
#else
565577
for (p=pval;*p;p++)
566578
#endif

‎src/interfaces/libpq/libpq-fe.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: libpq-fe.h,v 1.54 2000/01/14 05:33:15 tgl Exp $
9+
* $Id: libpq-fe.h,v 1.55 2000/01/15 05:37:21 ishii Exp $
1010
*
1111
*-------------------------------------------------------------------------
1212
*/
@@ -224,6 +224,7 @@ extern"C"
224224
externconstchar*PQerrorMessage(constPGconn*conn);
225225
externintPQsocket(constPGconn*conn);
226226
externintPQbackendPID(constPGconn*conn);
227+
externintPQclientencoding(constPGconn*conn);
227228

228229
/* Enable/disable tracing */
229230
externvoidPQtrace(PGconn*conn,FILE*debug_port);
@@ -235,7 +236,7 @@ extern"C"
235236
/* Passing of environment variables */
236237
/* Asynchronous (non-blocking) */
237238
externPGsetenvHandlePQsetenvStart(PGconn*conn);
238-
externPostgresPollingStatusTypePQsetenvPoll(PGsetenvHandlehandle);
239+
externPostgresPollingStatusTypePQsetenvPoll(PGconn*conn);
239240
externvoidPQsetenvAbort(PGsetenvHandlehandle);
240241

241242
/* Synchronous (blocking) */
@@ -333,7 +334,10 @@ extern"C"
333334
* 0, use variable width */
334335

335336
/* Determine length of multibyte encoded char at *s */
336-
externintPQmblen(constunsignedchar*s);
337+
externintPQmblen(constunsignedchar*s,intencoding);
338+
339+
/* Get encoding id from environment variable PGCLIENTENCODING */
340+
intPQenv2encoding(void);
337341

338342
/* === in fe-lobj.c === */
339343

‎src/interfaces/libpq/libpq-int.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*
1212
* Copyright (c) 1994, Regents of the University of California
1313
*
14-
* $Id: libpq-int.h,v 1.15 2000/01/14 05:33:15 tgl Exp $
14+
* $Id: libpq-int.h,v 1.16 2000/01/15 05:37:21 ishii Exp $
1515
*
1616
*-------------------------------------------------------------------------
1717
*/
@@ -236,6 +236,8 @@ struct pg_conn
236236

237237
/* Buffer for receiving various parts of messages */
238238
PQExpBufferDataworkBuffer;/* expansible string */
239+
240+
intclient_encoding;/* encoding id */
239241
};
240242

241243
/* ----------------

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp