]> Zhao Yanbai Git Server - minix.git/commitdiff
enable printing of 64-bit ints with gcc.
authorTomas Hruby <tom@minix3.org>
Wed, 11 Nov 2009 12:15:08 +0000 (12:15 +0000)
committerTomas Hruby <tom@minix3.org>
Wed, 11 Nov 2009 12:15:08 +0000 (12:15 +0000)
lib/stdio/doprnt.c
lib/stdio/icompute.c
lib/stdio/loc_incl.h

index a0248b68817bff11aefbb7191a9783bc2e275b68..9c4aba2fedc42504155613394298fd9512eb2609 100644 (file)
@@ -42,12 +42,12 @@ gnum(register const char *f, int *ip, va_list *app)
 static char *
 o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
 {
-       long signed_val;
-       unsigned long unsigned_val;
+       printval_s_t signed_val;
+       printval_u_t unsigned_val;
        char *old_s = s;
        int base;
 
-       switch (flags & (FL_SHORT | FL_LONG)) {
+       switch (flags & (FL_SHORT | FL_LONG | FL_LONGLONG)) {
        case FL_SHORT:
                if (is_signed) {
                        signed_val = (short) va_arg(*ap, int);
@@ -62,6 +62,15 @@ o_print(va_list *ap, int flags, char *s, char c, int precision, int is_signed)
                        unsigned_val = va_arg(*ap, unsigned long);
                }
                break;
+#if defined(__LONG_LONG_SUPPORTED)
+       case FL_LONG | FL_LONGLONG:
+               if (is_signed) {
+                       signed_val = va_arg(*ap, long long);
+               } else {
+                       unsigned_val = va_arg(*ap, unsigned long long);
+               }
+               break;
+#endif
        default:
                if (is_signed) {
                        signed_val = va_arg(*ap, int);
@@ -171,11 +180,27 @@ _doprnt(register const char *fmt, va_list ap, FILE *stream)
 
                s = s1 = buf;
 
-               switch (*fmt) {
-               case 'h':       flags |= FL_SHORT; fmt++; break;
-               case 'l':       flags |= FL_LONG; fmt++; break;
-               case 'L':       flags |= FL_LONGDOUBLE; fmt++; break;
-               }
+               flags &= ~FL_NOMORE;
+               do {
+                       switch (*fmt) {
+                       case 'h':
+                               flags |= FL_SHORT;
+                               break;
+                       case 'l':       
+                               if(flags & FL_LONG)
+                                       flags |= FL_LONGLONG;
+                               else
+                                       flags |= FL_LONG;
+                               break;
+                       case 'L':
+                               flags |= FL_LONGDOUBLE;
+                               break;
+                       default:
+                               flags |= FL_NOMORE;
+                               continue;
+                       }
+                       fmt++;
+               } while(!(flags & FL_NOMORE));
 
                switch (c = *fmt++) {
                default:
index 5e7fa80f6c853434ce4063067b52e3e948e9e4d0..6d2f33092120d626058713d0cb226bc78c30a34c 100644 (file)
@@ -8,7 +8,7 @@
 /* This routine is used in doprnt.c as well as in tmpfile.c and tmpnam.c. */
 
 char *
-_i_compute(unsigned long val, int base, char *s, int nrdigits)
+_i_compute(printval_u_t val, int base, char *s, int nrdigits)
 {
        int c;
 
index 77dee58a3011bfc4b40932e2916646ea4b77ec3a..1578003108b7bc34306f403476adbbfb1748ab2d 100644 (file)
@@ -4,15 +4,24 @@
 /* $Header$ */
 
 #include       <stdio.h>
+#include       <ansi.h>
 
 #define        io_testflag(p,x)        ((p)->_flags & (x))
 
 #include       <stdarg.h>
 
+#if defined(__LONG_LONG_SUPPORTED)
+typedef long long printval_s_t;
+typedef unsigned long long printval_u_t;
+#else
+typedef long printval_s_t;
+typedef unsigned long printval_u_t;
+#endif
+
 #ifdef _ANSI
 int _doprnt(const char *format, va_list ap, FILE *stream);
 int _doscan(FILE * stream, const char *format, va_list ap);
-char *_i_compute(unsigned long val, int base, char *s, int nrdigits);
+char *_i_compute(printval_u_t val, int base, char *s, int nrdigits);
 char *_f_print(va_list *ap, int flags, char *s, char c, int precision);
 void __cleanup(void);
 
@@ -38,3 +47,4 @@ char *_fcvt(long double value, int ndigit, int *decpt, int *sign);
 #define FL_SIGNEDCONV  0x0400          /* may contain a sign */
 #define        FL_NOASSIGN     0x0800          /* do not assign (in scanf) */
 #define        FL_NOMORE       0x1000          /* all flags collected */
+#define        FL_LONGLONG     0x2000          /* 64-bit for ints */