diff options
author | Tom Hughes <tomhughes@chromium.org> | 2022-06-17 15:47:18 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-07-19 17:55:21 +0000 |
commit | 1bc7945394c90dd2b00d8ea7c9201dc368904718 (patch) | |
tree | 77b11ce134657aec9efab0c8d23ab11aa26a7469 /common | |
parent | 3eb29b6aa5a4e5e8c85046be789c6dd8d38afbaa (diff) | |
download | chrome-ec-1bc7945394c90dd2b00d8ea7c9201dc368904718.tar.gz |
tree: Move printf declarations to stdio.h
The "builtin" directory is EC's copy of the C standard library headers.
Move the declarations for printf functions that are provided by the
standard library to the "builtin" directory. This change makes it easier
for future changes to optionally build with the C standard library
instead of the standalone EC subset.
BRANCH=none
BUG=b:172020503, b:234181908, b:237823627
TEST=make buildall
Signed-off-by: Tom Hughes <tomhughes@chromium.org>
Change-Id: I4a5b4f8b98b972e86c4cca65d4910b5aa07ec524
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3712034
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/printf.c | 56 |
1 files changed, 0 insertions, 56 deletions
diff --git a/common/printf.c b/common/printf.c index 9a3e593cba..91e4e722b0 100644 --- a/common/printf.c +++ b/common/printf.c @@ -488,59 +488,3 @@ int vfnprintf(int (*addchar)(void *context, int c), void *context, /* If we're still here, we consumed all output */ return EC_SUCCESS; } - -/* Context for snprintf() */ -struct snprintf_context { - char *str; - int size; -}; - -/** - * 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; - - if (!ctx->size) - return 1; - - *(ctx->str++) = c; - ctx->size--; - return 0; -} - -int crec_snprintf(char *str, size_t size, const char *format, ...) -{ - va_list args; - int rv; - - va_start(args, format); - rv = crec_vsnprintf(str, size, format, args); - va_end(args); - - return rv; -} - -int crec_vsnprintf(char *str, size_t size, const char *format, va_list args) -{ - struct snprintf_context ctx; - int rv; - - if (!str || !format || size <= 0) - return -EC_ERROR_INVAL; - - ctx.str = str; - ctx.size = size - 1; /* Reserve space for terminating '\0' */ - - rv = vfnprintf(snprintf_addchar, &ctx, format, args); - - /* Terminate string */ - *ctx.str = '\0'; - - return (rv == EC_SUCCESS) ? (ctx.str - str) : -rv; -} |