Commit 80c1e822 authored by Thomas G. Lockhart's avatar Thomas G. Lockhart

Unscramble port selection logic to avoid compiler complaints about

 uninitialized variables. I _think_ the logic is preserved...
parent c2f4779d
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
* *
* *
* IDENTIFICATION * IDENTIFICATION
* $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.46 1997/11/14 15:38:31 thomas Exp $ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.47 1997/11/17 16:42:39 thomas Exp $
* *
*------------------------------------------------------------------------- *-------------------------------------------------------------------------
*/ */
...@@ -350,49 +350,43 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha ...@@ -350,49 +350,43 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
conn->port = NULL; conn->port = NULL;
conn->notifyList = DLNewList(); conn->notifyList = DLNewList();
if (!pghost || pghost[0] == '\0') if ((pghost == NULL) || pghost[0] == '\0')
{ {
conn->pghost = NULL; conn->pghost = NULL;
if (tmp = getenv("PGHOST")) if ((tmp = getenv("PGHOST")) != NULL)
conn->pghost = strdup(tmp); conn->pghost = strdup(tmp);
} }
else else
conn->pghost = strdup(pghost); conn->pghost = strdup(pghost);
if (!pgport || pgport[0] == '\0') if ((pgport == NULL) || pgport[0] == '\0')
{
if (!(tmp = getenv("PGPORT")))
{ {
if ((tmp = getenv("PGPORT")) == NULL)
tmp = DEF_PGPORT; tmp = DEF_PGPORT;
}
conn->pgport = strdup(tmp); conn->pgport = strdup(tmp);
} }
else else
conn->pgport = strdup(pgport); conn->pgport = strdup(pgport);
if (!pgtty || pgtty[0] == '\0') if ((pgtty == NULL) || pgtty[0] == '\0')
{
if (!(tmp = getenv("PGTTY")))
{ {
if ((tmp = getenv("PGTTY")) == NULL)
tmp = DefaultTty; tmp = DefaultTty;
}
conn->pgtty = strdup(tmp); conn->pgtty = strdup(tmp);
} }
else else
conn->pgtty = strdup(pgtty); conn->pgtty = strdup(pgtty);
if (!pgoptions || pgoptions[0] == '\0') if ((pgoptions == NULL) || pgoptions[0] == '\0')
{
if (!(tmp = getenv("PGOPTIONS")))
{ {
if ((tmp = getenv("PGOPTIONS")) == NULL)
tmp = DefaultOption; tmp = DefaultOption;
}
conn->pgoptions = strdup(tmp); conn->pgoptions = strdup(tmp);
} }
else else
conn->pgoptions = strdup(pgoptions); conn->pgoptions = strdup(pgoptions);
if ((tmp = getenv("PGUSER"))) if ((tmp = getenv("PGUSER")) != NULL)
{ {
error = FALSE; error = FALSE;
conn->pguser = strdup(tmp); conn->pguser = strdup(tmp);
...@@ -413,19 +407,15 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha ...@@ -413,19 +407,15 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
} }
} }
if ((tmp = getenv("PGPASSWORD"))) if ((tmp = getenv("PGPASSWORD")) != NULL)
{
conn->pgpass = strdup(tmp); conn->pgpass = strdup(tmp);
}
else else
{
conn->pgpass = 0; conn->pgpass = 0;
}
if (!error) if (!error)
{ {
if (((tmp = (char *) dbName) && (dbName[0] != '\0')) || if ((((tmp = (char *) dbName) != NULL) && (dbName[0] != '\0'))
((tmp = getenv("PGDATABASE")))) || ((tmp = getenv("PGDATABASE"))))
conn->dbName = strdup(tmp); conn->dbName = strdup(tmp);
else else
conn->dbName = strdup(conn->pguser); conn->dbName = strdup(conn->pguser);
...@@ -523,17 +513,25 @@ connectDB(PGconn *conn) ...@@ -523,17 +513,25 @@ connectDB(PGconn *conn)
port = (Port *) malloc(sizeof(Port)); port = (Port *) malloc(sizeof(Port));
MemSet((char *) port, 0, sizeof(Port)); MemSet((char *) port, 0, sizeof(Port));
if (conn->pghost && if (conn->pghost != NULL)
(!(hp = gethostbyname(conn->pghost)) || hp->h_addrtype != AF_INET)) {
hp = gethostbyname(conn->pghost);
if ((hp == NULL) || (hp->h_addrtype != AF_INET))
{ {
(void) sprintf(conn->errorMessage, (void) sprintf(conn->errorMessage,
"connectDB() -- unknown hostname: %s\n", "connectDB() -- unknown hostname: %s\n",
conn->pghost); conn->pghost);
goto connect_errReturn; goto connect_errReturn;
} }
} else
hp = NULL;
#if FALSE
MemSet((char *) &port->raddr, 0, sizeof(port->raddr)); MemSet((char *) &port->raddr, 0, sizeof(port->raddr));
#endif
portno = atoi(conn->pgport); portno = atoi(conn->pgport);
port->raddr.in.sin_family = family = conn->pghost ? AF_INET : AF_UNIX; family = (conn->pghost != NULL) ? AF_INET : AF_UNIX;
port->raddr.in.sin_family = family;
if (family == AF_INET) if (family == AF_INET)
{ {
memmove((char *) &(port->raddr.in.sin_addr), memmove((char *) &(port->raddr.in.sin_addr),
...@@ -620,7 +618,7 @@ connectDB(PGconn *conn) ...@@ -620,7 +618,7 @@ connectDB(PGconn *conn)
} }
/* free the password so it's not hanging out in memory forever */ /* free the password so it's not hanging out in memory forever */
if (conn->pgpass) if (conn->pgpass != NULL)
{ {
free(conn->pgpass); free(conn->pgpass);
} }
...@@ -628,7 +626,7 @@ connectDB(PGconn *conn) ...@@ -628,7 +626,7 @@ connectDB(PGconn *conn)
/* set up the socket file descriptors */ /* set up the socket file descriptors */
conn->Pfout = fdopen(port->sock, "w"); conn->Pfout = fdopen(port->sock, "w");
conn->Pfin = fdopen(dup(port->sock), "r"); conn->Pfin = fdopen(dup(port->sock), "r");
if (!conn->Pfout || !conn->Pfin) if ((conn->Pfout == NULL) || (conn->Pfin == NULL))
{ {
(void) sprintf(conn->errorMessage, (void) sprintf(conn->errorMessage,
"connectDB() -- fdopen() failed: errno=%d\n%s\n", "connectDB() -- fdopen() failed: errno=%d\n%s\n",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment