aboutsummaryrefslogtreecommitdiffstats
path: root/src/output.c
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2009-11-24 09:37:53 -0500
committerKevin O'Connor <kevin@koconnor.net>2009-11-24 09:37:53 -0500
commit2be312c112a5ccfcd165f7ba3276e3aaf33ee92c (patch)
tree68538bbc722189cd6aeda42cfd7ace642cd1d8b8 /src/output.c
parent42bc3940d93911e382f5e72289f043d1faa9083e (diff)
downloadseabios-2be312c112a5ccfcd165f7ba3276e3aaf33ee92c.tar.gz
Update snprintf to return the number of bytes used.
Diffstat (limited to 'src/output.c')
-rw-r--r--src/output.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/output.c b/src/output.c
index 7f74a69e..7e91bfe1 100644
--- a/src/output.c
+++ b/src/output.c
@@ -376,12 +376,15 @@ putc_str(struct putcinfo *info, char c)
sinfo->str++;
}
-void
+// Build a formatted string. Note, this function returns the actual
+// number of bytes used (not including null) even in the overflow
+// case.
+int
snprintf(char *str, size_t size, const char *fmt, ...)
{
ASSERT32();
if (!size)
- return;
+ return 0;
struct snprintfinfo sinfo = { { putc_str }, str, str + size };
va_list args;
va_start(args, fmt);
@@ -389,8 +392,9 @@ snprintf(char *str, size_t size, const char *fmt, ...)
va_end(args);
char *end = sinfo.str;
if (end >= sinfo.end)
- end--;
+ end = sinfo.end - 1;
*end = '\0';
+ return end - str;
}