mirror of
https://github.com/Proxmark/proxmark3.git
synced 2025-08-14 10:36:58 -07:00
Split str* and mem* into string.[ch]
This commit is contained in:
parent
4cd41f34ea
commit
9ab7a6c755
15 changed files with 88 additions and 74 deletions
62
armsrc/string.c
Normal file
62
armsrc/string.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/* Implementations of the common string.h functions */
|
||||
#include "string.h"
|
||||
#include <stdint.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;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue