Re: [HACKERS] problems with sunos4 port, endian? - Mailing list pgsql-hackers

From Bruce Momjian
Subject Re: [HACKERS] problems with sunos4 port, endian?
Date
Msg-id 41cf1fbe2d3fc24d476011b8ccac7d82
Whole thread Raw
In response to [HACKERS] problems with sunos4 port, endian?  (Chris McGonagle <pglist@FOUR.net>)
List pgsql-hackers
I would love to here some enlightened opinions on this.

It was my belief that we didn't change the communication in 6.1, and
that all communication between different systems was working properly.

>
> >Endian problems with the endian changes to the libpq.  Ran into the same
> >situation here.  Have our own J/ODBC drivers we had to change...shorts and ints
> >are coming thru big endian instead of little endian.
>
> Here is a patch to fix the endian problem of 6.1. With this patch,
> your big endian postgres server will begin to speak little endian as
> 6.0!
>
> Tatsuo Ishii
> t-ishii@sra.co.jp
> --------------------------- cut here -----------------------
> Index: src/backend/libpq/pqcomprim.c
> ===================================================================
> RCS file: /home/mgr/t-ishii/repository/postgresql-v6.1/src/backend/libpq/pqcomprim.c,v
> retrieving revision 1.1.1.1
> diff -c -r1.1.1.1 pqcomprim.c
> *** pqcomprim.c    1997/06/16 01:45:30    1.1.1.1
> --- pqcomprim.c    1997/06/19 01:44:43
> ***************
> *** 24,34 ****
>   #  define hton_l(n) n
>   #else    /* BYTE_ORDER != LITTLE_ENDIAN */
>   #  if BYTE_ORDER == BIG_ENDIAN
> ! #    define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1])
> ! #    define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | \
> !                             ((u_char *)&n)[1] << 16 | \
> !                               ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3])
> ! #    define hton_s(n) (u_short)(((u_char *) &n)[2] << 8 | ((u_char *) &n)[3])
>   #    define hton_l(n) (ntoh_l(n))
>   #  else    /* BYTE_ORDER != BIG_ENDIAN */
>   #    if BYTE_ORDER == PDP_ENDIAN
> --- 24,34 ----
>   #  define hton_l(n) n
>   #else    /* BYTE_ORDER != LITTLE_ENDIAN */
>   #  if BYTE_ORDER == BIG_ENDIAN
> ! #    define ntoh_s(n) (u_short)(((u_char *) &n)[1] << 8 | ((u_char *) &n)[0])
> ! #    define ntoh_l(n) (u_long)(((u_char *)&n)[3] << 24 | \
> !                             ((u_char *)&n)[2] << 16 | \
> !                               ((u_char *)&n)[1] << 8 | ((u_char *)&n)[0])
> ! #    define hton_s(n) (ntoh_s(n))
>   #    define hton_l(n) (ntoh_l(n))
>   #  else    /* BYTE_ORDER != BIG_ENDIAN */
>   #    if BYTE_ORDER == PDP_ENDIAN
> ***************
> *** 43,51 ****
>   int pqPutShort(int integer, FILE *f)
>       {
>       int retval = 0;
> !     u_short n;
>
> !     n = hton_s(integer);
>       if(fwrite(&n, sizeof(u_short), 1, f) != 1)
>           retval = EOF;
>
> --- 43,52 ----
>   int pqPutShort(int integer, FILE *f)
>       {
>       int retval = 0;
> !     u_short n,s;
>
> !     s = integer;
> !     n = hton_s(s);
>       if(fwrite(&n, sizeof(u_short), 1, f) != 1)
>           retval = EOF;
>
>
>


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

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

pgsql-hackers by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] problems with sunos4 port, endian?
Next
From: Tatsuo Ishii
Date:
Subject: Re: [HACKERS] problems with sunos4 port, endian?