return *a < *b ? -1 : *a > *b;
}
+
+char *
+strtok_r (char *s, const char *delimiters, char **save_ptr)
+{
+ char *token;
+
+ ASSERT (delimiters != NULL);
+ ASSERT (save_ptr != NULL);
+
+ /* If S is nonnull, start from it.
+ If S is null, start from saved position. */
+ if (s == NULL)
+ s = *save_ptr;
+ ASSERT (s != NULL);
+
+ /* Skip any DELIMITERS at our current position. */
+ while (strchr (delimiters, *s) != NULL)
+ {
+ /* strchr() will always return nonnull if we're searching
+ for a null byte, because every string contains a null
+ byte (at the end). */
+ if (*s == '\0')
+ {
+ *save_ptr = s;
+ return NULL;
+ }
+
+ s++;
+ }
+
+ /* Skip any non-DELIMITERS up to the end of the string. */
+ token = s;
+ while (strchr (delimiters, *s) == NULL)
+ s++;
+ if (*s != '\0')
+ {
+ *s = '\0';
+ *save_ptr = s + 1;
+ }
+ else
+ *save_ptr = s;
+ return token;
+}
+
+int
+atoi (const char *s)
+{
+ bool negative;
+ int value;
+
+ /* Skip white space. */
+ while (isspace (*s))
+ s++;
+
+ /* Parse sign. */
+ negative = false;
+ if (*s == '+')
+ s++;
+ else if (*s == '-')
+ {
+ negative = true;
+ s++;
+ }
+
+ /* Parse digits. We always initially parse the value as
+ negative, and then make it positive later, because the
+ negative range of an int is bigger than the positive range
+ on a 2's complement system. */
+ for (value = 0; isdigit (*s); s++)
+ value = value * 10 - (*s - '0');
+ if (!negative)
+ value = -value;
+
+ return value;
+}
\f
static void
vprintf_core (const char *format, va_list args,
void
vprintk (const char *format, va_list args)
{
- enum if_level old_level = intr_disable ();
+ enum intr_level old_level = intr_disable ();
vprintf_core (format, args, vprintk_helper, NULL);
intr_set_level (old_level);
}
}
\f
void
-hex_dump (const void *buffer, size_t size)
+hex_dump (const void *buffer, size_t size, bool ascii)
{
const size_t n_per_line = 16;
const uint8_t *p = buffer;
printk ("%08zx", ofs);
n = size >= n_per_line ? n_per_line : size;
for (i = 0; i < n; i++)
- printk ("%c%02x", i == n / 2 ? '-' : ' ', (unsigned) p[i]);
- for (; i < n_per_line; i++)
- printk (" ");
- printk (" |");
- for (i = 0; i < n; i++)
- printk ("%c", isprint (p[i]) ? p[i] : '.');
- for (; i < n_per_line; i++)
- printk (" ");
- printk ("|\n");
+ printk ("%c%02x", i == n_per_line / 2 ? '-' : ' ', (unsigned) p[i]);
+
+ if (ascii)
+ {
+ for (; i < n_per_line; i++)
+ printk (" ");
+ printk (" |");
+ for (i = 0; i < n; i++)
+ printk ("%c", isprint (p[i]) ? p[i] : '.');
+ for (; i < n_per_line; i++)
+ printk (" ");
+ printk ("|");
+ }
+ printk ("\n");
p += n;
ofs += n;