From: David van Moolenbroek Date: Tue, 24 Jul 2012 16:14:48 +0000 (+0000) Subject: libsys: 64-bit numbers support for printf() X-Git-Tag: v3.2.1~442 X-Git-Url: http://zhaoyanbai.com/repos/%22http:/www.isc.org/icons/soc.html?a=commitdiff_plain;h=8caec1b57bb521c4da736c2591653a85952665e5;p=minix.git libsys: 64-bit numbers support for printf() Change some drivers accordingly. --- diff --git a/drivers/fbd/fbd.c b/drivers/fbd/fbd.c index 3cb7cf765..87faf6b65 100644 --- a/drivers/fbd/fbd.c +++ b/drivers/fbd/fbd.c @@ -426,9 +426,8 @@ static int fbd_transfer(dev_t UNUSED(minor), int do_write, u64_t position, do_write ? FBD_FLAG_WRITE : FBD_FLAG_READ); #if DEBUG - printf("FBD: %s operation for pos %lx:%08lx size %u -> hooks %x\n", - do_write ? "write" : "read", ex64hi(position), - ex64lo(position), size, hooks); + printf("FBD: %s operation for pos %"PRIx64" size %u -> hooks %x\n", + do_write ? "write" : "read", position, size, hooks); #endif if (hooks & PRE_HOOK) diff --git a/drivers/filter/driver.c b/drivers/filter/driver.c index b4106bbba..d0b742ffe 100644 --- a/drivers/filter/driver.c +++ b/drivers/filter/driver.c @@ -84,13 +84,14 @@ static int driver_open(int which) return RET_REDO; } #if DEBUG - printf("Filter: partition size: 0x%s / %lu sectors\n", - print64(disk_size), sectors); + printf("Filter: partition size: 0x%"PRIx64" / %lu sectors\n", + disk_size, sectors); #endif } else { if(cmp64(disk_size, part.size)) { - printf("Filter: partition size mismatch (%s != %s)\n", - print64(part.size), print64(disk_size)); + printf("Filter: partition size mismatch " + "(0x%"PRIx64" != 0x%"PRIx64")\n", + part.size, disk_size); return RET_REDO; } @@ -768,7 +769,7 @@ static int paired_sendrec(message *m1, message *m2, int both) int r; #if DEBUG2 - printf("paired_sendrec(%d) - <%d,%x:%x,%d> - %x,%x\n", + printf("paired_sendrec(%d) - <%d,%lx:%lx,%d> - %x,%x\n", both, m1->m_type, m1->BDEV_POS_HI, m1->BDEV_POS_LO, m1->BDEV_COUNT, m1->BDEV_GRANT, m2->BDEV_GRANT); #endif diff --git a/drivers/filter/inc.h b/drivers/filter/inc.h index f93d86eb0..c54a77e0c 100644 --- a/drivers/filter/inc.h +++ b/drivers/filter/inc.h @@ -118,6 +118,5 @@ extern void ds_event(void); /* util.c */ extern char *flt_malloc(size_t size, char *sbuf, size_t ssize); extern void flt_free(char *buf, size_t size, const char *sbuf); -extern char *print64(u64_t p); extern clock_t flt_alarm(clock_t dt); diff --git a/drivers/filter/sum.c b/drivers/filter/sum.c index 06dba8563..5fe581c2e 100644 --- a/drivers/filter/sum.c +++ b/drivers/filter/sum.c @@ -568,9 +568,8 @@ int transfer(u64_t pos, char *buffer, size_t *sizep, int flag_rw) r = read_write(phys_pos, ext_buffer, ext_buffer, &res_size, flag_rw); #if DEBUG2 - printf("Filter: transfer: read_write(%x:%x, %u, %d) = %d, %u\n", - ex64hi(phys_pos), ex64lo(phys_pos), ext_size, flag_rw, r, - res_size); + printf("Filter: transfer: read_write(%"PRIx64", %u, %d) = %d, %u\n", + phys_pos, ext_size, flag_rw, r, res_size); #endif if (r != OK) { diff --git a/drivers/filter/util.c b/drivers/filter/util.c index 1c5b4ef21..f57319874 100644 --- a/drivers/filter/util.c +++ b/drivers/filter/util.c @@ -38,21 +38,6 @@ void flt_free(char *buf, size_t size, const char *sbuf) free_contig(buf, size); } -/*===========================================================================* - * print64 * - *===========================================================================*/ -char *print64(u64_t p) -{ -#define NB 10 - static int n = 0; - static char buf[NB][100]; - u32_t lo = ex64lo(p), hi = ex64hi(p); - n = (n+1) % NB; - if(!hi) sprintf(buf[n], "%x", lo); - else sprintf(buf[n], "%x%08x", hi, lo); - return buf[n]; -} - /*===========================================================================* * flt_alarm * *===========================================================================*/ diff --git a/lib/libsys/vprintf.c b/lib/libsys/vprintf.c index b6120d052..e66908966 100644 --- a/lib/libsys/vprintf.c +++ b/lib/libsys/vprintf.c @@ -20,16 +20,16 @@ int vprintf(const char *fmt, va_list argp) { int c, charcount = 0; enum { LEFT, RIGHT } adjust; - enum { LONG, INT } intsize; + enum { LLONG, LONG, INT } intsize; int fill; int width, max, len, base; static char X2C_tab[]= "0123456789ABCDEF"; static char x2c_tab[]= "0123456789abcdef"; char *x2c; char *p; - long i; - unsigned long u; - char temp[8 * sizeof(long) / 3 + 2]; + long long i; + unsigned long long u; + char temp[8 * sizeof(long long) / 3 + 2]; while ((c= *fmt++) != 0) { if (c != '%') { @@ -93,13 +93,21 @@ int vprintf(const char *fmt, va_list argp) intsize= LONG; c= *fmt++; } + if (c == 'l' || c == 'L') { + /* "Long long" key, e.g. %lld. */ + intsize= LLONG; + c= *fmt++; + } if (c == 0) break; switch (c) { /* Decimal. */ case 'd': - i= intsize == LONG ? va_arg(argp, long) - : va_arg(argp, int); + switch (intsize) { + case LLONG: i= va_arg(argp, long long); break; + case LONG: i= va_arg(argp, long); break; + case INT: i= va_arg(argp, int); break; + } u= i < 0 ? -i : i; goto int2ascii; @@ -110,7 +118,8 @@ int vprintf(const char *fmt, va_list argp) /* Pointer, interpret as %X or %lX. */ case 'p': - if (sizeof(char *) > sizeof(int)) intsize= LONG; + if (sizeof(char *) > sizeof(long)) intsize= LLONG; + else if (sizeof(char *) > sizeof(int)) intsize= LONG; /* Hexadecimal. %X prints upper case A-F, not %lx. */ case 'X': @@ -122,8 +131,11 @@ int vprintf(const char *fmt, va_list argp) /* Unsigned decimal. */ case 'u': getint: - u= intsize == LONG ? va_arg(argp, unsigned long) - : va_arg(argp, unsigned int); + switch (intsize) { + case LLONG: u= va_arg(argp, unsigned long long); break; + case LONG: u= va_arg(argp, unsigned long); break; + case INT: u= va_arg(argp, unsigned int); break; + } int2ascii: p= temp + sizeof(temp)-1; *p= 0;