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

From Tatsuo Ishii
Subject Re: [HACKERS] problems with sunos4 port, endian?
Date
Msg-id 527334645df15072258b2080a5c1d8ff
Whole thread Raw
In response to [HACKERS] problems with sunos4 port, endian?  (Chris McGonagle <pglist@FOUR.net>)
List pgsql-hackers
>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;


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

pgsql-hackers by date:

Previous
From: Erik Bertelsen
Date:
Subject: Re: [HACKERS] Re: [QUESTIONS] Z39.50
Next
From: Bruce Momjian
Date:
Subject: Re: [HACKERS] problems with sunos4 port, endian?