88/* Is the other way around than system ntoh/hton, so we roll our own
99here */
1010
11- #if BYTE_ORDER == LITTLE_ENDIAN
12- #define ntoh_s (n ) n
13- #define ntoh_l (n ) n
14- #define hton_s (n ) n
15- #define hton_l (n ) n
16- #endif
17- #if BYTE_ORDER == BIG_ENDIAN
18- #define ntoh_s (n ) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
19- #define ntoh_l (n ) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
20- ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
21- #define hton_s (n ) (ntoh_s(n))
22- #define hton_l (n ) (ntoh_l(n))
23- #endif
24- #if BYTE_ORDER == PDP_ENDIAN
25- #endif
26- #ifndef ntoh_s
27- #error Please write byte order macros
11+ #ifndef BYTE_ORDER
12+ #error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN
2813#endif
2914
30- /* --------------------------------------------------------------------- */
31- int pqPutShort (const int integer ,FILE * f )
15+ #if BYTE_ORDER == LITTLE_ENDIAN
16+ # define ntoh_s (n ) n
17+ # define ntoh_l (n ) n
18+ # define hton_s (n ) n
19+ # define hton_l (n ) n
20+ #else /* BYTE_ORDER != LITTLE_ENDIAN */
21+ # if BYTE_ORDER == BIG_ENDIAN
22+ # define ntoh_s (n ) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
23+ # define ntoh_l (n ) (u_long)(((u_char *)&n)[0] << 24 | \
24+ ((u_char *)&n)[1] << 16 | \
25+ ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
26+ # define hton_s (n ) (ntoh_s(n))
27+ # define hton_l (n ) (ntoh_l(n))
28+ # else /* BYTE_ORDER != BIG_ENDIAN */
29+ # if BYTE_ORDER == PDP_ENDIAN
30+ ##error PDP_ENDIAN macros not written yet
31+ # else /* BYTE_ORDER != anything known */
32+ ##error BYTE_ORDER not defined as anything understood
33+ # endif /* BYTE_ORDER == PDP_ENDIAN */
34+ # endif /* BYTE_ORDER == BIG_ENDIAN */
35+ #endif /* BYTE_ORDER == LITTLE_ENDIAN */
36+
37+ /* --------------------------------------------------------------------- */
38+ int pqPutShort (int integer ,FILE * f )
3239 {
3340int retval = 0 ;
3441u_short n ;
@@ -41,7 +48,7 @@ int pqPutShort(const int integer, FILE *f)
4148 }
4249
4350/* --------------------------------------------------------------------- */
44- int pqPutLong (const int integer ,FILE * f )
51+ int pqPutLong (int integer ,FILE * f )
4552 {
4653int retval = 0 ;
4754u_long n ;
@@ -83,7 +90,7 @@ int pqGetLong(int *result, FILE *f)
8390/* pqGetNBytes: Read a chunk of exactly len bytes in buffer s.
8491Return 0 if ok.
8592*/
86- int pqGetNBytes (char * s ,const int len ,FILE * f )
93+ int pqGetNBytes (char * s ,size_t len ,FILE * f )
8794{
8895int cnt ;
8996
@@ -98,7 +105,7 @@ int pqGetNBytes(char* s, const int len, FILE *f)
98105}
99106
100107/* --------------------------------------------------------------------- */
101- int pqPutNBytes (const char * s ,const int len ,FILE * f )
108+ int pqPutNBytes (const char * s ,size_t len ,FILE * f )
102109{
103110if (f == NULL )
104111return 0 ;
@@ -110,7 +117,7 @@ int pqPutNBytes(const char *s, const int len, FILE *f)
110117}
111118
112119/* --------------------------------------------------------------------- */
113- int pqGetString (char * s ,int len ,FILE * f )
120+ int pqGetString (char * s ,size_t len ,FILE * f )
114121{
115122int c ;
116123
@@ -147,7 +154,7 @@ int pqGetByte(FILE *f)
147154}
148155
149156/* --------------------------------------------------------------------- */
150- int pqPutByte (const int c ,FILE * f )
157+ int pqPutByte (int c ,FILE * f )
151158{
152159if (!f )return 0 ;
153160
@@ -156,85 +163,3 @@ int pqPutByte(const int c, FILE *f)
156163
157164/* --------------------------------------------------------------------- */
158165
159- #include <stdlib.h>
160- #include <stdio.h>
161-
162- #include "postgres.h"
163- #include "libpq/pqcomm.h"
164-
165- /* --------------------------------------------------------------------- */
166- /* Is the other way around than system ntoh/hton, so we roll our own
167- here */
168-
169- #if BYTE_ORDER == LITTLE_ENDIAN
170- #define ntoh_s (n ) n
171- #define ntoh_l (n ) n
172- #define hton_s (n ) n
173- #define hton_l (n ) n
174- #endif
175- #if BYTE_ORDER == BIG_ENDIAN
176- #define ntoh_s (n ) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
177- #define ntoh_l (n ) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
178- ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
179- #define hton_s (n ) (ntoh_s(n))
180- #define hton_l (n ) (ntoh_l(n))
181- #endif
182- #if BYTE_ORDER == PDP_ENDIAN
183- #endif
184- #ifndef ntoh_s
185- #error Please write byte order macros
186- #endif
187-
188- /* --------------------------------------------------------------------- */
189- int pqPutShort (const int integer ,FILE * f )
190- {
191- int retval = 0 ;
192- u_short n ;
193-
194- n = hton_s (integer );
195- if (fwrite (& n ,sizeof (u_short ),1 ,f )!= 1 )
196- retval = 1 ;
197-
198- return retval ;
199- }
200-
201- /* --------------------------------------------------------------------- */
202- int pqPutLong (const int integer ,FILE * f )
203- {
204- int retval = 0 ;
205- u_long n ;
206-
207- n = hton_l (integer );
208- if (fwrite (& n ,sizeof (u_long ),1 ,f )!= 1 )
209- retval = 1 ;
210-
211- return retval ;
212- }
213-
214- /* --------------------------------------------------------------------- */
215- int pqGetShort (int * result ,FILE * f )
216- {
217- int retval = 0 ;
218- u_short n ;
219-
220- if (fread (& n ,sizeof (u_short ),1 ,f )!= 1 )
221- retval = 1 ;
222-
223- * result = ntoh_s (n );
224- return retval ;
225- }
226-
227- /* --------------------------------------------------------------------- */
228- int pqGetLong (int * result ,FILE * f )
229- {
230- int retval = 0 ;
231- u_long n ;
232-
233- if (fread (& n ,sizeof (u_long ),1 ,f )!= 1 )
234- retval = 1 ;
235-
236- * result = ntoh_l (n );
237- return retval ;
238- }
239-
240- /* --------------------------------------------------------------------- */