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

Commitbf872f0

Browse files
committed
From: "D'Arcy J.M. Cain" <darcy@druid.net>
Subject: [HACKERS] libpq/pqcomm stuff and Solaris byte orderI decided to go ahead with the required changes since no one else seemsto. I don't guarantee that it is perfect but with these changes thepackage actually compiles. While I was at it I added to the SparcSolaris header to define the byte order. Note that NetBSD sets thisin the system headers so it wasn't required there.In particular, someone may want to check whether I removed the correct84 lines from backend/libpq/pqcomprim.c.
1 parent7d5770e commitbf872f0

File tree

4 files changed

+46
-109
lines changed

4 files changed

+46
-109
lines changed

‎src/backend/libpq/pqcomm.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
*
99
* IDENTIFICATION
10-
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.13 1997/03/18 20:14:33 scrappy Exp $
10+
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.14 1997/03/20 18:21:35 scrappy Exp $
1111
*
1212
*-------------------------------------------------------------------------
1313
*/
@@ -217,7 +217,7 @@ int PQgetline(char *s, int maxlen)
217217
}
218218
else
219219
{
220-
for( ;*s;*s++)
220+
for( ;*s;s++)
221221
{
222222
if(*s=='\n')
223223
{

‎src/backend/libpq/pqcomprim.c

Lines changed: 31 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,34 @@
88
/* Is the other way around than system ntoh/hton, so we roll our own
99
here */
1010

11-
#ifBYTE_ORDER==LITTLE_ENDIAN
12-
#definentoh_s(n) n
13-
#definentoh_l(n) n
14-
#definehton_s(n) n
15-
#definehton_l(n) n
16-
#endif
17-
#ifBYTE_ORDER==BIG_ENDIAN
18-
#definentoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
19-
#definentoh_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-
#definehton_s(n) (ntoh_s(n))
22-
#definehton_l(n) (ntoh_l(n))
23-
#endif
24-
#ifBYTE_ORDER==PDP_ENDIAN
25-
#endif
26-
#ifndefntoh_s
27-
#error Please write byte order macros
11+
#ifndefBYTE_ORDER
12+
#error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN
2813
#endif
2914

30-
/* --------------------------------------------------------------------- */
31-
intpqPutShort(constintinteger,FILE*f)
15+
#ifBYTE_ORDER==LITTLE_ENDIAN
16+
# definentoh_s(n) n
17+
# definentoh_l(n) n
18+
# definehton_s(n) n
19+
# definehton_l(n) n
20+
#else/* BYTE_ORDER != LITTLE_ENDIAN */
21+
# ifBYTE_ORDER==BIG_ENDIAN
22+
# definentoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
23+
# definentoh_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+
# definehton_s(n) (ntoh_s(n))
27+
# definehton_l(n) (ntoh_l(n))
28+
# else/* BYTE_ORDER != BIG_ENDIAN */
29+
# ifBYTE_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+
intpqPutShort(intinteger,FILE*f)
3239
{
3340
intretval=0;
3441
u_shortn;
@@ -41,7 +48,7 @@ int pqPutShort(const int integer, FILE *f)
4148
}
4249

4350
/* --------------------------------------------------------------------- */
44-
intpqPutLong(constintinteger,FILE*f)
51+
intpqPutLong(intinteger,FILE*f)
4552
{
4653
intretval=0;
4754
u_longn;
@@ -83,7 +90,7 @@ int pqGetLong(int *result, FILE *f)
8390
/* pqGetNBytes: Read a chunk of exactly len bytes in buffer s.
8491
Return 0 if ok.
8592
*/
86-
intpqGetNBytes(char*s,constintlen,FILE*f)
93+
intpqGetNBytes(char*s,size_tlen,FILE*f)
8794
{
8895
intcnt;
8996

@@ -98,7 +105,7 @@ int pqGetNBytes(char* s, const int len, FILE *f)
98105
}
99106

100107
/* --------------------------------------------------------------------- */
101-
intpqPutNBytes(constchar*s,constintlen,FILE*f)
108+
intpqPutNBytes(constchar*s,size_tlen,FILE*f)
102109
{
103110
if (f==NULL)
104111
return0;
@@ -110,7 +117,7 @@ int pqPutNBytes(const char *s, const int len, FILE *f)
110117
}
111118

112119
/* --------------------------------------------------------------------- */
113-
intpqGetString(char*s,intlen,FILE*f)
120+
intpqGetString(char*s,size_tlen,FILE*f)
114121
{
115122
intc;
116123

@@ -147,7 +154,7 @@ int pqGetByte(FILE *f)
147154
}
148155

149156
/* --------------------------------------------------------------------- */
150-
intpqPutByte(constintc,FILE*f)
157+
intpqPutByte(intc,FILE*f)
151158
{
152159
if(!f)return0;
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-
#ifBYTE_ORDER==LITTLE_ENDIAN
170-
#definentoh_s(n) n
171-
#definentoh_l(n) n
172-
#definehton_s(n) n
173-
#definehton_l(n) n
174-
#endif
175-
#ifBYTE_ORDER==BIG_ENDIAN
176-
#definentoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
177-
#definentoh_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-
#definehton_s(n) (ntoh_s(n))
180-
#definehton_l(n) (ntoh_l(n))
181-
#endif
182-
#ifBYTE_ORDER==PDP_ENDIAN
183-
#endif
184-
#ifndefntoh_s
185-
#error Please write byte order macros
186-
#endif
187-
188-
/* --------------------------------------------------------------------- */
189-
intpqPutShort(constintinteger,FILE*f)
190-
{
191-
intretval=0;
192-
u_shortn;
193-
194-
n=hton_s(integer);
195-
if(fwrite(&n,sizeof(u_short),1,f)!=1)
196-
retval=1;
197-
198-
returnretval;
199-
}
200-
201-
/* --------------------------------------------------------------------- */
202-
intpqPutLong(constintinteger,FILE*f)
203-
{
204-
intretval=0;
205-
u_longn;
206-
207-
n=hton_l(integer);
208-
if(fwrite(&n,sizeof(u_long),1,f)!=1)
209-
retval=1;
210-
211-
returnretval;
212-
}
213-
214-
/* --------------------------------------------------------------------- */
215-
intpqGetShort(int*result,FILE*f)
216-
{
217-
intretval=0;
218-
u_shortn;
219-
220-
if(fread(&n,sizeof(u_short),1,f)!=1)
221-
retval=1;
222-
223-
*result=ntoh_s(n);
224-
returnretval;
225-
}
226-
227-
/* --------------------------------------------------------------------- */
228-
intpqGetLong(int*result,FILE*f)
229-
{
230-
intretval=0;
231-
u_longn;
232-
233-
if(fread(&n,sizeof(u_long),1,f)!=1)
234-
retval=1;
235-
236-
*result=ntoh_l(n);
237-
returnretval;
238-
}
239-
240-
/* --------------------------------------------------------------------- */

‎src/include/libpq/pqcomm.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Copyright (c) 1994, Regents of the University of California
88
*
9-
* $Id: pqcomm.h,v 1.9 1997/03/16 18:50:47 scrappy Exp $
9+
* $Id: pqcomm.h,v 1.10 1997/03/20 18:23:03 scrappy Exp $
1010
*
1111
* NOTES
1212
* Some of this should move to libpq.h
@@ -126,8 +126,16 @@ extern int PQAsyncNotifyWaiting;
126126
/* in pqcompriv.c */
127127
intpqGetShort(int*,FILE*);
128128
intpqGetLong(int*,FILE*);
129+
intpqGetNBytes(char*,size_t,FILE*);
130+
intpqGetString(char*,size_t,FILE*);
131+
intpqGetByte(FILE*);
132+
129133
intpqPutShort(int,FILE*);
130134
intpqPutLong(int,FILE*);
135+
intpqPutNBytes(constchar*,size_t,FILE*);
136+
intpqPutString(constchar*,FILE*);
137+
intpqPutByte(int,FILE*);
138+
131139
/*
132140
* prototypes for functions in pqpacket.c
133141
*/

‎src/port/sparc_solaris.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,7 @@
44
# defineSYSV_DIRENT
55
# defineHAS_TEST_AND_SET
66
typedefunsignedcharslock_t;
7+
8+
#ifndefBYTE_ORDER
9+
#defineBYTE_ORDERBIG_ENDIAN
10+
#endif

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp