diff options
author | Randall Spangler <rspangler@chromium.org> | 2012-10-25 12:46:08 -0700 |
---|---|---|
committer | Gerrit <chrome-bot@google.com> | 2012-10-25 14:12:10 -0700 |
commit | e228692eb2b3828ee39adf5a668e71208478226a (patch) | |
tree | 18b2febd911da8de8a6d7515701fdd3a42494b7c /common/printf.c | |
parent | f3d1fe08555de0157a27472ef68d1230bf60115b (diff) | |
download | chrome-ec-e228692eb2b3828ee39adf5a668e71208478226a.tar.gz |
Clean up printf module
No functional changes.
BUG=chrome-os-partner:15579
BRANCH=none
TEST=boot system; debug output still shows up on EC console
Change-Id: I63f4f9481f5393aaff065b37a274236bd78622d9
Signed-off-by: Randall Spangler <rspangler@chromium.org>
Reviewed-on: https://gerrit.chromium.org/gerrit/36581
Reviewed-by: Bill Richardson <wfrichar@chromium.org>
Diffstat (limited to 'common/printf.c')
-rw-r--r-- | common/printf.c | 32 |
1 files changed, 22 insertions, 10 deletions
diff --git a/common/printf.c b/common/printf.c index b356e0e58a..dad02ac4c7 100644 --- a/common/printf.c +++ b/common/printf.c @@ -13,6 +13,13 @@ static const char error_str[] = "ERROR"; #define MAX_FORMAT 1024 /* Maximum chars in a single format field */ +/** + * Convert a single digit to hex + * + * @param c Value of digit (0 - 0x0f) + * + * @return The corresponding ASCII character ('0' - 'f'). + */ static int hexdigit(int c) { return c > 9 ? (c + 'a' - 10) : (c + '0'); @@ -21,10 +28,11 @@ static int hexdigit(int c) int vfnprintf(int (*addchar)(void *context, int c), void *context, const char *format, va_list args) { + /* + * Longest uint64 in decimal = 20 + * longest uint32 in binary = 32 + */ char intbuf[34]; - /* Longest uint64 in decimal = 20 - * longest uint32 in binary = 32 - */ int dropped_chars = 0; int is_left; int pad_zero; @@ -185,8 +193,10 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, if (format == error_str) continue; /* Bad format specifier */ - /* Convert integer to string, starting at end of - * buffer and working backwards. */ + /* + * Convert integer to string, starting at end of + * buffer and working backwards. + */ vstr = intbuf + sizeof(intbuf) - 1; *(vstr) = '\0'; @@ -256,15 +266,19 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, return dropped_chars ? EC_ERROR_OVERFLOW : EC_SUCCESS; } - /* Context for snprintf() */ struct snprintf_context { char *str; int size; }; - -/* Add a character to the string */ +/** + * Add a character to the string context. + * + * @param context Context receiving character + * @param c Character to add + * @return 0 if character added, 1 if character dropped because no space. + */ static int snprintf_addchar(void *context, int c) { struct snprintf_context *ctx = (struct snprintf_context *)context; @@ -277,8 +291,6 @@ static int snprintf_addchar(void *context, int c) return 0; } - -/* Print formatted outut to a string */ int snprintf(char *str, int size, const char *format, ...) { struct snprintf_context ctx; |