mirror of
https://github.com/postgres/postgres.git
synced 2025-08-22 21:53:06 +03:00
Replace most usages of ntoh[ls] and hton[sl] with pg_bswap.h.
All postgres internal usages are replaced, it's just libpq example usages that haven't been converted. External users of libpq can't generally rely on including postgres internal headers. Note that this includes replacing open-coded byte swapping of 64bit integers (using two 32 bit swaps) with a single 64bit swap. Where it looked applicable, I have removed netinet/in.h and arpa/inet.h usage, which previously provided the relevant functionality. It's perfectly possible that I missed other reasons for including those, the buildfarm will tell. Author: Andres Freund Discussion: https://postgr.es/m/20170927172019.gheidqy6xvlxb325@alap3.anarazel.de
This commit is contained in:
@@ -17,18 +17,15 @@
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* for ntohl/htonl */
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
|
||||
/* local includes */
|
||||
#include "receivelog.h"
|
||||
#include "streamutil.h"
|
||||
|
||||
#include "access/xlog_internal.h"
|
||||
#include "pqexpbuffer.h"
|
||||
#include "common/fe_memutils.h"
|
||||
#include "datatype/timestamp.h"
|
||||
#include "port/pg_bswap.h"
|
||||
#include "pqexpbuffer.h"
|
||||
|
||||
#define ERRCODE_DUPLICATE_OBJECT "42710"
|
||||
|
||||
@@ -576,17 +573,9 @@ feTimestampDifferenceExceeds(TimestampTz start_time,
|
||||
void
|
||||
fe_sendint64(int64 i, char *buf)
|
||||
{
|
||||
uint32 n32;
|
||||
uint64 n64 = pg_hton64(i);
|
||||
|
||||
/* High order half first, since we're doing MSB-first */
|
||||
n32 = (uint32) (i >> 32);
|
||||
n32 = htonl(n32);
|
||||
memcpy(&buf[0], &n32, 4);
|
||||
|
||||
/* Now the low order half */
|
||||
n32 = (uint32) i;
|
||||
n32 = htonl(n32);
|
||||
memcpy(&buf[4], &n32, 4);
|
||||
memcpy(buf, &n64, sizeof(n64));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -595,18 +584,9 @@ fe_sendint64(int64 i, char *buf)
|
||||
int64
|
||||
fe_recvint64(char *buf)
|
||||
{
|
||||
int64 result;
|
||||
uint32 h32;
|
||||
uint32 l32;
|
||||
uint64 n64;
|
||||
|
||||
memcpy(&h32, buf, 4);
|
||||
memcpy(&l32, buf + 4, 4);
|
||||
h32 = ntohl(h32);
|
||||
l32 = ntohl(l32);
|
||||
memcpy(&n64, buf, sizeof(n64));
|
||||
|
||||
result = h32;
|
||||
result <<= 32;
|
||||
result |= l32;
|
||||
|
||||
return result;
|
||||
return pg_ntoh64(n64);
|
||||
}
|
||||
|
Reference in New Issue
Block a user