diff options
| author | Jilles Tjoelker <jilles@FreeBSD.org> | 2011-05-28 11:37:47 +0000 |
|---|---|---|
| committer | Jilles Tjoelker <jilles@FreeBSD.org> | 2011-05-28 11:37:47 +0000 |
| commit | 98102dabd3d1f00bb970634a5722be0f7e93078d (patch) | |
| tree | 97044025b3bbee11165340fbea5bcf368dd81b10 /usr.bin/printf | |
| parent | 802e09ac9ee9473983514693e46d8f22012e7f1d (diff) | |
Notes
Diffstat (limited to 'usr.bin/printf')
| -rw-r--r-- | usr.bin/printf/printf.1 | 5 | ||||
| -rw-r--r-- | usr.bin/printf/printf.c | 20 |
2 files changed, 19 insertions, 6 deletions
diff --git a/usr.bin/printf/printf.1 b/usr.bin/printf/printf.1 index 56c685507f74..2afb9d393e6e 100644 --- a/usr.bin/printf/printf.1 +++ b/usr.bin/printf/printf.1 @@ -31,7 +31,7 @@ .\" @(#)printf.1 8.1 (Berkeley) 6/6/93 .\" $FreeBSD$ .\" -.Dd April 25, 2011 +.Dd May 28, 2011 .Dt PRINTF 1 .Os .Sh NAME @@ -68,8 +68,7 @@ otherwise it is evaluated as a C constant, with the following extensions: A leading plus or minus sign is allowed. .It If the leading character is a single or double quote, the value is the -.Tn ASCII -code of the next character. +character code of the next character. .El .Pp The format string is reused as often as necessary to satisfy the 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); } |
