From: William A. Rowe Jr Date: Wed, 25 Jul 2001 21:34:15 +0000 (+0000) Subject: Change over to apr_strfsize() for apr_off_t file size formatting. X-Git-Tag: 2.0.22~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5b9603140957b696f5648249cad38f94c01ae660;p=thirdparty%2Fapache%2Fhttpd.git Change over to apr_strfsize() for apr_off_t file size formatting. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@89713 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/include/util_script.h b/include/util_script.h index 4e436bf0b1b..1cf8796b6ad 100644 --- a/include/util_script.h +++ b/include/util_script.h @@ -160,17 +160,6 @@ AP_DECLARE(int) ap_scan_script_header_err_core(request_rec *r, char *buffer, int (*getsfunc) (char *, int, void *), void *getsfunc_data); -/** - * Convert the file size given in size into a formatted string and send the - * string to the client. The size should always be in bytes, although the - * string sent to the client may be in bytes, kb, or MB, depending on the size - * of the file. - * @param size The size of the file - * @param r The currnt request - * @deffunc void ap_send_size(apr_ssize_t size, request_rec *r) - */ -AP_DECLARE(void) ap_send_size(apr_ssize_t size, request_rec *r); - #ifdef __cplusplus } #endif diff --git a/modules/filters/mod_include.c b/modules/filters/mod_include.c index b4540074b35..a375712ad23 100644 --- a/modules/filters/mod_include.c +++ b/modules/filters/mod_include.c @@ -1079,33 +1079,6 @@ static int find_file(request_rec *r, const char *directive, const char *tag, } } -#define NEG_SIGN " -" -#define ZERO_K " 0k" -#define ONE_K " 1k" - -static void generate_size(apr_ssize_t size, char *buff, apr_size_t buff_size) -{ - /* XXX: this -1 thing is a gross hack */ - if (size == (apr_ssize_t)-1) { - memcpy (buff, NEG_SIGN, sizeof(NEG_SIGN)+1); - } - else if (!size) { - memcpy (buff, ZERO_K, sizeof(ZERO_K)+1); - } - else if (size < 1024) { - memcpy (buff, ONE_K, sizeof(ONE_K)+1); - } - else if (size < 1048576) { - apr_snprintf(buff, buff_size, "%4" APR_SSIZE_T_FMT "k", (size + 512) / 1024); - } - else if (size < 103809024) { - apr_snprintf(buff, buff_size, "%4.1fM", size / 1048576.0); - } - else { - apr_snprintf(buff, buff_size, "%4" APR_SSIZE_T_FMT "M", (size + 524288) / 1048576); - } -} - static int handle_fsize(include_ctx_t *ctx, apr_bucket_brigade **bb, request_rec *r, ap_filter_t *f, apr_bucket *head_ptr, apr_bucket **inserted_head) { @@ -1134,7 +1107,7 @@ static int handle_fsize(include_ctx_t *ctx, apr_bucket_brigade **bb, request_rec char buff[50]; if (!(ctx->flags & FLAG_SIZE_IN_BYTES)) { - generate_size(finfo.size, buff, sizeof(buff)); + apr_strfsize(finfo.size, buff); s_len = strlen (buff); } else { diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index 8906251ddcb..90575c5d86a 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -1355,7 +1355,7 @@ static void output_directories(struct ent **ar, int n, if (!(autoindex_opts & SUPPRESS_LAST_MOD)) { emit_link(r, "Last modified", K_LAST_MOD, keyid, direction, static_columns); - ap_rputs(" ", r); + ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_SIZE)) { emit_link(r, "Size", K_SIZE, keyid, direction, static_columns); @@ -1445,7 +1445,8 @@ static void output_directories(struct ent **ar, int n, } } if (!(autoindex_opts & SUPPRESS_SIZE)) { - ap_send_size(ar[x]->size, r); + char buf[5]; + ap_rputs(apr_strfsize(ar[x]->size, buf), r); ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_DESC)) { diff --git a/modules/test/mod_autoindex.c b/modules/test/mod_autoindex.c index d875082a85d..f01365c0434 100644 --- a/modules/test/mod_autoindex.c +++ b/modules/test/mod_autoindex.c @@ -1442,7 +1442,8 @@ static void output_directories(struct ent **ar, int n, } } if (!(autoindex_opts & SUPPRESS_SIZE)) { - ap_send_size(ar[x]->size, r); + char buf[5]; + ap_rputs(apr_strfsize(ar[x]->size, buf), r); ap_rputs(" ", r); } if (!(autoindex_opts & SUPPRESS_DESC)) { diff --git a/server/util_script.c b/server/util_script.c index f6d3e483f09..c80fba1d83a 100644 --- a/server/util_script.c +++ b/server/util_script.c @@ -634,27 +634,3 @@ AP_DECLARE_NONSTD(int) ap_scan_script_header_err_strs(request_rec *r, va_end(strs.args); return res; } - -AP_DECLARE(void) ap_send_size(apr_ssize_t size, request_rec *r) -{ - /* XXX: this -1 thing is a gross hack */ - if (size == (apr_ssize_t)-1) { - ap_rputs(" -", r); - } - else if (!size) { - ap_rputs(" 0k", r); - } - else if (size < 1024) { - ap_rputs(" 1k", r); - } - else if (size < 1048576) { - ap_rprintf(r, "%4" APR_SSIZE_T_FMT "k", (size + 512) / 1024); - } - else if (size < 103809024) { - ap_rprintf(r, "%4.1fM", size / 1048576.0); - } - else { - ap_rprintf(r, "%4" APR_SSIZE_T_FMT "M", (size + 524288) / 1048576); - } -} -