Implement storedevs, prepare to port littlefs
This commit is contained in:
@ -13,7 +13,11 @@ void *hal_memset(void *p, int c, size_t n);
|
||||
void *hal_memcpy(void *dst, const void *src, size_t n);
|
||||
size_t hal_strlen(char *s);
|
||||
int hal_memcmp(const void *s1, const void *s2, int len);
|
||||
|
||||
int hal_strcmp(const char *a, const char *b);
|
||||
size_t hal_strcspn(const char *s, const char *reject);
|
||||
size_t hal_strspn(const char *s, const char *accept);
|
||||
char *hal_strcpy(char *dest, const char *src);
|
||||
char *hal_strchr(const char *s, int c);
|
||||
|
||||
#if defined(__x86_64__)
|
||||
# define HAL_PAGE_SIZE 0x1000
|
||||
|
@ -45,3 +45,67 @@ int hal_memcmp(const void *s1, const void *s2, int len)
|
||||
}
|
||||
return charCompareStatus;
|
||||
}
|
||||
|
||||
int hal_strcmp(const char *a, const char *b) {
|
||||
while (*a && (*a == *b)) {
|
||||
a++, b++;
|
||||
}
|
||||
return (unsigned char)*a - (unsigned char)*b;
|
||||
}
|
||||
|
||||
size_t hal_strcspn(const char *s, const char *reject) {
|
||||
size_t count = 0;
|
||||
for (; *s != '\0'; ++s) {
|
||||
const char *r = reject;
|
||||
while (*r != '\0') {
|
||||
if (*s == *r) {
|
||||
return count;
|
||||
}
|
||||
r++;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
size_t hal_strspn(const char *s, const char *accept) {
|
||||
size_t count = 0;
|
||||
for (; *s != '\0'; ++s) {
|
||||
const char *a = accept;
|
||||
int matched = 0;
|
||||
while (*a != '\0') {
|
||||
if (*s == *a) {
|
||||
matched = 1;
|
||||
break;
|
||||
}
|
||||
a++;
|
||||
}
|
||||
if (!matched) {
|
||||
return count;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
char *hal_strcpy(char *dest, const char *src) {
|
||||
char *d = dest;
|
||||
while ((*d++ = *src++) != '\0') {
|
||||
;
|
||||
}
|
||||
return dest;
|
||||
}
|
||||
|
||||
char *hal_strchr(const char *s, int c) {
|
||||
char ch = (char)c;
|
||||
while (*s != '\0') {
|
||||
if (*s == ch) {
|
||||
return (char *)s;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (ch == '\0') {
|
||||
return (char *)s;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
Reference in New Issue
Block a user