8
8
/* Is the other way around than system ntoh/hton, so we roll our own
9
9
here */
10
10
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
28
13
#endif
29
14
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 )
32
39
{
33
40
int retval = 0 ;
34
41
u_short n ;
@@ -41,7 +48,7 @@ int pqPutShort(const int integer, FILE *f)
41
48
}
42
49
43
50
/* --------------------------------------------------------------------- */
44
- int pqPutLong (const int integer , FILE * f )
51
+ int pqPutLong (int integer , FILE * f )
45
52
{
46
53
int retval = 0 ;
47
54
u_long n ;
@@ -83,7 +90,7 @@ int pqGetLong(int *result, FILE *f)
83
90
/* pqGetNBytes: Read a chunk of exactly len bytes in buffer s.
84
91
Return 0 if ok.
85
92
*/
86
- int pqGetNBytes (char * s , const int len , FILE * f )
93
+ int pqGetNBytes (char * s , size_t len , FILE * f )
87
94
{
88
95
int cnt ;
89
96
@@ -98,7 +105,7 @@ int pqGetNBytes(char* s, const int len, FILE *f)
98
105
}
99
106
100
107
/* --------------------------------------------------------------------- */
101
- int pqPutNBytes (const char * s , const int len , FILE * f )
108
+ int pqPutNBytes (const char * s , size_t len , FILE * f )
102
109
{
103
110
if (f == NULL )
104
111
return 0 ;
@@ -110,7 +117,7 @@ int pqPutNBytes(const char *s, const int len, FILE *f)
110
117
}
111
118
112
119
/* --------------------------------------------------------------------- */
113
- int pqGetString (char * s , int len , FILE * f )
120
+ int pqGetString (char * s , size_t len , FILE * f )
114
121
{
115
122
int c ;
116
123
@@ -147,7 +154,7 @@ int pqGetByte(FILE *f)
147
154
}
148
155
149
156
/* --------------------------------------------------------------------- */
150
- int pqPutByte (const int c , FILE * f )
157
+ int pqPutByte (int c , FILE * f )
151
158
{
152
159
if (!f ) return 0 ;
153
160
@@ -156,85 +163,3 @@ int pqPutByte(const int c, FILE *f)
156
163
157
164
/* --------------------------------------------------------------------- */
158
165
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
- /* --------------------------------------------------------------------- */
0 commit comments