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
}
}
-#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)
{
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 {
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);
}
}
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)) {
}
}
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)) {
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);
- }
-}
-