From a84f393bd5c17be23160eafdb27cae74a102090d Mon Sep 17 00:00:00 2001 From: Aurora Date: Tue, 30 Aug 2016 21:32:15 +0200 Subject: [PATCH] Move the itoa function to strings.c --- source/fs.c | 11 +---------- source/strings.c | 14 ++++++++++++++ source/strings.h | 3 ++- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/source/fs.c b/source/fs.c index 3eb247c..ff3e692 100644 --- a/source/fs.c +++ b/source/fs.c @@ -181,17 +181,8 @@ u32 firmRead(void *dest, u32 firmType) //Complete the string with the .app name concatenateStrings(path, "/00000000.app"); - //Last digit of the .app - u32 i = 42; - //Convert back the .app name from integer to array - u32 tempVersion = firmVersion; - while(tempVersion) - { - static const char hexDigits[] = "0123456789ABCDEF"; - path[i--] = hexDigits[tempVersion & 0xF]; - tempVersion >>= 4; - } + hexItoa(firmVersion, &path[35]); fileRead(dest, path); diff --git a/source/strings.c b/source/strings.c index adaa712..9d0bb2d 100644 --- a/source/strings.c +++ b/source/strings.c @@ -38,4 +38,18 @@ void concatenateStrings(char *destination, const char *source) j = strlen(destination); memcpy(&destination[j], source, i + 1); +} + +void hexItoa(u32 number, char *out) +{ + const char hexDigits[] = "0123456789ABCDEF"; + u32 i = 0; + + while(number > 0) + { + out[7 - i++] = hexDigits[number & 0xF]; + number >>= 4; + } + + for(; i < 8; i++) out[7 - i] = '0'; } \ No newline at end of file diff --git a/source/strings.h b/source/strings.h index f6b035f..f6ac599 100644 --- a/source/strings.h +++ b/source/strings.h @@ -25,4 +25,5 @@ #include "types.h" int strlen(const char *string); -void concatenateStrings(char *destination, const char *source); \ No newline at end of file +void concatenateStrings(char *destination, const char *source); +void hexItoa(u32 number, char *out); \ No newline at end of file