@@ -709,6 +709,28 @@ int CntIndexInit(PGLOBAL g, PTDB ptdb, int id, bool sorted)
709
709
return (tdbp->To_Kindex ->IsMul ()) ? 2 : 1 ;
710
710
} // end of CntIndexInit
711
711
712
+ #if defined(WORDS_BIGENDIAN)
713
+ /* **********************************************************************/
714
+ /* Swap bytes of the key that are written in little endian order. */
715
+ /* **********************************************************************/
716
+ static void SetSwapValue (PVAL valp, char *kp)
717
+ {
718
+ if (valp->IsTypeNum () && valp->GetType () != TYPE_DECIM) {
719
+ uchar buf[8 ];
720
+ int i, k= valp->GetClen ();
721
+
722
+ for (i = 0 ; k > 0 ;)
723
+ buf[i++]= kp[--k];
724
+
725
+
726
+
727
+ valp->SetBinValue ((void *)buf);
728
+ } else
729
+ valp->SetBinValue ((void *)kp);
730
+
731
+ } // end of SetSwapValue
732
+ #endif // WORDS_BIGENDIAN
733
+
712
734
/* **********************************************************************/
713
735
/* IndexRead: fetch a record having the index value. */
714
736
/* **********************************************************************/
@@ -779,7 +801,12 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
779
801
780
802
if (!valp->IsTypeNum ()) {
781
803
if (colp->GetColUse (U_VAR)) {
804
+ #if defined(WORDS_BIGENDIAN)
805
+ ((char *)&lg)[0 ]= ((char *)kp)[1 ];
806
+ ((char *)&lg)[1 ]= ((char *)kp)[0 ];
807
+ #else // !WORDS_BIGENDIAN
782
808
lg= *(short *)kp;
809
+ #endif // !WORDS_BIGENDIAN
783
810
kp+= sizeof (short );
784
811
rcb= valp->SetValue_char (kp, (int )lg);
785
812
} else
@@ -797,7 +824,11 @@ RCODE CntIndexRead(PGLOBAL g, PTDB ptdb, OPVAL op,
797
824
} // endif b
798
825
799
826
} else
827
+ #if defined(WORDS_BIGENDIAN)
828
+ SetSwapValue (valp, kp);
829
+ #else // !WORDS_BIGENDIAN
800
830
valp->SetBinValue ((void *)kp);
831
+ #endif // !WORDS_BIGENDIAN
801
832
802
833
kp+= valp->GetClen ();
803
834
@@ -893,7 +924,12 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
893
924
894
925
if (!valp->IsTypeNum ()) {
895
926
if (colp->GetColUse (U_VAR)) {
927
+ #if defined(WORDS_BIGENDIAN)
928
+ ((char *)&lg)[0 ]= ((char *)p)[1 ];
929
+ ((char *)&lg)[1 ]= ((char *)p)[0 ];
930
+ #else // !WORDS_BIGENDIAN
896
931
lg= *(short *)p;
932
+ #endif // !WORDS_BIGENDIAN
897
933
p+= sizeof (short );
898
934
rcb= valp->SetValue_char ((char *)p, (int )lg);
899
935
} else
@@ -912,7 +948,11 @@ int CntIndexRange(PGLOBAL g, PTDB ptdb, const uchar* *key, uint *len,
912
948
} // endif b
913
949
914
950
} else
915
- valp->SetBinValue ((void *)p);
951
+ #if defined(WORDS_BIGENDIAN)
952
+ SetSwapValue (valp, (char *)kp);
953
+ #else // !WORDS_BIGENDIAN
954
+ valp->SetBinValue ((void *)kp);
955
+ #endif // !WORDS_BIGENDIAN
916
956
917
957
if (trace) {
918
958
char bf[32 ];
0 commit comments