* 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
| 468 | * to strlen(). |
| 469 | */ |
| 470 | int |
| 471 | pg_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 |