MCPcopy Create free account
hub / github.com/apache/cloudberry / pg_do_encoding_conversion_buf

Function pg_do_encoding_conversion_buf

src/backend/utils/mb/mbutils.c:470–495  ·  view source on GitHub ↗

* Convert src string to another encoding. * * This function has a different API than the other conversion functions. * The caller should've looked up the conversion function using * FindDefaultConversionProc(). Unlike the other functions, the converted * result is not palloc'd. It is written to the caller-supplied buffer * instead. * * src_encoding - encoding to convert from * dest_en

Source from the content-addressed store, hash-verified

468 * to strlen().
469 */
470int
471pg_do_encoding_conversion_buf(Oid proc,
472 int src_encoding,
473 int dest_encoding,
474 unsigned char *src, int srclen,
475 unsigned char *dest, int destlen,
476 bool noError)
477{
478 Datum result;
479
480 /*
481 * If the destination buffer is not large enough to hold the result in the
482 * worst case, limit the input size passed to the conversion function.
483 */
484 if ((Size) srclen >= ((destlen - 1) / (Size) MAX_CONVERSION_GROWTH))
485 srclen = ((destlen - 1) / (Size) MAX_CONVERSION_GROWTH);
486
487 result = OidFunctionCall6(proc,
488 Int32GetDatum(src_encoding),
489 Int32GetDatum(dest_encoding),
490 CStringGetDatum((char *)src),
491 CStringGetDatum((char *)dest),
492 Int32GetDatum(srclen),
493 BoolGetDatum(noError));
494 return DatumGetInt32(result);
495}
496
497/*
498 * Convert string to encoding encoding_name. The source

Callers 3

CopyConvertBufFunction · 0.85
CopyConversionErrorFunction · 0.85
test_enc_conversionFunction · 0.85

Calls 4

Int32GetDatumFunction · 0.85
CStringGetDatumFunction · 0.85
BoolGetDatumFunction · 0.85
DatumGetInt32Function · 0.85

Tested by 1

test_enc_conversionFunction · 0.68