X-Git-Url: https://git.cryptolib.org/?p=arm-crypto-lib.git;a=blobdiff_plain;f=test_src%2Fstring-extras.c;h=18cf67f6f5ced5fc8cbdc8d080ca1ff462bff334;hp=f4c95a2421dd567eac1e2ccb5b14d77a5f456807;hb=a0b23b3327c8bc2ecd7278c95662fdebf6f15d6b;hpb=5f46191d2615ebe2caa6e111b478031a34f20b9e diff --git a/test_src/string-extras.c b/test_src/string-extras.c index f4c95a2..18cf67f 100644 --- a/test_src/string-extras.c +++ b/test_src/string-extras.c @@ -1,7 +1,7 @@ /* string_extras.c */ /* This file is part of the ARM-Crypto-Lib. - Copyright (C) 2006-2010 Daniel Otte (daniel.otte@rub.de) + Copyright (C) 2008 Daniel Otte (daniel.otte@rub.de) This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,6 +29,8 @@ #include #include +#include "cli.h" + uint32_t stridentcnt(const char* a, const char* b){ uint16_t i=0; for(;;){ @@ -42,8 +44,13 @@ uint32_t stridentcnt(const char* a, const char* b){ uint16_t firstword_length(const char* s){ uint16_t ret=0; - while(isgraph(*s++)) + if(!s){ + return 0; + } + int c; + while(c=*s++, isgraph(c)){ ret++; + } return ret; } @@ -89,7 +96,11 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){ return buffer; } while(a){ + /* toolchain bug?? result = div(a, radix); + */ + result.quot = a/radix; + result.rem = a%radix; *ptr = result.rem; if(result.rem<10){ *ptr += '0'; @@ -104,12 +115,14 @@ char* ultoa(unsigned long a, char* buffer, uint8_t radix){ return buffer; } + char* ulltoa(unsigned long long a, char* buffer, uint8_t radix){ if(radix<2 || radix>36){ return NULL; } char* ptr=buffer; uint8_t rem; + unsigned long long quot; if(a==0){ ptr[0] = '0'; ptr[1] = '\0'; @@ -117,14 +130,14 @@ char* ulltoa(unsigned long long a, char* buffer, uint8_t radix){ } while(a){ rem = a % radix; - a = a / radix; - *ptr = rem; + quot = a / radix; if(rem<10){ - *ptr += '0'; + rem += '0'; }else{ - *ptr += 'a'-10; + rem += 'a'-10; } - ++ptr; + *ptr++ =rem; + a = quot; } *ptr = '\0'; str_reverse(buffer);