From: Johannes Sixt Date: Thu, 14 Aug 2008 07:39:46 GMT Subject: Re: [PATCH 2] count-objects: add human-readable size option Message-ID: <48A3E142.9060606@viscovery.net> In-Reply-To: <1218687684-11671-1-git-send-email-marcus@griep.us> Marcus Griep schrieb: > +void human_readable_size(char *buf, int buf_size, double size /* in bytes */) > +{ > + char human_readable_prefixes[10] = "BKMGTPEZY"; > + if (buf_size < 5) > + die("insufficient buffer size"); > + int i = 0; > + for (; i < 8 && size >= 1000 ; ++i, size = size / 1024) > + ; > + if (size >= 1000) > + die("size greater than 999Y"); No need to die here. Just make the buffer large enough, and you can have something that is as large as 18446744073709551615Y. -- Hannes