Make sure that sign extension does not happen when we convert to wide
characters. From Miloslav Trmac
This commit is contained in:
parent
9bebb1e48e
commit
16339a29a1
|
@ -0,0 +1,16 @@
|
|||
# $NetBSD: Makefile,v 1.1 2005/03/27 18:49:51 christos Exp $
|
||||
|
||||
NOMAN= # defined
|
||||
|
||||
PROG= mbtowc_test
|
||||
WARNS?= 1
|
||||
|
||||
regress: ${PROG}
|
||||
@if ./${PROG}; then \
|
||||
echo PASSED; \
|
||||
else \
|
||||
echo FAILED; \
|
||||
exit 1; \
|
||||
fi
|
||||
|
||||
.include <bsd.prog.mk>
|
|
@ -0,0 +1,30 @@
|
|||
/* From: Miloslav Trmac <mitr@volny.cz> */
|
||||
#include <langinfo.h>
|
||||
#include <limits.h>
|
||||
#include <locale.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
wchar_t wc;
|
||||
char back[MB_LEN_MAX];
|
||||
int ret;
|
||||
size_t i;
|
||||
|
||||
setlocale(LC_ALL, "");
|
||||
printf("Charset: %s\n", nl_langinfo(CODESET));
|
||||
ret = mbtowc(&wc, "\xe4", 1);
|
||||
printf("mbtowc(): %d\n", ret);
|
||||
if(ret > 0) {
|
||||
printf("Result: 0x%08lX\n",(unsigned long)wc);
|
||||
ret = wctomb(back, wc);
|
||||
printf("wctomb(): %d\n", ret);
|
||||
for(i = 0; ret > 0 && i <(size_t)ret; i++)
|
||||
printf("%02X ",(unsigned char)back[i]);
|
||||
putchar('\n');
|
||||
return EXIT_SUCCESS;
|
||||
} else
|
||||
return EXIT_FAILURE;
|
||||
}
|
Loading…
Reference in New Issue