summaryrefslogtreecommitdiff
path: root/bsd-snprintf.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2000-09-30 09:49:08 +1100
committerDamien Miller <djm@mindrot.org>2000-09-30 09:49:08 +1100
commit3dfb0dd7fd3e792e73e27a213f53b3fe452b8e45 (patch)
tree9a7251d0f01a726aac7cda14f759081a0adaccde /bsd-snprintf.c
parentbea034a5bfcce67b1149b28a57c58a605170e68f (diff)
- (djm) Support in bsd-snprintf.c for long long conversions from
Ben Lindstrom <mouring@pconline.com> - (djm) Cleanup NeXT support from Ben Lindstrom <mouring@pconline.com>
Diffstat (limited to 'bsd-snprintf.c')
-rw-r--r--bsd-snprintf.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/bsd-snprintf.c b/bsd-snprintf.c
index 5b674c569..3a82a586f 100644
--- a/bsd-snprintf.c
+++ b/bsd-snprintf.c
@@ -38,6 +38,10 @@
38 * missing. Some systems only have snprintf() but not vsnprintf(), so 38 * missing. Some systems only have snprintf() but not vsnprintf(), so
39 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF. 39 * the code is now broken down under HAVE_SNPRINTF and HAVE_VSNPRINTF.
40 * 40 *
41 * Ben Lindstrom <mouring@pconline.com> 09/27/00 for OpenSSH
42 * Welcome to the world of %lld and %qd support. With other
43 * long long support. This is needed for sftp-server to work
44 * right.
41 **************************************************************/ 45 **************************************************************/
42 46
43#include "config.h" 47#include "config.h"
@@ -111,9 +115,10 @@ static void dopr_outch (char *buffer, size_t *currlen, size_t maxlen, char c );
111#define DP_F_UNSIGNED (1 << 6) 115#define DP_F_UNSIGNED (1 << 6)
112 116
113/* Conversion Flags */ 117/* Conversion Flags */
114#define DP_C_SHORT 1 118#define DP_C_SHORT 1
115#define DP_C_LONG 2 119#define DP_C_LONG 2
116#define DP_C_LDOUBLE 3 120#define DP_C_LDOUBLE 3
121#define DP_C_LONG_LONG 4
117 122
118#define char_to_int(p) (p - '0') 123#define char_to_int(p) (p - '0')
119#ifndef MAX 124#ifndef MAX
@@ -222,7 +227,6 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
222 state = DP_S_MOD; 227 state = DP_S_MOD;
223 break; 228 break;
224 case DP_S_MOD: 229 case DP_S_MOD:
225 /* Currently, we don't support Long Long, bummer */
226 switch (ch) 230 switch (ch)
227 { 231 {
228 case 'h': 232 case 'h':
@@ -232,7 +236,15 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
232 case 'l': 236 case 'l':
233 cflags = DP_C_LONG; 237 cflags = DP_C_LONG;
234 ch = *format++; 238 ch = *format++;
239 if (ch == 'l') {
240 cflags = DP_C_LONG_LONG;
241 ch = *format++;
242 }
235 break; 243 break;
244 case 'q':
245 cflags = DP_C_LONG_LONG;
246 ch = *format++;
247 break;
236 case 'L': 248 case 'L':
237 cflags = DP_C_LDOUBLE; 249 cflags = DP_C_LDOUBLE;
238 ch = *format++; 250 ch = *format++;
@@ -251,6 +263,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
251 value = va_arg (args, short int); 263 value = va_arg (args, short int);
252 else if (cflags == DP_C_LONG) 264 else if (cflags == DP_C_LONG)
253 value = va_arg (args, long int); 265 value = va_arg (args, long int);
266 else if (cflags == DP_C_LONG_LONG)
267 value = va_arg (args, long long);
254 else 268 else
255 value = va_arg (args, int); 269 value = va_arg (args, int);
256 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); 270 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -261,6 +275,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
261 value = va_arg (args, unsigned short int); 275 value = va_arg (args, unsigned short int);
262 else if (cflags == DP_C_LONG) 276 else if (cflags == DP_C_LONG)
263 value = va_arg (args, unsigned long int); 277 value = va_arg (args, unsigned long int);
278 else if (cflags == DP_C_LONG_LONG)
279 value = va_arg (args, unsigned long long);
264 else 280 else
265 value = va_arg (args, unsigned int); 281 value = va_arg (args, unsigned int);
266 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags); 282 fmtint (buffer, &currlen, maxlen, value, 8, min, max, flags);
@@ -271,6 +287,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
271 value = va_arg (args, unsigned short int); 287 value = va_arg (args, unsigned short int);
272 else if (cflags == DP_C_LONG) 288 else if (cflags == DP_C_LONG)
273 value = va_arg (args, unsigned long int); 289 value = va_arg (args, unsigned long int);
290 else if (cflags == DP_C_LONG_LONG)
291 value = va_arg (args, unsigned long long);
274 else 292 else
275 value = va_arg (args, unsigned int); 293 value = va_arg (args, unsigned int);
276 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags); 294 fmtint (buffer, &currlen, maxlen, value, 10, min, max, flags);
@@ -283,6 +301,8 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
283 value = va_arg (args, unsigned short int); 301 value = va_arg (args, unsigned short int);
284 else if (cflags == DP_C_LONG) 302 else if (cflags == DP_C_LONG)
285 value = va_arg (args, unsigned long int); 303 value = va_arg (args, unsigned long int);
304 else if (cflags == DP_C_LONG_LONG)
305 value = va_arg (args, unsigned long long);
286 else 306 else
287 value = va_arg (args, unsigned int); 307 value = va_arg (args, unsigned int);
288 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags); 308 fmtint (buffer, &currlen, maxlen, value, 16, min, max, flags);
@@ -337,6 +357,12 @@ static void dopr (char *buffer, size_t maxlen, const char *format, va_list args)
337 num = va_arg (args, long int *); 357 num = va_arg (args, long int *);
338 *num = currlen; 358 *num = currlen;
339 } 359 }
360 else if (cflags == DP_C_LONG_LONG)
361 {
362 long long *num;
363 num = va_arg (args, long long *);
364 *num = currlen;
365 }
340 else 366 else
341 { 367 {
342 int *num; 368 int *num;
@@ -747,9 +773,11 @@ int main (void)
747 "%+22.33d", 773 "%+22.33d",
748 "%01.3d", 774 "%01.3d",
749 "%4d", 775 "%4d",
776 "%lld",
777 "%qd",
750 NULL 778 NULL
751 }; 779 };
752 long int_nums[] = { -1, 134, 91340, 341, 0203, 0}; 780 long long int_nums[] = { -1, 134, 91340, 341, 0203, 0, 9999999 };
753 int x, y; 781 int x, y;
754 int fail = 0; 782 int fail = 0;
755 int num = 0; 783 int num = 0;