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

Commit 43e9490

Browse files
committed
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/ydd372wk28h.fsf@CeBiTec.Uni-Bielefeld.DE
1 parent 38a1144 commit 43e9490

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

contrib/pgcrypto/pgp-armor.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ static const unsigned char _base64[] =
4242
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
4343

4444
static int
45-
b64_encode(const uint8 *src, unsigned len, uint8 *dst)
45+
pg_base64_encode(const uint8 *src, unsigned len, uint8 *dst)
4646
{
4747
uint8 *p,
4848
*lend = dst + 76;
@@ -92,7 +92,7 @@ b64_encode(const uint8 *src, unsigned len, uint8 *dst)
9292

9393
/* probably should use lookup table */
9494
static int
95-
b64_decode(const uint8 *src, unsigned len, uint8 *dst)
95+
pg_base64_decode(const uint8 *src, unsigned len, uint8 *dst)
9696
{
9797
const uint8 *srcend = src + len,
9898
*s = src;
@@ -160,7 +160,7 @@ b64_decode(const uint8 *src, unsigned len, uint8 *dst)
160160
}
161161

162162
static unsigned
163-
b64_enc_len(unsigned srclen)
163+
pg_base64_enc_len(unsigned srclen)
164164
{
165165
/*
166166
* 3 bytes will be converted to 4, linefeed after 76 chars
@@ -169,7 +169,7 @@ b64_enc_len(unsigned srclen)
169169
}
170170

171171
static unsigned
172-
b64_dec_len(unsigned srclen)
172+
pg_base64_dec_len(unsigned srclen)
173173
{
174174
return (srclen * 3) >> 2;
175175
}
@@ -218,11 +218,11 @@ pgp_armor_encode(const uint8 *src, unsigned len, StringInfo dst,
218218
appendStringInfo(dst, "%s: %s\n", keys[n], values[n]);
219219
appendStringInfoChar(dst, '\n');
220220

221-
/* make sure we have enough room to b64_encode() */
222-
b64len = b64_enc_len(len);
221+
/* make sure we have enough room to pg_base64_encode() */
222+
b64len = pg_base64_enc_len(len);
223223
enlargeStringInfo(dst, (int) b64len);
224224

225-
res = b64_encode(src, len, (uint8 *) dst->data + dst->len);
225+
res = pg_base64_encode(src, len, (uint8 *) dst->data + dst->len);
226226
if (res > b64len)
227227
elog(FATAL, "overflow - encode estimate too small");
228228
dst->len += res;
@@ -358,14 +358,14 @@ pgp_armor_decode(const uint8 *src, int len, StringInfo dst)
358358
goto out;
359359

360360
/* decode crc */
361-
if (b64_decode(p + 1, 4, buf) != 3)
361+
if (pg_base64_decode(p + 1, 4, buf) != 3)
362362
goto out;
363363
crc = (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2];
364364

365365
/* decode data */
366-
blen = (int) b64_dec_len(len);
366+
blen = (int) pg_base64_dec_len(len);
367367
enlargeStringInfo(dst, blen);
368-
res = b64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
368+
res = pg_base64_decode(base64_start, base64_end - base64_start, (uint8 *) dst->data);
369369
if (res > blen)
370370
elog(FATAL, "overflow - decode estimate too small");
371371
if (res >= 0)

src/backend/utils/adt/encode.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ static const int8 b64lookup[128] = {
215215
};
216216

217217
static unsigned
218-
b64_encode(const char *src, unsigned len, char *dst)
218+
pg_base64_encode(const char *src, unsigned len, char *dst)
219219
{
220220
char *p,
221221
*lend = dst + 76;
@@ -262,7 +262,7 @@ b64_encode(const char *src, unsigned len, char *dst)
262262
}
263263

264264
static unsigned
265-
b64_decode(const char *src, unsigned len, char *dst)
265+
pg_base64_decode(const char *src, unsigned len, char *dst)
266266
{
267267
const char *srcend = src + len,
268268
*s = src;
@@ -332,14 +332,14 @@ b64_decode(const char *src, unsigned len, char *dst)
332332

333333

334334
static unsigned
335-
b64_enc_len(const char *src, unsigned srclen)
335+
pg_base64_enc_len(const char *src, unsigned srclen)
336336
{
337337
/* 3 bytes will be converted to 4, linefeed after 76 chars */
338338
return (srclen + 2) * 4 / 3 + srclen / (76 * 3 / 4);
339339
}
340340

341341
static unsigned
342-
b64_dec_len(const char *src, unsigned srclen)
342+
pg_base64_dec_len(const char *src, unsigned srclen)
343343
{
344344
return (srclen * 3) >> 2;
345345
}
@@ -532,7 +532,7 @@ static const struct
532532
{
533533
"base64",
534534
{
535-
b64_enc_len, b64_dec_len, b64_encode, b64_decode
535+
pg_base64_enc_len, pg_base64_dec_len, pg_base64_encode, pg_base64_decode
536536
}
537537
},
538538
{

0 commit comments

Comments
 (0)