summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2018-02-28 23:33:45 +0000
committerTom Lane2018-02-28 23:33:45 +0000
commit43e9490866386ba57c5457c6dbeedb04a51c2086 (patch)
treeaeff75a1de83d6f95051b6d849118e388599e6e6
parent38a1144a91d207997dd68a8c2af759f88547016f (diff)
Rename base64 routines to avoid conflict with Solaris built-in functions.
Solaris 11.4 has built-in functions named b64_encode and b64_decode. Rename ours to something else to avoid the conflict (fortunately, ours are static so the impact is limited). One could wish for less duplication of code in this area, but that would be a larger patch and not very suitable for back-patching. Since this is a portability fix, we want to put it into all supported branches. Report and initial patch by Rainer Orth, reviewed and adjusted a bit by Michael Paquier Discussion: https://postgr.es/m/[email protected]
-rw-r--r--contrib/pgcrypto/pgp-armor.c20
-rw-r--r--src/backend/utils/adt/encode.c10
2 files changed, 15 insertions, 15 deletions
diff --git a/contrib/pgcrypto/pgp-armor.c b/contrib/pgcrypto/pgp-armor.c
index 5c8355808a9..aa5b563a31a 100644
--- a/contrib/pgcrypto/pgp-armor.c
+++ b/contrib/pgcrypto/pgp-armor.c
@@ -42,7 +42,7 @@ static const unsigned char _base64[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static int
-b64_encode(const uint8 *src, unsigned len, uint8 *dst)
+pg_base64_encode(const uint8 *src, unsigned len, uint8 *dst)
{
uint8 *p,
*lend = dst + 76;
@@ -92,7 +92,7 @@ b64_encode(const uint8 *src, unsigned len, uint8 *dst)
/* probably should use lookup table */
static int
-b64_decode(const uint8 *src, unsigned len, uint8 *dst)
+pg_base64_decode(const uint8 *src, unsigned len, uint8 *dst)
{
const uint8 *srcend = src + len,
*s = src;
@@ -160,7 +160,7 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
}
static unsigned
-b64_enc_len(unsigned srclen)
+pg_base64_enc_len(unsigned srclen)
{
/*
* 3 bytes will be converted to 4, linefeed after 76 chars
@@ -169,7 +169,7 @@ b64_enc_len(unsigned srclen)
}
static unsigned
-b64_dec_len(unsigned srclen)
+pg_base64_dec_len(unsigned srclen)
{
return (srclen * 3) >> 2;
}
@@ -218,11 +218,11 @@ pgp_armor_encode(const uint8 *src, unsigned len, StringInfo dst,
appendStringInfo(dst, "%s: %s\n", keys[n], values[n]);
appendStringInfoChar(dst, '\n');
- /* make sure we have enough room to b64_encode() */
- b64len = b64_enc_len(len);
+ /* make sure we have enough room to pg_base64_encode() */
+ b64len = pg_base64_enc_len(len);
enlargeStringInfo(dst, (int) b64len);
- res = b64_encode(src, len, (uint8 *) dst->data + dst->len);
+ res = pg_base64_encode(src, len, (uint8 *) dst->data + dst->len);
if (res > b64len)
elog(FATAL, "overflow - encode estimate too small");
dst->len += res;
@@ -358,14 +358,14 @@ pgp_armor_decode(const uint8 *src, int len, StringInfo dst)
goto out;
/* decode crc */
- if (b64_decode(p + 1, 4, buf) != 3)
+ if (pg_base64_decode(p + 1, 4, buf) != 3)
goto out;
crc = (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2];
/* decode data */
- blen = (int) b64_dec_len(len);
+ blen = (int) pg_base64_dec_len(len);
enlargeStringInfo(dst, blen);
- res = b64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
+ res = pg_base64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
if (res > blen)
elog(FATAL, "overflow - decode estimate too small");
if (res >= 0)
diff --git a/src/backend/utils/adt/encode.c b/src/backend/utils/adt/encode.c
index f527ee2a434..56438382f67 100644
--- a/src/backend/utils/adt/encode.c
+++ b/src/backend/utils/adt/encode.c
@@ -215,7 +215,7 @@ static const int8 b64lookup[128] = {
};
static unsigned
-b64_encode(const char *src, unsigned len, char *dst)
+pg_base64_encode(const char *src, unsigned len, char *dst)
{
char *p,
*lend = dst + 76;
@@ -262,7 +262,7 @@ b64_encode(const char *src, unsigned len, char *dst)
}
static unsigned
-b64_decode(const char *src, unsigned len, char *dst)
+pg_base64_decode(const char *src, unsigned len, char *dst)
{
const char *srcend = src + len,
*s = src;
@@ -332,14 +332,14 @@ b64_decode(const char *src, unsigned len, char *dst)
static unsigned
-b64_enc_len(const char *src, unsigned srclen)
+pg_base64_enc_len(const char *src, unsigned srclen)
{
/* 3 bytes will be converted to 4, linefeed after 76 chars */
return (srclen + 2) * 4 / 3 + srclen / (76 * 3 / 4);
}
static unsigned
-b64_dec_len(const char *src, unsigned srclen)
+pg_base64_dec_len(const char *src, unsigned srclen)
{
return (srclen * 3) >> 2;
}
@@ -532,7 +532,7 @@ static const struct
{
"base64",
{
- b64_enc_len, b64_dec_len, b64_encode, b64_decode
+ pg_base64_enc_len, pg_base64_dec_len, pg_base64_encode, pg_base64_decode
}
},
{