Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit bf872f0

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

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-
#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
{
3340
int retval = 0;
3441
u_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
{
4653
int retval = 0;
4754
u_long n;
@@ -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-
int pqGetNBytes(char* s, const int len, FILE *f)
93+
int pqGetNBytes(char *s, size_t len, FILE *f)
8794
{
8895
int 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
{
103110
if (f == NULL)
104111
return 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
{
115122
int 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
{
152159
if(!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-
/* --------------------------------------------------------------------- */

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
int pqGetShort(int *, FILE *);
128128
int pqGetLong(int *, FILE *);
129+
int pqGetNBytes(char *, size_t, FILE *);
130+
int pqGetString(char *, size_t, FILE *);
131+
int pqGetByte(FILE *);
132+
129133
int pqPutShort(int, FILE *);
130134
int pqPutLong(int, FILE *);
135+
int pqPutNBytes(const char *, size_t, FILE *);
136+
int pqPutString(const char *, FILE *);
137+
int pqPutByte(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
# define SYSV_DIRENT
55
# define HAS_TEST_AND_SET
66
typedef unsigned char slock_t;
7+
8+
#ifndef BYTE_ORDER
9+
#define BYTE_ORDER BIG_ENDIAN
10+
#endif

0 commit comments

Comments
 (0)