aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/printf/printf.c
diff options
context:
space:
mode:
authorJilles Tjoelker <jilles@FreeBSD.org>2011-05-28 11:37:47 +0000
committerJilles Tjoelker <jilles@FreeBSD.org>2011-05-28 11:37:47 +0000
commit98102dabd3d1f00bb970634a5722be0f7e93078d (patch)
tree97044025b3bbee11165340fbea5bcf368dd81b10 /usr.bin/printf/printf.c
parent802e09ac9ee9473983514693e46d8f22012e7f1d (diff)
Notes
Diffstat (limited to 'usr.bin/printf/printf.c')
-rw-r--r--usr.bin/printf/printf.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index 56c1caf638c9..eace37050a8d 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -58,6 +58,7 @@ static const char rcsid[] =
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <wchar.h>
#ifdef SHELL
#define main printfcmd
@@ -537,10 +538,23 @@ static int
asciicode(void)
{
int ch;
+ wchar_t wch;
+ mbstate_t mbs;
- ch = **gargv;
- if (ch == '\'' || ch == '"')
- ch = (*gargv)[1];
+ ch = (unsigned char)**gargv;
+ if (ch == '\'' || ch == '"') {
+ memset(&mbs, 0, sizeof(mbs));
+ switch (mbrtowc(&wch, *gargv + 1, MB_LEN_MAX, &mbs)) {
+ case (size_t)-2:
+ case (size_t)-1:
+ wch = (unsigned char)gargv[0][1];
+ break;
+ case 0:
+ wch = 0;
+ break;
+ }
+ ch = wch;
+ }
++gargv;
return (ch);
}