Change the behavior of the parse_unit code to return the number of

bytes needed to print the whole string (minus the trailing '\0'), just
like snprintf.  Idea from bugreport from Gabriel Kihlman <gk@stacken.kth.se>.


git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@14324 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Love Hörnquist Åstrand
2004-10-30 22:33:08 +00:00
parent 9f27ea17bf
commit 78e5e11b1a
2 changed files with 12 additions and 4 deletions

View File

@@ -212,9 +212,13 @@ unparse_something (int num, const struct units *units, char *s, size_t len,
tmp = (*print) (s, len, div, u->name, num);
if (tmp < 0)
return tmp;
len -= tmp;
s += tmp;
if (tmp > len) {
len = 0;
s = NULL;
} else {
len -= tmp;
s += tmp;
}
ret += tmp;
}
}