From 164e9a7b879ce7fd282a50006ce6c90069bb1bbe Mon Sep 17 00:00:00 2001 From: gardners Date: Sat, 6 Oct 2012 07:00:41 +0200 Subject: [PATCH] removed dependency on -lm log2 to make Android building easier. --- rhizome_packetformats.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/rhizome_packetformats.c b/rhizome_packetformats.c index 55191f41..ff471cd1 100644 --- a/rhizome_packetformats.c +++ b/rhizome_packetformats.c @@ -24,12 +24,26 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. #include "overlay_address.h" #include "overlay_packet.h" #include -#include #include #include #include #include +/* Android doesn't have log2(), and we don't really need to do floating point + math to work out how big a file is. + */ +int log2ll(unsigned long long x) +{ + unsigned char lookup[16]={0,1,2,2,3,3,3,3,4,4,4,4,4,4,4,4}; + int v=-1; + if (x>0xffffffff) { v+=32; x=x>>32LL; } + if (x>0xffff) { v+=16; x=x>>16LL; } + if (x>0xff) { v+= 8; x=x>> 8LL; } + if (x>0xf) { v+= 4; x=x>> 4LL; } + v+=lookup[x&0xf]; + return v; +} + int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar) { @@ -71,7 +85,7 @@ int rhizome_manifest_to_bar(rhizome_manifest *m,unsigned char *bar) for(i=0;icryptoSignPublic[i]; /* file length */ - bar[RHIZOME_BAR_FILESIZE_OFFSET]=log2(m->fileLength); + bar[RHIZOME_BAR_FILESIZE_OFFSET]=log2ll(m->fileLength); /* Version */ for(i=0;i<7;i++) bar[RHIZOME_BAR_VERSION_OFFSET+6-i]=(m->version>>(8*i))&0xff;