summaryrefslogtreecommitdiff
path: root/src/interfaces/libpq/fe-misc.c
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2017-10-01 15:36:14 -0700
committerAndres Freund <andres@anarazel.de>2017-10-01 15:36:14 -0700
commit0ba99c84e8c7138143059b281063d4cca5a2bfea (patch)
tree521367c1888ca186fa229efc3489fb4298c8dc08 /src/interfaces/libpq/fe-misc.c
parent1f2830f9df9f0196ba541c1e253463afe657cb67 (diff)
downloadpostgresql-0ba99c84e8c7138143059b281063d4cca5a2bfea.tar.gz
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
Diffstat (limited to 'src/interfaces/libpq/fe-misc.c')
-rw-r--r--src/interfaces/libpq/fe-misc.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/interfaces/libpq/fe-misc.c b/src/interfaces/libpq/fe-misc.c
index cac6359585..41b1749d07 100644
--- a/src/interfaces/libpq/fe-misc.c
+++ b/src/interfaces/libpq/fe-misc.c
@@ -33,9 +33,6 @@
#include <signal.h>
#include <time.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
#ifdef WIN32
#include "win32.h"
#else
@@ -53,6 +50,7 @@
#include "libpq-fe.h"
#include "libpq-int.h"
#include "mb/pg_wchar.h"
+#include "port/pg_bswap.h"
#include "pg_config_paths.h"
@@ -278,14 +276,14 @@ pqGetInt(int *result, size_t bytes, PGconn *conn)
return EOF;
memcpy(&tmp2, conn->inBuffer + conn->inCursor, 2);
conn->inCursor += 2;
- *result = (int) ntohs(tmp2);
+ *result = (int) pg_ntoh16(tmp2);
break;
case 4:
if (conn->inCursor + 4 > conn->inEnd)
return EOF;
memcpy(&tmp4, conn->inBuffer + conn->inCursor, 4);
conn->inCursor += 4;
- *result = (int) ntohl(tmp4);
+ *result = (int) pg_ntoh32(tmp4);
break;
default:
pqInternalNotice(&conn->noticeHooks,
@@ -314,12 +312,12 @@ pqPutInt(int value, size_t bytes, PGconn *conn)
switch (bytes)
{
case 2:
- tmp2 = htons((uint16) value);
+ tmp2 = pg_hton16((uint16) value);
if (pqPutMsgBytes((const char *) &tmp2, 2, conn))
return EOF;
break;
case 4:
- tmp4 = htonl((uint32) value);
+ tmp4 = pg_hton32((uint32) value);
if (pqPutMsgBytes((const char *) &tmp4, 4, conn))
return EOF;
break;
@@ -597,7 +595,7 @@ pqPutMsgEnd(PGconn *conn)
{
uint32 msgLen = conn->outMsgEnd - conn->outMsgStart;
- msgLen = htonl(msgLen);
+ msgLen = pg_hton32(msgLen);
memcpy(conn->outBuffer + conn->outMsgStart, &msgLen, 4);
}