summaryrefslogtreecommitdiff
path: root/strings
diff options
context:
space:
mode:
authorwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-07-25 21:32:45 +0000
committerwrowe <wrowe@13f79535-47bb-0310-9956-ffa450edef68>2001-07-25 21:32:45 +0000
commit3e81aa3669fd886b8dbcf6ca551f0a807769440b (patch)
treef9430fdcf2be24ab5fe302147c75ece2de13bd96 /strings
parent346dcc0c1e42f9f5c338ec1c83b4553d1f54122c (diff)
downloadlibapr-3e81aa3669fd886b8dbcf6ca551f0a807769440b.tar.gz
Replace the very limited-use ap_send_size with apr_strfsize(), which
works within a fixed buffer. I'm open to using the old ap_send_size() text formatting, but this result is one character shorter in size and equally readable. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/trunk@62023 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'strings')
-rw-r--r--strings/apr_strings.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/strings/apr_strings.c b/strings/apr_strings.c
index d7ae082b6..01ea9ff5f 100644
--- a/strings/apr_strings.c
+++ b/strings/apr_strings.c
@@ -235,3 +235,37 @@ APR_DECLARE(char *) apr_off_t_toa(apr_pool_t *p, apr_off_t n)
}
return start;
}
+
+APR_DECLARE(char *) apr_strfsize(apr_off_t size, char *buf)
+{
+ const char ord[] = "KMTPE";
+ const char *o = ord;
+ int remain;
+
+ if (size < 0) {
+ return strcpy(buf, " - ");
+ }
+ if (size < 973) {
+ sprintf(buf, "%3d ", (int) size, o);
+ return buf;
+ }
+ do {
+ remain = (int)(size & 1023);
+ size >>= 10;
+ if (size >= 973) {
+ ++o;
+ continue;
+ }
+ if (size < 9 || (size == 9 && remain < 973)) {
+ if ((remain = ((remain * 5) + 256) / 512) >= 10)
+ ++size, remain = 0;
+ sprintf(buf, "%d.%d%c", (int) size, remain, *o);
+ return buf;
+ }
+ if (remain >= 512)
+ ++size;
+ sprintf(buf, "%3d%c", (int) size, *o);
+ return buf;
+ } while (1);
+}
+