Re: [HACKERS] Snapshot 270198 compile error

Bruce Momjian <maillist@candle.pha.pa.us>

From: Bruce Momjian <maillist@candle.pha.pa.us>
To: phil@river-bank.demon.co.uk (Phil Thompson)
Cc: goran@bildbasen.se, fenix@am.ring.ru, pgsql-hackers@postgreSQL.org
Date: 1998-01-27T19:50:01Z
Lists: pgsql-hackers
> 
> Bruce Momjian wrote:
> 
> >   #define       UNIXSOCK_PATH(sun,port) \
> >         (sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)) + \
> > !               + 1 + sizeof ((sun).sun_family))
> > ! /*
> > !  *            + 1 is for BSD-specific sizeof((sun).sun_len)
> > !  *            We never actually set sun_len, and I can't think of a
> > !  *            platform-safe way of doing it, but the code still works. bjm
> > !  */

OK, I am with you.  Even better, let's use offset().  Takes care of
possible OS padding between fields too:

---------------------------------------------------------------------------


*** ./include/libpq/pqcomm.h.orig	Tue Jan 27 14:28:27 1998
--- ./include/libpq/pqcomm.h	Tue Jan 27 14:48:15 1998
***************
*** 35,44 ****
  
  #define	UNIXSOCK_PATH(sun,port) \
  	(sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)) + \
! 		+ 1 + sizeof ((sun).sun_family))
  /*
!  *		+ 1 is for BSD-specific sizeof((sun).sun_len)
!  *		We never actually set sun_len, and I can't think of a
   *		platform-safe way of doing it, but the code still works. bjm
   */
  
--- 35,44 ----
  
  #define	UNIXSOCK_PATH(sun,port) \
  	(sprintf((sun).sun_path, "/tmp/.s.PGSQL.%d", (port)) + \
! 		offsetof(struct sockaddr_un, sun_path))
  /*
!  *		We do this because sun_len is in BSD's struct, while others don't.
!  *		We never actually set BSD's sun_len, and I can't think of a
   *		platform-safe way of doing it, but the code still works. bjm
   */
  


-- 
Bruce Momjian
maillist@candle.pha.pa.us