summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2005-12-19 19:39:26 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2005-12-19 19:39:26 +0000
commit650d471e3f4e3cde9b0fad19c0538e328bbf5f35 (patch)
tree87404e1cbfb793232655731316ce5da2e67aa4cb /lib/libc
parentf91e934c96572ce4a982aa5d681cfdf92da58382 (diff)
Add %hhd to *printf and *scanf as well as %z to *scanf. This was
sent out and approved about 6 months ago and has been rotting in my tree ever since.
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/stdio/vfprintf.c11
-rw-r--r--lib/libc/stdio/vfscanf.c40
2 files changed, 39 insertions, 12 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c
index 2b5314856db..b22dea8f0e7 100644
--- a/lib/libc/stdio/vfprintf.c
+++ b/lib/libc/stdio/vfprintf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfprintf.c,v 1.33 2005/09/23 02:33:34 tedu Exp $ */
+/* $OpenBSD: vfprintf.c,v 1.34 2005/12/19 19:39:25 millert Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
@@ -246,6 +246,7 @@ vfprintf(FILE *fp, const char *fmt0, _BSD_VA_LIST_ ap)
flags&PTRINT ? GETARG(ptrdiff_t) : \
flags&SIZEINT ? GETARG(ssize_t) : \
flags&SHORTINT ? (long)(short)GETARG(int) : \
+ flags&CHARINT ? (long)(__signed char)GETARG(int) : \
(long)GETARG(int))
#define UARG() \
(flags&QUADINT ? GETARG(u_quad_t) : \
@@ -253,6 +254,7 @@ vfprintf(FILE *fp, const char *fmt0, _BSD_VA_LIST_ ap)
flags&PTRINT ? GETARG(ptrdiff_t) : /* XXX */ \
flags&SIZEINT ? GETARG(size_t) : \
flags&SHORTINT ? (u_long)(u_short)GETARG(int) : \
+ flags&CHARINT ? (u_long)(u_char)GETARG(int) : \
(u_long)GETARG(u_int))
/*
@@ -934,7 +936,12 @@ reswitch: switch (ch) {
goto rflag;
#endif
case 'h':
- flags |= SHORTINT;
+ if (*fmt == 'h') {
+ fmt++;
+ flags |= CHARINT;
+ } else {
+ flags |= SHORTINT;
+ }
goto rflag;
case 'l':
if (*fmt == 'l') {
diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c
index 0546c5c5145..b319271aecf 100644
--- a/lib/libc/stdio/vfscanf.c
+++ b/lib/libc/stdio/vfscanf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfscanf.c,v 1.15 2005/08/08 08:05:36 espie Exp $ */
+/* $OpenBSD: vfscanf.c,v 1.16 2005/12/19 19:39:25 millert Exp $ */
/*-
* Copyright (c) 1990, 1993
* The Regents of the University of California. All rights reserved.
@@ -46,13 +46,15 @@
/*
* Flags used during conversion.
*/
-#define LONG 0x01 /* l: long or double */
-#define LONGDBL 0x02 /* L: long double; unimplemented */
-#define SHORT 0x04 /* h: short */
-#define QUAD 0x08 /* q: quad */
-#define SUPPRESS 0x10 /* suppress assignment */
-#define POINTER 0x20 /* weird %p pointer (`fake hex') */
-#define NOSKIP 0x40 /* do not skip blanks */
+#define LONG 0x0001 /* l: long or double */
+#define LONGDBL 0x0002 /* L: long double; unimplemented */
+#define SHORT 0x0004 /* h: short */
+#define QUAD 0x0008 /* q: quad */
+#define SUPPRESS 0x0010 /* suppress assignment */
+#define POINTER 0x0020 /* weird %p pointer (`fake hex') */
+#define NOSKIP 0x0040 /* do not skip blanks */
+#define SHORTSHORT 0x0080 /* hh: 8 bit integer */
+#define SIZEINT 0x0100 /* z: (signed) size_t */
/*
* The following are used in numeric conversions only:
@@ -153,7 +155,12 @@ literal:
flags |= LONGDBL;
goto again;
case 'h':
- flags |= SHORT;
+ if (*fmt == 'h') {
+ fmt++;
+ flags |= SHORTSHORT;
+ } else {
+ flags |= SHORT;
+ }
goto again;
case 'l':
if (*fmt == 'l') {
@@ -166,6 +173,9 @@ literal:
case 'q':
flags |= QUAD;
goto again;
+ case 'z':
+ flags |= SIZEINT;
+ goto again;
case '0': case '1': case '2': case '3': case '4':
case '5': case '6': case '7': case '8': case '9':
@@ -252,10 +262,16 @@ literal:
case 'n':
if (flags & SUPPRESS) /* ??? */
continue;
- if (flags & SHORT)
+ if (flags & SHORTSHORT)
+ *va_arg(ap, __signed char *) = nread;
+ else if (flags & SHORT)
*va_arg(ap, short *) = nread;
else if (flags & LONG)
*va_arg(ap, long *) = nread;
+ else if (flags & QUAD)
+ *va_arg(ap, quad_t *) = nread;
+ else if (flags & SIZEINT)
+ *va_arg(ap, ssize_t *) = nread;
else
*va_arg(ap, int *) = nread;
continue;
@@ -537,12 +553,16 @@ literal:
if (flags & POINTER)
*va_arg(ap, void **) =
(void *)(long)res;
+ else if (flags & SIZEINT)
+ *va_arg(ap, ssize_t *) = res;
else if (flags & QUAD)
*va_arg(ap, quad_t *) = res;
else if (flags & LONG)
*va_arg(ap, long *) = res;
else if (flags & SHORT)
*va_arg(ap, short *) = res;
+ else if (flags & SHORTSHORT)
+ *va_arg(ap, __signed char *) = res;
else
*va_arg(ap, int *) = res;
nassigned++;