- start Apache__Util.h
- port Apache::Util::size_string
- add tests
BTW, any reason why size_string doesn't handle '%dG' format, for GiB? Is
it because the perl IV data type couldn't hold that size? From perl.h:
/*
The IV type is supposed to be long enough to hold any integral
value or a pointer.
--Andy Dougherty August 1996
*/
Index: xs/maps/modperl_functions.map
===================================================================
RCS file: /home/cvs/modperl-2.0/xs/maps/modperl_functions.map,v
retrieving revision 1.33
diff -u -r1.33 modperl_functions.map
--- xs/maps/modperl_functions.map 21 Jan 2002 08:27:30 -0000 1.33
+++ xs/maps/modperl_functions.map 25 Jan 2002 08:21:20 -0000
@@ -98,3 +98,6 @@
MODULE=Apache::SubProcess
# ap_subprocess_ won't work
modperl_spawn_proc_prog | MPXS_ | ... | spawn_proc_prog
+
+MODULE=Apache::Util
+ mpxs_Apache__Util_size_string
--- /dev/null Thu Jan 1 07:30:00 1970
+++ t/response/TestApache/util.pm Fri Jan 25 13:44:55 2002
@@ -0,0 +1,34 @@
+package TestApache::util;
+
+use strict;
+use warnings FATAL => 'all';
+
+use Apache::Test;
+use Apache::TestUtil;
+use Apache::Util ();
+use Apache::Const -compile => 'OK';
+
+my %size = (
+ '-1' => " -",
+ 0 => " 0k",
+ 42 => " 1k",
+ 42_000 => " 41k",
+ 42_000_000 => "40.1M",
+ 4_200_000_000 => "4005M",
+);
+
+sub handler {
+ my $r = shift;
+
+ plan $r, tests => 6;
+
+ t_debug("size_string");
+ while (my($k, $v) = each %size) {
+ ok t_cmp($v, Apache::Util::size_string($k));
+ }
+
+ Apache::OK;
+}
+
+1;
+__END__
--- /dev/null Thu Jan 1 07:30:00 1970
+++ xs/Apache/Util/Apache__Util.h Fri Jan 25 16:20:55 2002
@@ -0,0 +1,26 @@
+static MP_INLINE
+SV *mpxs_Apache__Util_size_string(pTHX_ size_t size)
+{
+ SV *sv = newSVpv(" -", 5);
+
+ if (size == (size_t)-1) {
+
/**/
+ }
+ else if (!size) {
+
sv_setpv(sv, " 0k");
+ }
+ else if (size < 1024) {
+
sv_setpv(sv, " 1k");
+ }
+ else if (size < 1048576) {
+
sv_setpvf(sv, "%4dk", (size + 512) / 1024);
+ }
+ else if (size < 103809024) {
+
sv_setpvf(sv, "%4.1fM", size / 1048576.0);
+ }
+ else {
+
sv_setpvf(sv, "%4dM", (size + 524288) / 1048576);
+ }
+
+ return sv;
+}
_____________________________________________________________________
Stas Bekman JAm_pH -- Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide http://perl.apache.org/guide
mailto:[EMAIL PROTECTED] http://ticketmaster.com http://apacheweek.com
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]