File tree 1 file changed +15
-11
lines changed
1 file changed +15
-11
lines changed Original file line number Diff line number Diff line change 10
10
11
11
12
12
/* --------------------------------------------------------------------- */
13
- /* Is the other way around than system ntoh/hton, so we roll our own
14
- here */
15
-
16
- #ifndef BYTE_ORDER
13
+ /* These definitions for ntoh/hton are the other way around from the
14
+ * default system definitions, so we roll our own here.
15
+ */
16
+
17
+ #ifndef BYTE_ORDER
17
18
#error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN
18
19
#endif
19
20
24
25
# define hton_l (n ) n
25
26
#else /* BYTE_ORDER != LITTLE_ENDIAN */
26
27
# if BYTE_ORDER == BIG_ENDIAN
27
- # define ntoh_s (n ) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1])
28
- # define ntoh_l (n ) (u_long)(((u_char *)&n)[0] << 24 | \
29
- ((u_char *)&n)[1] << 16 | \
30
- ((u_char *)&n)[2] << 8 | ((u_char *)&n)[3])
31
- # define hton_s (n ) (u_short)(((u_char *) &n)[2] << 8 | ((u_char *) &n)[3])
28
+ # define ntoh_s (n ) (u_short)(((u_char *)&n)[1] << 8 \
29
+ | ((u_char *)&n)[0])
30
+ # define ntoh_l (n ) (u_long) (((u_char *)&n)[3] << 24 \
31
+ | ((u_char *)&n)[2] << 16 \
32
+ | ((u_char *)&n)[1] << 8 \
33
+ | ((u_char *)&n)[0])
34
+ # define hton_s (n ) (ntoh_s(n))
32
35
# define hton_l (n ) (ntoh_l(n))
33
36
# else /* BYTE_ORDER != BIG_ENDIAN */
34
37
# if BYTE_ORDER == PDP_ENDIAN
43
46
int pqPutShort (int integer , FILE * f )
44
47
{
45
48
int retval = 0 ;
46
- u_short n ;
49
+ u_short n , s ;
47
50
48
- n = hton_s (integer );
51
+ s = integer ;
52
+ n = hton_s (s );
49
53
if (fwrite (& n , sizeof (u_short ), 1 , f ) != 1 )
50
54
retval = EOF ;
51
55
You can’t perform that action at this time.
0 commit comments