Skip to content

Commit d07f79a

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 cadb14c commit d07f79a

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

contrib/pgcrypto/pgp-armor.c

Lines changed: 9 additions & 9 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
}
@@ -214,7 +214,7 @@ pgp_armor_encode(const uint8 *src, unsigned len, uint8 *dst)
214214
memcpy(pos, armor_header, n);
215215
pos += n;
216216

217-
n = b64_encode(src, len, pos);
217+
n = pg_base64_encode(src, len, pos);
218218
pos += n;
219219

220220
if (*(pos - 1) != '\n')
@@ -355,12 +355,12 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
355355
goto out;
356356

357357
/* decode crc */
358-
if (b64_decode(p + 1, 4, buf) != 3)
358+
if (pg_base64_decode(p + 1, 4, buf) != 3)
359359
goto out;
360360
crc = (((long) buf[0]) << 16) + (((long) buf[1]) << 8) + (long) buf[2];
361361

362362
/* decode data */
363-
res = b64_decode(base64_start, base64_end - base64_start, dst);
363+
res = pg_base64_decode(base64_start, base64_end - base64_start, dst);
364364

365365
/* check crc */
366366
if (res >= 0 && crc24(dst, res) != crc)
@@ -372,11 +372,11 @@ pgp_armor_decode(const uint8 *src, unsigned len, uint8 *dst)
372372
unsigned
373373
pgp_armor_enc_len(unsigned len)
374374
{
375-
return b64_enc_len(len) + strlen(armor_header) + strlen(armor_footer) + 16;
375+
return pg_base64_enc_len(len) + strlen(armor_header) + strlen(armor_footer) + 16;
376376
}
377377

378378
unsigned
379379
pgp_armor_dec_len(unsigned len)
380380
{
381-
return b64_dec_len(len);
381+
return pg_base64_dec_len(len);
382382
}

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;
@@ -331,14 +331,14 @@ b64_decode(const char *src, unsigned len, char *dst)
331331

332332

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

340340
static unsigned
341-
b64_dec_len(const char *src, unsigned srclen)
341+
pg_base64_dec_len(const char *src, unsigned srclen)
342342
{
343343
return (srclen * 3) >> 2;
344344
}
@@ -531,7 +531,7 @@ static const struct
531531
{
532532
"base64",
533533
{
534-
b64_enc_len, b64_dec_len, b64_encode, b64_decode
534+
pg_base64_enc_len, pg_base64_dec_len, pg_base64_encode, pg_base64_decode
535535
}
536536
},
537537
{

0 commit comments

Comments
 (0)