MCPcopy Create free account
hub / github.com/Tripwire/tripwire-open-source / tss_ConvertOneCharacter

Function tss_ConvertOneCharacter

src/core/codeconvert.cpp:527–609  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

525
526template<class BufferT, class SourceT>
527int tss_ConvertOneCharacter(iconv_t convForward,
528 iconv_t convReverse,
529 const char** ppSource,
530 size_t* pnSourceLeft,
531 char** ppBuffer,
532 size_t* pnBufferLeft
533# if (!SUPPORTS_EXPLICIT_TEMPLATE_FUNC_INST)
534 ,
535 BufferT /*dummy*/,
536 SourceT /*dummy*/
537# endif
538)
539{
540 cDebug d("tss_ConvertOneCharacter< B, S, C >()");
541
542 const char* pSrc = *ppSource;
543 char* pBuf = *ppBuffer;
544
545 //-- HACK!!!! BAM -- see if it is one of our reserved UCS2 characters
546 // TODO:BAM -- how does this affect our converters that don't use the UTF-8 step?
547 if (tss_IsFlaggedCharacter(**((SourceT**)ppSource)))
548 {
549 d.TraceDebug("Found one of our unconvertable characters in the reserved range!\n");
550 return -1;
551 }
552
553 //-- Try to find the number of items needed to get a complete character
554 size_t nSrcTry;
555 for (nSrcTry = sizeof(SourceT); nSrcTry <= *pnBufferLeft && nSrcTry <= MB_LEN_MAX; nSrcTry += sizeof(SourceT))
556 {
557 size_t nSrcLeft = nSrcTry;
558 size_t nBufLeft = *pnBufferLeft; // Try to find a character in 'n' items
559
560 // NOTE: On solaris sparc, iconv will attempt to NULL terminate the output,
561 // so make sure that the buffer has space for a terminating NULL
562 d.TraceDebug("attempting to convert with %u items\n", nSrcTry);
563 size_t nConv = // NOTE:
564 iconv(convForward, // On return, these addresses
565 (ICONV_SOURCE_TYPE**)&pSrc, // are set for one past the last
566 &nSrcLeft, // "item" converted successfully
567 &pBuf,
568 &nBufLeft);
569
570 if (nConv == (size_t)-1)
571 {
572 if (errno == EINVAL)
573 {
574 d.TraceDebug("more items needed\n");
575 continue;
576 }
577 else
578 {
579 d.TraceDebug("iconv failed with %d (not EINVAL)\n", errno);
580 return -1;
581 }
582 }
583 else
584 {

Callers 1

codeconvert.cppFile · 0.85

Calls 3

tss_IsFlaggedCharacterFunction · 0.85
tss_ReverseConvertFunction · 0.85
TraceDebugMethod · 0.60

Tested by

no test coverage detected