Skip to content

Commit

Permalink
Add support for 'z' precision prefix to format strings
Browse files Browse the repository at this point in the history
The 'z' precision prefix is very useful when formatting values of type
size_t and it is part of the C99 standard.

So add support for this to the function format_str_v(). This function is
used for example when formatting log output.
  • Loading branch information
jakeru committed Jun 9, 2020
1 parent ac3f63e commit bc1070c
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions os/lib/dbg-io/strformat.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,17 @@ format_str_v(const strformat_context_t *ctxt, const char *format, va_list ap)
} else {
flags |= SIZE_SHORT;
}
} else if(*pos == 'z') {
if(sizeof(size_t) == sizeof(short)) {
flags |= SIZE_SHORT;
} else if(sizeof(size_t) == sizeof(long)) {
flags |= SIZE_LONG;
#ifdef HAVE_LONGLONG
} else if(sizeof(size_t) == sizeof(long long)) {
flags |= SIZE_LONGLONG;
}
#endif
pos++;
}

/* parse conversion specifier */
Expand Down

0 comments on commit bc1070c

Please sign in to comment.