From 9ab7a6c75566a2d06e56a8a97173c6382a3c5b3d Mon Sep 17 00:00:00 2001 From: marcansoft Date: Sun, 21 Feb 2010 00:10:28 +0000 Subject: [PATCH] Split str* and mem* into string.[ch] --- armsrc/Makefile | 1 + armsrc/appmain.c | 11 +++----- armsrc/fpgaloader.c | 1 + armsrc/hitag2.c | 2 +- armsrc/iso14443.c | 1 + armsrc/iso14443a.c | 2 ++ armsrc/iso15693.c | 1 + armsrc/legicrf.c | 1 + armsrc/lfops.c | 1 + armsrc/printf.c | 1 + armsrc/printf.h | 2 -- armsrc/string.c | 62 +++++++++++++++++++++++++++++++++++++++++++++ armsrc/string.h | 10 ++++++++ armsrc/util.c | 60 +------------------------------------------ armsrc/util.h | 6 +---- 15 files changed, 88 insertions(+), 74 deletions(-) create mode 100644 armsrc/string.c create mode 100644 armsrc/string.h diff --git a/armsrc/Makefile b/armsrc/Makefile index 0aa4ea6b..967bf097 100644 --- a/armsrc/Makefile +++ b/armsrc/Makefile @@ -19,6 +19,7 @@ THUMBSRC = start.c \ $(SRC_LF) \ appmain.c printf.c \ util.c \ + string.c \ usb.c # These are to be compiled in ARM mode diff --git a/armsrc/appmain.c b/armsrc/appmain.c index c2ea9f7d..62f13fd4 100644 --- a/armsrc/appmain.c +++ b/armsrc/appmain.c @@ -8,6 +8,10 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" +#include "printf.h" +#include "string.h" + +#include #include "legicrf.h" @@ -16,13 +20,6 @@ # include "LCD.h" #endif -#define va_list __builtin_va_list -#define va_start __builtin_va_start -#define va_arg __builtin_va_arg -#define va_end __builtin_va_end -int kvsprintf(char const *fmt, void *arg, int radix, va_list ap); - - #define abs(x) ( ((x)<0) ? -(x) : (x) ) //============================================================================= diff --git a/armsrc/fpgaloader.c b/armsrc/fpgaloader.c index c093c73c..50a6521d 100644 --- a/armsrc/fpgaloader.c +++ b/armsrc/fpgaloader.c @@ -7,6 +7,7 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" +#include "string.h" //----------------------------------------------------------------------------- // Set up the Serial Peripheral Interface as master diff --git a/armsrc/hitag2.c b/armsrc/hitag2.c index 1278b758..875eba2a 100644 --- a/armsrc/hitag2.c +++ b/armsrc/hitag2.c @@ -10,8 +10,8 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" - #include "hitag2.h" +#include "string.h" struct hitag2_cipher_state { uint64_t state; diff --git a/armsrc/iso14443.c b/armsrc/iso14443.c index 0e446abe..f50d7cb9 100644 --- a/armsrc/iso14443.c +++ b/armsrc/iso14443.c @@ -7,6 +7,7 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" +#include "string.h" #include "iso14443crc.h" diff --git a/armsrc/iso14443a.c b/armsrc/iso14443a.c index 409bd3d6..e60f3198 100644 --- a/armsrc/iso14443a.c +++ b/armsrc/iso14443a.c @@ -6,6 +6,8 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" +#include "string.h" + #include "iso14443crc.h" static uint8_t *trace = (uint8_t *) BigBuf; diff --git a/armsrc/iso15693.c b/armsrc/iso15693.c index 30a631e8..31c13e95 100644 --- a/armsrc/iso15693.c +++ b/armsrc/iso15693.c @@ -11,6 +11,7 @@ #include "proxmark3.h" #include "util.h" #include "apps.h" +#include "string.h" // FROM winsrc\prox.h ////////////////////////////////// #define arraylen(x) (sizeof(x)/sizeof((x)[0])) diff --git a/armsrc/legicrf.c b/armsrc/legicrf.c index eb38939d..b3ac89bd 100644 --- a/armsrc/legicrf.c +++ b/armsrc/legicrf.c @@ -7,6 +7,7 @@ #include "proxmark3.h" #include "apps.h" #include "util.h" +#include "string.h" #include "legicrf.h" #include "legic_prng.h" diff --git a/armsrc/lfops.c b/armsrc/lfops.c index 93c0cbde..dcc9e54d 100644 --- a/armsrc/lfops.c +++ b/armsrc/lfops.c @@ -9,6 +9,7 @@ #include "util.h" #include "hitag2.h" #include "crc16.h" +#include "string.h" void AcquireRawAdcSamples125k(int at134khz) { diff --git a/armsrc/printf.c b/armsrc/printf.c index 49537c64..d5e61798 100644 --- a/armsrc/printf.c +++ b/armsrc/printf.c @@ -38,6 +38,7 @@ #include #include "printf.h" #include "util.h" +#include "string.h" typedef uint32_t uintmax_t; typedef int32_t intmax_t; diff --git a/armsrc/printf.h b/armsrc/printf.h index 5c2ade8c..b1d613c1 100644 --- a/armsrc/printf.h +++ b/armsrc/printf.h @@ -7,6 +7,4 @@ int kvsprintf(const char *format, void *arg, int radix, va_list ap) __attribute_ int vsprintf(char *str, const char *format, va_list ap) __attribute__ ((format (printf, 2, 0))); int sprintf(char *str, const char *format, ...) __attribute__ ((format (printf, 2, 3))); - - #endif \ No newline at end of file diff --git a/armsrc/string.c b/armsrc/string.c new file mode 100644 index 00000000..a3d3c049 --- /dev/null +++ b/armsrc/string.c @@ -0,0 +1,62 @@ +/* Implementations of the common string.h functions */ +#include "string.h" +#include + +void *memcpy(void *dest, const void *src, int len) +{ + uint8_t *d = dest; + const uint8_t *s = src; + while((len--) > 0) { + *d = *s; + d++; + s++; + } + return dest; +} + +void *memset(void *dest, int c, int len) +{ + uint8_t *d = dest; + while((len--) > 0) { + *d = c; + d++; + } + return dest; +} + +int memcmp(const void *av, const void *bv, int len) +{ + const uint8_t *a = av; + const uint8_t *b = bv; + + while((len--) > 0) { + if(*a != *b) { + return *a - *b; + } + a++; + b++; + } + return 0; +} + +int strlen(const char *str) +{ + int l = 0; + while(*str) { + l++; + str++; + } + return l; +} + +char* strncat(char *dest, const char *src, unsigned int n) +{ + unsigned int dest_len = strlen(dest); + unsigned int i; + + for (i = 0 ; i < n && src[i] != '\0' ; i++) + dest[dest_len + i] = src[i]; + dest[dest_len + i] = '\0'; + + return dest; +} diff --git a/armsrc/string.h b/armsrc/string.h new file mode 100644 index 00000000..0a683293 --- /dev/null +++ b/armsrc/string.h @@ -0,0 +1,10 @@ +#ifndef __STRING_H +#define __STRING_H + +int strlen(const char *str); +void *memcpy(void *dest, const void *src, int len); +void *memset(void *dest, int c, int len); +int memcmp(const void *av, const void *bv, int len); +char *strncat(char *dest, const char *src, unsigned int n); + +#endif /* __STRING_H */ \ No newline at end of file diff --git a/armsrc/util.c b/armsrc/util.c index ae6408cf..7a2895cf 100644 --- a/armsrc/util.c +++ b/armsrc/util.c @@ -4,65 +4,7 @@ //----------------------------------------------------------------------------- #include "proxmark3.h" #include "util.h" - -void *memcpy(void *dest, const void *src, int len) -{ - uint8_t *d = dest; - const uint8_t *s = src; - while((len--) > 0) { - *d = *s; - d++; - s++; - } - return dest; -} - -void *memset(void *dest, int c, int len) -{ - uint8_t *d = dest; - while((len--) > 0) { - *d = c; - d++; - } - return dest; -} - -int memcmp(const void *av, const void *bv, int len) -{ - const uint8_t *a = av; - const uint8_t *b = bv; - - while((len--) > 0) { - if(*a != *b) { - return *a - *b; - } - a++; - b++; - } - return 0; -} - -int strlen(const char *str) -{ - int l = 0; - while(*str) { - l++; - str++; - } - return l; -} - -char* strncat(char *dest, const char *src, unsigned int n) -{ - unsigned int dest_len = strlen(dest); - unsigned int i; - - for (i = 0 ; i < n && src[i] != '\0' ; i++) - dest[dest_len + i] = src[i]; - dest[dest_len + i] = '\0'; - - return dest; -} +#include "string.h" void num_to_bytes(uint64_t n, size_t len, uint8_t* dest) { diff --git a/armsrc/util.h b/armsrc/util.h index 621f3fe5..0af673cc 100644 --- a/armsrc/util.h +++ b/armsrc/util.h @@ -13,11 +13,7 @@ #define BUTTON_SINGLE_CLICK -1 #define BUTTON_DOUBLE_CLICK -2 #define BUTTON_ERROR -99 -int strlen(const char *str); -void *memcpy(void *dest, const void *src, int len); -void *memset(void *dest, int c, int len); -int memcmp(const void *av, const void *bv, int len); -char *strncat(char *dest, const char *src, unsigned int n); + void num_to_bytes(uint64_t n, size_t len, uint8_t* dest); uint64_t bytes_to_num(uint8_t* src, size_t len); -- 2.39.2