X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flib%2Fstdio.c;h=4b0ba1967f2698bbce124fd4cad9bfb3ac17ff95;hb=75efee76500d95f53adf73e178b4a9872d93f131;hp=95dfdbe66273b8c8557813e0064b9f60b08afd0f;hpb=404ff9b49909b1648cef613e66d2c54a345e72ad;p=pintos-anon diff --git a/src/lib/stdio.c b/src/lib/stdio.c index 95dfdbe..4b0ba19 100644 --- a/src/lib/stdio.c +++ b/src/lib/stdio.c @@ -1,5 +1,7 @@ -#include #include +#include +#include +#include #include #include @@ -198,6 +200,9 @@ __vprintf (const char *format, va_list args, case INT: value = va_arg (args, int); break; + case INTMAX: + value = va_arg (args, intmax_t); + break; case LONG: value = va_arg (args, long); break; @@ -239,6 +244,9 @@ __vprintf (const char *format, va_list args, case INT: value = va_arg (args, unsigned); break; + case INTMAX: + value = va_arg (args, uintmax_t); + break; case LONG: value = va_arg (args, unsigned long); break; @@ -552,51 +560,55 @@ __printf (const char *format, __vprintf (format, args, output, aux); va_end (args); } - -/* Writes string S to the console, followed by a new-line - character. */ -int -puts (const char *s) -{ - while (*s != '\0') - putchar (*s++); - putchar ('\n'); - return 0; -} -/* Dumps the SIZE bytes in BUFFER to the console as hex bytes - arranged 16 per line. If ASCII is true then the corresponding - ASCII characters are also rendered alongside. */ +/* Dumps the SIZE bytes in BUF to the console as hex bytes + arranged 16 per line. Numeric offsets are also included, + starting at OFS for the first byte in BUF. If ASCII is true + then the corresponding ASCII characters are also rendered + alongside. */ void -hex_dump (const void *buffer, size_t size, bool ascii) +hex_dump (uintptr_t ofs, const void *buf_, size_t size, bool ascii) { - const size_t n_per_line = 16; /* Maximum bytes per line. */ - size_t n; /* Number of bytes in this line. */ - const uint8_t *p; /* Start of current line in buffer. */ + const uint8_t *buf = buf_; + const size_t per_line = 16; /* Maximum bytes per line. */ - for (p = buffer; p < (uint8_t *) buffer + size; p += n) + while (size > 0) { + size_t start, end, n; size_t i; - + /* Number of bytes on this line. */ - n = (uint8_t *) (buffer + size) - p; - if (n > n_per_line) - n = n_per_line; + start = ofs % per_line; + end = per_line; + if (end - start > size) + end = start + size; + n = end - start; /* Print line. */ - for (i = 0; i < n; i++) - printf ("%c%02x", i == n_per_line / 2 ? '-' : ' ', (unsigned) p[i]); + printf ("%08jx ", (uintmax_t) ROUND_DOWN (ofs, per_line)); + for (i = 0; i < start; i++) + printf (" "); + for (; i < end; i++) + printf ("%02hhx%c", + buf[i - start], i == per_line / 2 - 1? '-' : ' '); if (ascii) { - for (; i < n_per_line; i++) + for (; i < per_line; i++) printf (" "); - printf (" |"); - for (i = 0; i < n; i++) - printf ("%c", isprint (p[i]) ? p[i] : '.'); - for (; i < n_per_line; i++) + printf ("|"); + for (i = 0; i < start; i++) + printf (" "); + for (; i < end; i++) + printf ("%c", + isprint (buf[i - start]) ? buf[i - start] : '.'); + for (; i < per_line; i++) printf (" "); printf ("|"); } printf ("\n"); + + ofs += n; + buf += n; + size -= n; } }