- (djm) [openbsd-compat/bsd-snprintf.c] teach our local snprintf code the

'j' (intmax_t/uintmax_t) and 'z' (size_t/ssize_t) conversions in case we
   start to use them in the future.
This commit is contained in:
Damien Miller 2013-08-28 12:49:43 +10:00
parent f2f6c315a9
commit 04be8b9e53
2 changed files with 43 additions and 2 deletions

View File

@ -1,3 +1,8 @@
20130828
- (djm) [openbsd-compat/bsd-snprintf.c] teach our local snprintf code the
'j' (intmax_t/uintmax_t) and 'z' (size_t/ssize_t) conversions in case we
start to use them in the future.
20130821 20130821
- (djm) OpenBSD CVS Sync - (djm) OpenBSD CVS Sync
- djm@cvs.openbsd.org 2013/08/06 23:03:49 - djm@cvs.openbsd.org 2013/08/06 23:03:49

View File

@ -160,6 +160,8 @@
#define DP_C_LONG 2 #define DP_C_LONG 2
#define DP_C_LDOUBLE 3 #define DP_C_LDOUBLE 3
#define DP_C_LLONG 4 #define DP_C_LLONG 4
#define DP_C_SIZE 5
#define DP_C_INTMAX 6
#define char_to_int(p) ((p)- '0') #define char_to_int(p) ((p)- '0')
#ifndef MAX #ifndef MAX
@ -182,7 +184,7 @@ static int dopr(char *buffer, size_t maxlen, const char *format,
static int fmtstr(char *buffer, size_t *currlen, size_t maxlen, static int fmtstr(char *buffer, size_t *currlen, size_t maxlen,
char *value, int flags, int min, int max); char *value, int flags, int min, int max);
static int fmtint(char *buffer, size_t *currlen, size_t maxlen, static int fmtint(char *buffer, size_t *currlen, size_t maxlen,
LLONG value, int base, int min, int max, int flags); intmax_t value, int base, int min, int max, int flags);
static int fmtfp(char *buffer, size_t *currlen, size_t maxlen, static int fmtfp(char *buffer, size_t *currlen, size_t maxlen,
LDOUBLE fvalue, int min, int max, int flags); LDOUBLE fvalue, int min, int max, int flags);
@ -190,7 +192,7 @@ static int
dopr(char *buffer, size_t maxlen, const char *format, va_list args_in) dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
{ {
char ch; char ch;
LLONG value; intmax_t value;
LDOUBLE fvalue; LDOUBLE fvalue;
char *strvalue; char *strvalue;
int min; int min;
@ -287,6 +289,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
cflags = DP_C_SHORT; cflags = DP_C_SHORT;
ch = *format++; ch = *format++;
break; break;
case 'j':
cflags = DP_C_INTMAX;
ch = *format++;
break;
case 'l': case 'l':
cflags = DP_C_LONG; cflags = DP_C_LONG;
ch = *format++; ch = *format++;
@ -299,6 +305,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
cflags = DP_C_LDOUBLE; cflags = DP_C_LDOUBLE;
ch = *format++; ch = *format++;
break; break;
case 'z':
cflags = DP_C_SIZE;
ch = *format++;
break;
default: default:
break; break;
} }
@ -314,6 +324,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
value = va_arg (args, long int); value = va_arg (args, long int);
else if (cflags == DP_C_LLONG) else if (cflags == DP_C_LLONG)
value = va_arg (args, LLONG); value = va_arg (args, LLONG);
else if (cflags == DP_C_SIZE)
value = va_arg (args, ssize_t);
else if (cflags == DP_C_INTMAX)
value = va_arg (args, intmax_t);
else else
value = va_arg (args, int); value = va_arg (args, int);
if (fmtint(buffer, &currlen, maxlen, if (fmtint(buffer, &currlen, maxlen,
@ -328,6 +342,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
value = (long)va_arg (args, unsigned long int); value = (long)va_arg (args, unsigned long int);
else if (cflags == DP_C_LLONG) else if (cflags == DP_C_LLONG)
value = (long)va_arg (args, unsigned LLONG); value = (long)va_arg (args, unsigned LLONG);
else if (cflags == DP_C_SIZE)
value = va_arg (args, size_t);
else if (cflags == DP_C_INTMAX)
value = va_arg (args, uintmax_t);
else else
value = (long)va_arg (args, unsigned int); value = (long)va_arg (args, unsigned int);
if (fmtint(buffer, &currlen, maxlen, value, if (fmtint(buffer, &currlen, maxlen, value,
@ -342,6 +360,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
value = (long)va_arg (args, unsigned long int); value = (long)va_arg (args, unsigned long int);
else if (cflags == DP_C_LLONG) else if (cflags == DP_C_LLONG)
value = (LLONG)va_arg (args, unsigned LLONG); value = (LLONG)va_arg (args, unsigned LLONG);
else if (cflags == DP_C_SIZE)
value = va_arg (args, size_t);
else if (cflags == DP_C_INTMAX)
value = va_arg (args, uintmax_t);
else else
value = (long)va_arg (args, unsigned int); value = (long)va_arg (args, unsigned int);
if (fmtint(buffer, &currlen, maxlen, value, if (fmtint(buffer, &currlen, maxlen, value,
@ -358,6 +380,10 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
value = (long)va_arg (args, unsigned long int); value = (long)va_arg (args, unsigned long int);
else if (cflags == DP_C_LLONG) else if (cflags == DP_C_LLONG)
value = (LLONG)va_arg (args, unsigned LLONG); value = (LLONG)va_arg (args, unsigned LLONG);
else if (cflags == DP_C_SIZE)
value = va_arg (args, size_t);
else if (cflags == DP_C_INTMAX)
value = va_arg (args, uintmax_t);
else else
value = (long)va_arg (args, unsigned int); value = (long)va_arg (args, unsigned int);
if (fmtint(buffer, &currlen, maxlen, value, if (fmtint(buffer, &currlen, maxlen, value,
@ -416,6 +442,7 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
(long) strvalue, 16, min, max, flags) == -1) (long) strvalue, 16, min, max, flags) == -1)
return -1; return -1;
break; break;
#if we_dont_want_this_in_openssh
case 'n': case 'n':
if (cflags == DP_C_SHORT) { if (cflags == DP_C_SHORT) {
short int *num; short int *num;
@ -429,12 +456,21 @@ dopr(char *buffer, size_t maxlen, const char *format, va_list args_in)
LLONG *num; LLONG *num;
num = va_arg (args, LLONG *); num = va_arg (args, LLONG *);
*num = (LLONG)currlen; *num = (LLONG)currlen;
} else if (cflags == DP_C_SIZE) {
ssize_t *num;
num = va_arg (args, ssize_t *);
*num = (ssize_t)currlen;
} else if (cflags == DP_C_INTMAX) {
intmax_t *num;
num = va_arg (args, intmax_t *);
*num = (intmax_t)currlen;
} else { } else {
int *num; int *num;
num = va_arg (args, int *); num = va_arg (args, int *);
*num = currlen; *num = currlen;
} }
break; break;
#endif
case '%': case '%':
DOPR_OUTCH(buffer, currlen, maxlen, ch); DOPR_OUTCH(buffer, currlen, maxlen, ch);
break; break;