mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
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.
This commit is contained in:
parent
7d5770eaf2
commit
bf872f0aff
@ -7,7 +7,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.13 1997/03/18 20:14:33 scrappy Exp $
|
||||
* $Header: /cvsroot/pgsql/src/backend/libpq/pqcomm.c,v 1.14 1997/03/20 18:21:35 scrappy Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@ -217,7 +217,7 @@ int PQgetline(char *s, int maxlen)
|
||||
}
|
||||
else
|
||||
{
|
||||
for( ; *s; *s++)
|
||||
for( ; *s; s++)
|
||||
{
|
||||
if(*s == '\n')
|
||||
{
|
||||
|
@ -8,27 +8,34 @@
|
||||
/* Is the other way around than system ntoh/hton, so we roll our own
|
||||
here */
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define ntoh_s(n) n
|
||||
#define ntoh_l(n) n
|
||||
#define hton_s(n) n
|
||||
#define hton_l(n) n
|
||||
#endif
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
|
||||
#define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
|
||||
((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
|
||||
#define hton_s(n) (ntoh_s(n))
|
||||
#define hton_l(n) (ntoh_l(n))
|
||||
#endif
|
||||
#if BYTE_ORDER == PDP_ENDIAN
|
||||
#endif
|
||||
#ifndef ntoh_s
|
||||
#error Please write byte order macros
|
||||
#ifndef BYTE_ORDER
|
||||
#error BYTE_ORDER must be defined as LITTLE_ENDIAN, BIG_ENDIAN or PDP_ENDIAN
|
||||
#endif
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
# define ntoh_s(n) n
|
||||
# define ntoh_l(n) n
|
||||
# define hton_s(n) n
|
||||
# define hton_l(n) n
|
||||
#else /* BYTE_ORDER != LITTLE_ENDIAN */
|
||||
# if BYTE_ORDER == BIG_ENDIAN
|
||||
# define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
|
||||
# define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | \
|
||||
((u_char *)&n)[1] << 16 | \
|
||||
((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
|
||||
# define hton_s(n) (ntoh_s(n))
|
||||
# define hton_l(n) (ntoh_l(n))
|
||||
# else /* BYTE_ORDER != BIG_ENDIAN */
|
||||
# if BYTE_ORDER == PDP_ENDIAN
|
||||
# #error PDP_ENDIAN macros not written yet
|
||||
# else /* BYTE_ORDER != anything known */
|
||||
# #error BYTE_ORDER not defined as anything understood
|
||||
# endif /* BYTE_ORDER == PDP_ENDIAN */
|
||||
# endif /* BYTE_ORDER == BIG_ENDIAN */
|
||||
#endif /* BYTE_ORDER == LITTLE_ENDIAN */
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutShort(const int integer, FILE *f)
|
||||
int pqPutShort(int integer, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_short n;
|
||||
@ -41,7 +48,7 @@ int pqPutShort(const int integer, FILE *f)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutLong(const int integer, FILE *f)
|
||||
int pqPutLong(int integer, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_long n;
|
||||
@ -83,7 +90,7 @@ int pqGetLong(int *result, FILE *f)
|
||||
/* pqGetNBytes: Read a chunk of exactly len bytes in buffer s.
|
||||
Return 0 if ok.
|
||||
*/
|
||||
int pqGetNBytes(char* s, const int len, FILE *f)
|
||||
int pqGetNBytes(char *s, size_t len, FILE *f)
|
||||
{
|
||||
int cnt;
|
||||
|
||||
@ -98,7 +105,7 @@ int pqGetNBytes(char* s, const int len, FILE *f)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutNBytes(const char *s, const int len, FILE *f)
|
||||
int pqPutNBytes(const char *s, size_t len, FILE *f)
|
||||
{
|
||||
if (f == NULL)
|
||||
return 0;
|
||||
@ -110,7 +117,7 @@ int pqPutNBytes(const char *s, const int len, FILE *f)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqGetString(char *s, int len, FILE *f)
|
||||
int pqGetString(char *s, size_t len, FILE *f)
|
||||
{
|
||||
int c;
|
||||
|
||||
@ -147,7 +154,7 @@ int pqGetByte(FILE *f)
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutByte(const int c, FILE *f)
|
||||
int pqPutByte(int c, FILE *f)
|
||||
{
|
||||
if(!f) return 0;
|
||||
|
||||
@ -156,85 +163,3 @@ int pqPutByte(const int c, FILE *f)
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "postgres.h"
|
||||
#include "libpq/pqcomm.h"
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
/* Is the other way around than system ntoh/hton, so we roll our own
|
||||
here */
|
||||
|
||||
#if BYTE_ORDER == LITTLE_ENDIAN
|
||||
#define ntoh_s(n) n
|
||||
#define ntoh_l(n) n
|
||||
#define hton_s(n) n
|
||||
#define hton_l(n) n
|
||||
#endif
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
#define ntoh_s(n) (u_short)(((u_char *) &n)[0] << 8 | ((u_char *) &n)[1]);
|
||||
#define ntoh_l(n) (u_long)(((u_char *)&n)[0] << 24 | ((u_char *)&n)[1] << 16 |\
|
||||
((u_char *)&n)[2] << 8 | ((u_char *)&n)[3]);
|
||||
#define hton_s(n) (ntoh_s(n))
|
||||
#define hton_l(n) (ntoh_l(n))
|
||||
#endif
|
||||
#if BYTE_ORDER == PDP_ENDIAN
|
||||
#endif
|
||||
#ifndef ntoh_s
|
||||
#error Please write byte order macros
|
||||
#endif
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutShort(const int integer, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_short n;
|
||||
|
||||
n = hton_s(integer);
|
||||
if(fwrite(&n, sizeof(u_short), 1, f) != 1)
|
||||
retval = 1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqPutLong(const int integer, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_long n;
|
||||
|
||||
n = hton_l(integer);
|
||||
if(fwrite(&n, sizeof(u_long), 1, f) != 1)
|
||||
retval = 1;
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqGetShort(int *result, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_short n;
|
||||
|
||||
if(fread(&n, sizeof(u_short), 1, f) != 1)
|
||||
retval = 1;
|
||||
|
||||
*result = ntoh_s(n);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
int pqGetLong(int *result, FILE *f)
|
||||
{
|
||||
int retval = 0;
|
||||
u_long n;
|
||||
|
||||
if(fread(&n, sizeof(u_long), 1, f) != 1)
|
||||
retval = 1;
|
||||
|
||||
*result = ntoh_l(n);
|
||||
return retval;
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------- */
|
||||
|
@ -6,7 +6,7 @@
|
||||
*
|
||||
* Copyright (c) 1994, Regents of the University of California
|
||||
*
|
||||
* $Id: pqcomm.h,v 1.9 1997/03/16 18:50:47 scrappy Exp $
|
||||
* $Id: pqcomm.h,v 1.10 1997/03/20 18:23:03 scrappy Exp $
|
||||
*
|
||||
* NOTES
|
||||
* Some of this should move to libpq.h
|
||||
@ -126,8 +126,16 @@ extern int PQAsyncNotifyWaiting;
|
||||
/* in pqcompriv.c */
|
||||
int pqGetShort(int *, FILE *);
|
||||
int pqGetLong(int *, FILE *);
|
||||
int pqGetNBytes(char *, size_t, FILE *);
|
||||
int pqGetString(char *, size_t, FILE *);
|
||||
int pqGetByte(FILE *);
|
||||
|
||||
int pqPutShort(int, FILE *);
|
||||
int pqPutLong(int, FILE *);
|
||||
int pqPutNBytes(const char *, size_t, FILE *);
|
||||
int pqPutString(const char *, FILE *);
|
||||
int pqPutByte(int, FILE *);
|
||||
|
||||
/*
|
||||
* prototypes for functions in pqpacket.c
|
||||
*/
|
||||
|
@ -4,3 +4,7 @@
|
||||
# define SYSV_DIRENT
|
||||
# define HAS_TEST_AND_SET
|
||||
typedef unsigned char slock_t;
|
||||
|
||||
#ifndef BYTE_ORDER
|
||||
#define BYTE_ORDER BIG_ENDIAN
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user