Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit3ded6fd

Browse files
author
Thomas G. Lockhart
committed
Fix code to do the right thing with mixed-endian clients and servers.
1 parentbf3bcb6 commit3ded6fd

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

‎src/backend/libpq/pqcomprim.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@
1010

1111

1212
/* --------------------------------------------------------------------- */
13-
/* Is the other way around than system ntoh/hton, so we roll our own
14-
here */
15-
16-
#ifndefBYTE_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+
#ifndefBYTE_ORDER
1718
#error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN
1819
#endif
1920

@@ -24,11 +25,13 @@
2425
# definehton_l(n) n
2526
#else/* BYTE_ORDER != LITTLE_ENDIAN */
2627
# ifBYTE_ORDER==BIG_ENDIAN
27-
# definentoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1])
28-
# definentoh_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-
# definehton_s(n) (u_short)(((u_char *) &n)[2] << 8 | ((u_char *) &n)[3])
28+
# definentoh_s(n) (u_short)(((u_char *)&n)[1] << 8 \
29+
| ((u_char *)&n)[0])
30+
# definentoh_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+
# definehton_s(n) (ntoh_s(n))
3235
# definehton_l(n) (ntoh_l(n))
3336
# else/* BYTE_ORDER != BIG_ENDIAN */
3437
# ifBYTE_ORDER==PDP_ENDIAN
@@ -43,9 +46,10 @@
4346
intpqPutShort(intinteger,FILE*f)
4447
{
4548
intretval=0;
46-
u_shortn;
49+
u_shortn,s;
4750

48-
n=hton_s(integer);
51+
s=integer;
52+
n=hton_s(s);
4953
if(fwrite(&n,sizeof(u_short),1,f)!=1)
5054
retval=EOF;
5155

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp