Fix gcc 10 link issues
[legacy-proxmark3.git] / bootrom / string.c
blobb2710d077f38c1ac70f100eb6d6e25794c3da8ca
1 //-----------------------------------------------------------------------------
2 // Jonathan Westhues, Sept 2005
3 //
4 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
5 // at your option, any later version. See the LICENSE.txt file for the text of
6 // the license.
7 //-----------------------------------------------------------------------------
8 // Common string.h functions
9 //-----------------------------------------------------------------------------
11 #include "string.h"
12 #include <stdint.h>
14 void *memcpy(void *dest, const void *src, size_t len) {
15 uint8_t *d = dest;
16 const uint8_t *s = src;
17 while((len--) > 0) {
18 *d = *s;
19 d++;
20 s++;
22 return dest;
26 void *memset(void *dest, int c, size_t len) {
27 uint8_t *d = dest;
28 while((len--) > 0) {
29 *d = c;
30 d++;
32 return dest;
36 void *memmove(void *dest, const void *src, size_t len) {
37 uint8_t *d = dest;
38 const uint8_t *s = src;
39 if (dest <= src) {
40 while((len--) > 0) {
41 *d = *s;
42 d++;
43 s++;
45 } else {
46 d = d + len - 1;
47 s = s + len - 1;
48 while((len--) > 0) {
49 *d = *s;
50 d--;
51 s--;
54 return dest;
58 int memcmp(const void *av, const void *bv, size_t len) {
59 const uint8_t *a = av;
60 const uint8_t *b = bv;
62 while((len--) > 0) {
63 if(*a != *b) {
64 return *a - *b;
66 a++;
67 b++;
69 return 0;
73 size_t strlen(const char *str) {
74 int l = 0;
75 while(*str) {
76 l++;
77 str++;
79 return l;
83 char* strncat(char *dest, const char *src, size_t n) {
84 unsigned int dest_len = strlen(dest);
85 unsigned int i;
87 for (i = 0 ; i < n && src[i] != '\0' ; i++)
88 dest[dest_len + i] = src[i];
89 dest[dest_len + i] = '\0';
91 return dest;
95 char* strcat(char *dest, const char *src) {
96 unsigned int dest_len = strlen(dest);
97 unsigned int i;
99 for (i = 0 ; src[i] != '\0' ; i++)
100 dest[dest_len + i] = src[i];
101 dest[dest_len + i] = '\0';
103 return dest;