2 ** Copyright 2001 Double Precision, Inc.
3 ** See COPYING for distribution information.
12 static const char rcsid
[]="$Id: strsize.c,v 1.2 2003/01/05 04:01:17 mrsam Exp $";
14 static void cat_n(char *buf
, unsigned long n
)
16 char bb
[NUMBUFSIZE
+1];
17 char *p
=bb
+sizeof(bb
)-1;
22 *--p
= "0123456789"[n
% 10];
28 char *libmail_str_sizekb(unsigned long n
, char *sizebuf
)
30 /* If size is less than 1K bytes, display it as 0.xK */
34 strcpy(sizebuf
, "0.");
35 cat_n(sizebuf
, (int)(10 * n
/ 1024 ));
38 /* If size is less than 1 meg, display is as xK */
40 else if (n
< 1024 * 1024)
43 cat_n(sizebuf
, (unsigned long)(n
+512)/1024);
47 /* Otherwise, display in megabytes */
51 unsigned long nm
=(double)n
/ (1024.0 * 1024.0) * 10;
54 cat_n( sizebuf
, nm
/ 10);
56 cat_n( sizebuf
, nm
% 10);