77 *
88 *
99 * IDENTIFICATION
10- * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.46 1997/11/14 15:38:31 thomas Exp $
10+ * $Header: /cvsroot/pgsql/src/interfaces/libpq/fe-connect.c,v 1.47 1997/11/17 16:42:39 thomas Exp $
1111 *
1212 *-------------------------------------------------------------------------
1313 */
@@ -350,49 +350,43 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
350350conn -> port = NULL ;
351351conn -> notifyList = DLNewList ();
352352
353- if (! pghost || pghost [0 ]== '\0' )
353+ if (( pghost == NULL ) || pghost [0 ]== '\0' )
354354{
355355conn -> pghost = NULL ;
356- if (tmp = getenv ("PGHOST" ))
356+ if (( tmp = getenv ("PGHOST" )) != NULL )
357357conn -> pghost = strdup (tmp );
358358}
359359else
360360conn -> pghost = strdup (pghost );
361361
362- if (! pgport || pgport [0 ]== '\0' )
362+ if (( pgport == NULL ) || pgport [0 ]== '\0' )
363363{
364- if (!(tmp = getenv ("PGPORT" )))
365- {
364+ if ((tmp = getenv ("PGPORT" ))== NULL )
366365tmp = DEF_PGPORT ;
367- }
368366conn -> pgport = strdup (tmp );
369367}
370368else
371369conn -> pgport = strdup (pgport );
372370
373- if (! pgtty || pgtty [0 ]== '\0' )
371+ if (( pgtty == NULL ) || pgtty [0 ]== '\0' )
374372{
375- if (!(tmp = getenv ("PGTTY" )))
376- {
373+ if ((tmp = getenv ("PGTTY" ))== NULL )
377374tmp = DefaultTty ;
378- }
379375conn -> pgtty = strdup (tmp );
380376}
381377else
382378conn -> pgtty = strdup (pgtty );
383379
384- if (! pgoptions || pgoptions [0 ]== '\0' )
380+ if (( pgoptions == NULL ) || pgoptions [0 ]== '\0' )
385381{
386- if (!(tmp = getenv ("PGOPTIONS" )))
387- {
382+ if ((tmp = getenv ("PGOPTIONS" ))== NULL )
388383tmp = DefaultOption ;
389- }
390384conn -> pgoptions = strdup (tmp );
391385}
392386else
393387conn -> pgoptions = strdup (pgoptions );
394388
395- if ((tmp = getenv ("PGUSER" )))
389+ if ((tmp = getenv ("PGUSER" ))!= NULL )
396390{
397391error = FALSE;
398392conn -> pguser = strdup (tmp );
@@ -413,19 +407,15 @@ PQsetdb(const char *pghost, const char *pgport, const char *pgoptions, const cha
413407}
414408}
415409
416- if ((tmp = getenv ("PGPASSWORD" )))
417- {
410+ if ((tmp = getenv ("PGPASSWORD" ))!= NULL )
418411conn -> pgpass = strdup (tmp );
419- }
420412else
421- {
422413conn -> pgpass = 0 ;
423- }
424414
425415if (!error )
426416{
427- if (((tmp = (char * )dbName )&& (dbName [0 ]!= '\0' ))||
428- ((tmp = getenv ("PGDATABASE" ))))
417+ if (((( tmp = (char * )dbName )!= NULL ) && (dbName [0 ]!= '\0' ))
418+ || ((tmp = getenv ("PGDATABASE" ))))
429419conn -> dbName = strdup (tmp );
430420else
431421conn -> dbName = strdup (conn -> pguser );
@@ -523,17 +513,25 @@ connectDB(PGconn *conn)
523513port = (Port * )malloc (sizeof (Port ));
524514MemSet ((char * )port ,0 ,sizeof (Port ));
525515
526- if (conn -> pghost &&
527- (!(hp = gethostbyname (conn -> pghost ))|| hp -> h_addrtype != AF_INET ))
516+ if (conn -> pghost != NULL )
528517{
529- (void )sprintf (conn -> errorMessage ,
530- "connectDB() -- unknown hostname: %s\n" ,
531- conn -> pghost );
532- gotoconnect_errReturn ;
533- }
518+ hp = gethostbyname (conn -> pghost );
519+ if ((hp == NULL )|| (hp -> h_addrtype != AF_INET ))
520+ {
521+ (void )sprintf (conn -> errorMessage ,
522+ "connectDB() -- unknown hostname: %s\n" ,
523+ conn -> pghost );
524+ gotoconnect_errReturn ;
525+ }
526+ }else
527+ hp = NULL ;
528+
529+ #if FALSE
534530MemSet ((char * )& port -> raddr ,0 ,sizeof (port -> raddr ));
531+ #endif
535532portno = atoi (conn -> pgport );
536- port -> raddr .in .sin_family = family = conn -> pghost ?AF_INET :AF_UNIX ;
533+ family = (conn -> pghost != NULL ) ?AF_INET :AF_UNIX ;
534+ port -> raddr .in .sin_family = family ;
537535if (family == AF_INET )
538536{
539537memmove ((char * )& (port -> raddr .in .sin_addr ),
@@ -620,15 +618,15 @@ connectDB(PGconn *conn)
620618}
621619
622620/* free the password so it's not hanging out in memory forever */
623- if (conn -> pgpass )
621+ if (conn -> pgpass != NULL )
624622{
625623free (conn -> pgpass );
626624}
627625
628626/* set up the socket file descriptors */
629627conn -> Pfout = fdopen (port -> sock ,"w" );
630628conn -> Pfin = fdopen (dup (port -> sock ),"r" );
631- if (! conn -> Pfout || ! conn -> Pfin )
629+ if (( conn -> Pfout == NULL ) || ( conn -> Pfin == NULL ) )
632630{
633631(void )sprintf (conn -> errorMessage ,
634632"connectDB() -- fdopen() failed: errno=%d\n%s\n" ,