| 31 | */ |
| 32 | #ifdef TSK_WIN32 |
| 33 | static int |
| 34 | tsk_printf_conv(WCHAR * wbuf, int wlen, const char *msg, va_list * args) |
| 35 | { |
| 36 | char *cbuf; |
| 37 | UTF8 *ptr8; |
| 38 | UTF16 *ptr16; |
| 39 | int retVal; |
| 40 | size_t len, clen; |
| 41 | |
| 42 | wbuf[0] = '\0'; |
| 43 | |
| 44 | /* Allocate a UTF-8 buffer and process the printf args */ |
| 45 | clen = wlen * 3; |
| 46 | if (NULL == (cbuf = (char *) tsk_malloc(clen))) { |
| 47 | return 1; |
| 48 | } |
| 49 | |
| 50 | #ifdef _MSC_VER |
| 51 | vsnprintf_s(cbuf, clen - 1, _TRUNCATE, msg, *args); |
| 52 | #else |
| 53 | vsnprintf(cbuf, clen - 1, msg, *args); |
| 54 | #endif |
| 55 | len = strlen(cbuf); |
| 56 | |
| 57 | //Convert to UTF-16 |
| 58 | ptr8 = (UTF8 *) cbuf; |
| 59 | ptr16 = (UTF16 *) wbuf; |
| 60 | retVal = |
| 61 | tsk_UTF8toUTF16((const UTF8 **) &ptr8, &ptr8[len + 1], &ptr16, |
| 62 | &ptr16[wlen], TSKlenientConversion); |
| 63 | if (retVal != TSKconversionOK) { |
| 64 | *ptr16 = '\0'; |
| 65 | if (tsk_verbose) |
| 66 | tsk_fprintf(stderr, |
| 67 | "tsk_printf_conv: error converting string to UTF-16\n"); |
| 68 | } |
| 69 | |
| 70 | free(cbuf); |
| 71 | return 0; |
| 72 | } |
| 73 | #endif |
| 74 | |
| 75 | /** |
no test coverage detected